Skip to content

The agent engineering platform.

better error message on parsing errors (#11342)

Harrison Chasebdf865d8e8dc
diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.py
index f46e1595c3..47aa3ae972 100644
--- a/libs/langchain/langchain/agents/agent.py
+++ b/libs/langchain/langchain/agents/agent.py
@@ -931,7 +931,12 @@ class AgentExecutor(Chain):
else:
raise_error = False
if raise_error:
- raise e
+ raise ValueError(
+ "An output parsing error occurred. "
+ "In order to pass this error back to the agent and have it try "
+ "again, pass `handle_parsing_errors=True` to the AgentExecutor. "
+ f"This is the error: {str(e)}"
+ )
text = str(e)
if isinstance(self.handle_parsing_errors, bool):
if e.send_to_llm:
@@ -1027,7 +1032,12 @@ class AgentExecutor(Chain):
else:
raise_error = False
if raise_error:
- raise e
+ raise ValueError(
+ "An output parsing error occurred. "
+ "In order to pass this error back to the agent and have it try "
+ "again, pass `handle_parsing_errors=True` to the AgentExecutor. "
+ f"This is the error: {str(e)}"
+ )
text = str(e)
if isinstance(self.handle_parsing_errors, bool):
if e.send_to_llm: