|
|
|
|
|
by pcwelder
361 days ago
|
|
``` try: answer = chain.invoke(question)
# print(answer) # raw JSON output
display_answer(answer)
except Exception as e: print(f"An error occurred: {e}")
chain_no_parser = prompt | llm
raw_output = chain_no_parser.invoke(question)
print(f"Raw output:\n\n{raw_output}")
```Wait, are you calling LLM again if parsing fails just to get what LLM has sent to you already? The whole thing is not difficult to do if you directly call API without Lang chain, it'd also help you avoid such inefficiency. |
|
Langchain has a way to return raw output, aside "with structured output": https://python.langchain.com/docs/how_to/structured_output/#...
It's pretty common to use a cheaper model to fix these errors to match the schema if it fails with a tool call.