parse() — langchain Function Reference
Architecture documentation for the parse() function in output_parser.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 574abdbf_1008_8bfd_6fa6_4755d13af11e["parse()"] 249246d0_3ae9_06a7_6f45_d2d016bf1e28["StructuredChatOutputParser"] 574abdbf_1008_8bfd_6fa6_4755d13af11e -->|defined in| 249246d0_3ae9_06a7_6f45_d2d016bf1e28 a7391953_9a9c_49a0_f325_c37255835024["parse()"] a7391953_9a9c_49a0_f325_c37255835024 -->|calls| 574abdbf_1008_8bfd_6fa6_4755d13af11e a7391953_9a9c_49a0_f325_c37255835024["parse()"] 574abdbf_1008_8bfd_6fa6_4755d13af11e -->|calls| a7391953_9a9c_49a0_f325_c37255835024 style 574abdbf_1008_8bfd_6fa6_4755d13af11e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/structured_chat/output_parser.py lines 36–55
def parse(self, text: str) -> AgentAction | AgentFinish:
try:
action_match = self.pattern.search(text)
if action_match is not None:
response = json.loads(action_match.group(1).strip(), strict=False)
if isinstance(response, list):
# gpt turbo frequently ignores the directive to emit a single action
logger.warning("Got multiple action responses: %s", response)
response = response[0]
if response["action"] == "Final Answer":
return AgentFinish({"output": response["action_input"]}, text)
return AgentAction(
response["action"],
response.get("action_input", {}),
text,
)
return AgentFinish({"output": text}, text)
except Exception as e:
msg = f"Could not parse LLM output: {text}"
raise OutputParserException(msg) from e
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/structured_chat/output_parser.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/agents/structured_chat/output_parser.py at line 36.
What does parse() call?
parse() calls 1 function(s): parse.
What calls parse()?
parse() is called by 1 function(s): parse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free