parse() — langchain Function Reference
Architecture documentation for the parse() function in output_parser.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c7b49729_4166_704a_aecf_f39c2616b986["parse()"] 3ad96f4e_9c83_f4d2_9ced_687b8a7dd6a9["ConvoOutputParser"] c7b49729_4166_704a_aecf_f39c2616b986 -->|defined in| 3ad96f4e_9c83_f4d2_9ced_687b8a7dd6a9 style c7b49729_4166_704a_aecf_f39c2616b986 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/conversational/output_parser.py lines 23–44
def parse(self, text: str) -> AgentAction | AgentFinish:
"""Parse the output from the agent into an AgentAction or AgentFinish object.
Args:
text: The text to parse.
Returns:
An AgentAction or AgentFinish object.
"""
if f"{self.ai_prefix}:" in text:
return AgentFinish(
{"output": text.rsplit(f"{self.ai_prefix}:", maxsplit=1)[-1].strip()},
text,
)
regex = r"Action: (.*?)[\n]*Action Input: ([\s\S]*)"
match = re.search(regex, text, re.DOTALL)
if not match:
msg = f"Could not parse LLM output: `{text}`"
raise OutputParserException(msg)
action = match.group(1)
action_input = match.group(2)
return AgentAction(action.strip(), action_input.strip(" ").strip('"'), text)
Domain
Subdomains
Source
Frequently Asked Questions
What does parse() do?
parse() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/agents/conversational/output_parser.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/agents/conversational/output_parser.py at line 23.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free