Harpinder
Harpinder•8mo ago

Hey folks, do we have some restrictions

Hey folks, do we have some restrictions on what kind of input/outputs a "chain" can have in LangChain while integrating with Langfuse? I was trying Langfuse, but got an error
Exception in adding task Object of type AnswerChainInput is not JSON serializable
Exception in adding task Object of type AnswerChainInput is not JSON serializable
where,
@dataclass
class AnswerChainInput:
query: str
role_description: str
articles: list[SearchResponse]
qa_list: list[SearchResponse]

@dataclass
class SearchResponse:
text: str
id: str
@dataclass
class AnswerChainInput:
query: str
role_description: str
articles: list[SearchResponse]
qa_list: list[SearchResponse]

@dataclass
class SearchResponse:
text: str
id: str
I have two chains KBSearch which outputs a dict {"articles": list[SearchResponse], "qa": list[SearchResponse]} and that output is "piped" (in LangChain's LCEL terms) to the AnswerChain I did get some part of trace in between, sharing link: https://cloud.langfuse.com/project/clr8y6gcu0000ckbq48ve60bz/traces/b3147d4f-89fc-4bb6-85f7-dc5329db6f8f?observation=b7a13e12-105a-42e3-b90e-7c175d2c0cf9 Could you let me know if these errors are right now expected, or do you think this is a bug?
8 Replies
Harpinder
Harpinder•8mo ago
bumping this..! @Marc bumping this one more time in case you can give some clue on this? Just wanted to know if it's a known bug/expected feature, or I am using it somehow wrong
Marc
Marc•8mo ago
Interesting error, thanks for sharing
Marc
Marc•8mo ago
GitHub
bug: JSON serializability issues · Issue #948 · langfuse/langfuse
Describe the bug Langfuse fails to serialize some of the runs with error: Exception in adding task Object of type <X> is not JSON serializable where X = a custom type. To reproduce @dataclass...
Marc
Marc•8mo ago
This is your issue right? Will try to look into this soon to fix/debug
Harpinder
Harpinder•8mo ago
hey yeah, this is my issue only.. Thanks for taking out the time to look into it! Hey @Marc , any luck here?
Harpinder
Harpinder•8mo ago
https://github.com/langfuse/langfuse-python/pull/357 Have raised a PR with a potential fix. PTAL when you get some time! Thanks!
GitHub
fix: support more types for JSON serialization by SinghCoder · Pull...
Fixes langfuse/langfuse#948 For my case, it was a dataclass which I was returning as a chain output, and python default JSON serializer does not support dataclasses dumping.. See StackOverflow Thre...
Marc
Marc•8mo ago
thanks a lot! @Max just merged it this was on the list to fix this week, you were faster 🙂
Harpinder
Harpinder•8mo ago