Skip to content

The agent engineering platform.

Use raise from statement so that users can find detailed error message (#11461)

Yang, Bo3a82bd7bdb5d
diff --git a/libs/langchain/langchain/agents/chat/output_parser.py b/libs/langchain/langchain/agents/chat/output_parser.py
index b7c37885a6..6ef7a155c2 100644
--- a/libs/langchain/langchain/agents/chat/output_parser.py
+++ b/libs/langchain/langchain/agents/chat/output_parser.py
@@ -37,9 +37,11 @@ class ChatOutputParser(AgentOutputParser):
response["action"], response.get("action_input", {}), text
)
- except Exception:
+ except Exception as exc:
if not includes_answer:
- raise OutputParserException(f"Could not parse LLM output: {text}")
+ raise OutputParserException(
+ f"Could not parse LLM output: {text}"
+ ) from exc
output = text.split(FINAL_ANSWER_ACTION)[-1].strip()
return AgentFinish({"output": output}, text)