ReActOutputParser Class — langchain Architecture
Architecture documentation for the ReActOutputParser class in output_parser.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 040e163e_61b0_c9f4_7eff_dd7878f3f7fe["ReActOutputParser"] d9685a4b_26b0_bca9_f857_03bb2ffc9dd4["AgentOutputParser"] 040e163e_61b0_c9f4_7eff_dd7878f3f7fe -->|extends| d9685a4b_26b0_bca9_f857_03bb2ffc9dd4 1c037a99_fe6d_e353_78f4_508869dc6909["output_parser.py"] 040e163e_61b0_c9f4_7eff_dd7878f3f7fe -->|defined in| 1c037a99_fe6d_e353_78f4_508869dc6909 99c00fbe_ffee_45d9_c776_0e5e089bc1cc["parse()"] 040e163e_61b0_c9f4_7eff_dd7878f3f7fe -->|method| 99c00fbe_ffee_45d9_c776_0e5e089bc1cc 8b3f976c_a02c_4792_bd0b_53baeccfdefd["_type()"] 040e163e_61b0_c9f4_7eff_dd7878f3f7fe -->|method| 8b3f976c_a02c_4792_bd0b_53baeccfdefd
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/react/output_parser.py lines 10–34
class ReActOutputParser(AgentOutputParser):
"""Output parser for the ReAct agent."""
@override
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)
@property
def _type(self) -> str:
return "react"
Extends
Source
Frequently Asked Questions
What is the ReActOutputParser class?
ReActOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/react/output_parser.py.
Where is ReActOutputParser defined?
ReActOutputParser is defined in libs/langchain/langchain_classic/agents/react/output_parser.py at line 10.
What does ReActOutputParser extend?
ReActOutputParser extends AgentOutputParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free