parse() — langchain Function Reference
Architecture documentation for the parse() function in output_parser.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD ea846c6f_225c_b26e_1924_b844031769a0["parse()"] c64d0531_c96b_8590_370b_7ce9e34ea9b9["ReActOutputParser"] ea846c6f_225c_b26e_1924_b844031769a0 -->|defined in| c64d0531_c96b_8590_370b_7ce9e34ea9b9 style ea846c6f_225c_b26e_1924_b844031769a0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/react/output_parser.py lines 14–30
def parse(self, text: str) -> AgentAction | AgentFinish:
action_prefix = "Action: "
if not text.strip().split("\n")[-1].startswith(action_prefix):
msg = f"Could not parse LLM Output: {text}"
raise OutputParserException(msg)
action_block = text.strip().split("\n")[-1]
action_str = action_block[len(action_prefix) :]
# Parse out the action and the directive.
re_matches = re.search(r"(.*?)\[(.*?)\]", action_str)
if re_matches is None:
msg = f"Could not parse action directive: {action_str}"
raise OutputParserException(msg)
action, action_input = re_matches.group(1), re_matches.group(2)
if action == "Finish":
return AgentFinish({"output": action_input}, text)
return AgentAction(action, action_input, 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/react/output_parser.py.
Where is parse() defined?
parse() is defined in libs/langchain/langchain_classic/agents/react/output_parser.py at line 14.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free