Skip to content

Commit 5d581ba

Browse files
authored
langchain: support the situation when action_input is null in json output_parser (#29680)
Description: This PR fixes handling of null action_input in [langchain.agents.output_parser]. Previously, passing null to action_input could cause OutputParserException with unclear error message which cause LLM don't know how to modify the action. The changes include: Added null-check validation before processing action_input Implemented proper fallback behavior with default values Maintained backward compatibility with existing implementations Error Examples: ``` { "action":"some action", "action_input":null } ``` Issue: None Dependencies: None
1 parent beb75b2 commit 5d581ba

File tree

1 file changed

+4
-3
lines changed
  • libs/langchain/langchain/agents/output_parsers

1 file changed

+4
-3
lines changed

libs/langchain/langchain/agents/output_parsers/json.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
5050
if response["action"] == "Final Answer":
5151
return AgentFinish({"output": response["action_input"]}, text)
5252
else:
53-
return AgentAction(
54-
response["action"], response.get("action_input", {}), text
55-
)
53+
action_input = response.get("action_input", {})
54+
if action_input is None:
55+
action_input = {}
56+
return AgentAction(response["action"], action_input, text)
5657
except Exception as e:
5758
raise OutputParserException(f"Could not parse LLM output: {text}") from e
5859

0 commit comments

Comments
 (0)