ConvoOutputParser Class — langchain Architecture
Architecture documentation for the ConvoOutputParser class in output_parser.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 7b6152a7_4385_b958_e4d1_bd4468e4393f["ConvoOutputParser"] d9685a4b_26b0_bca9_f857_03bb2ffc9dd4["AgentOutputParser"] 7b6152a7_4385_b958_e4d1_bd4468e4393f -->|extends| d9685a4b_26b0_bca9_f857_03bb2ffc9dd4 e19c3095_7c11_1cbd_db92_84d82e0878fb["output_parser.py"] 7b6152a7_4385_b958_e4d1_bd4468e4393f -->|defined in| e19c3095_7c11_1cbd_db92_84d82e0878fb 90ce7237_5395_03b2_b455_faeadc7dc075["get_format_instructions()"] 7b6152a7_4385_b958_e4d1_bd4468e4393f -->|method| 90ce7237_5395_03b2_b455_faeadc7dc075 e02d8b25_f4ba_35dc_2b02_b9697955f659["parse()"] 7b6152a7_4385_b958_e4d1_bd4468e4393f -->|method| e02d8b25_f4ba_35dc_2b02_b9697955f659 32728613_e370_e8d2_ab8d_f1a7b06466ab["_type()"] 7b6152a7_4385_b958_e4d1_bd4468e4393f -->|method| 32728613_e370_e8d2_ab8d_f1a7b06466ab
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py lines 12–55
class ConvoOutputParser(AgentOutputParser):
"""Output parser for the conversational agent."""
format_instructions: str = FORMAT_INSTRUCTIONS
"""Default formatting instructions"""
def get_format_instructions(self) -> str:
"""Returns formatting instructions for the given output parser."""
return self.format_instructions
def parse(self, text: str) -> AgentAction | AgentFinish:
"""Attempts to parse the given text into an AgentAction or AgentFinish.
Raises:
OutputParserException if parsing fails.
"""
try:
# Attempt to parse the text into a structured format (assumed to be JSON
# stored as markdown)
response = parse_json_markdown(text)
# If the response contains an 'action' and 'action_input'
if "action" in response and "action_input" in response:
action, action_input = response["action"], response["action_input"]
# If the action indicates a final answer, return an AgentFinish
if action == "Final Answer":
return AgentFinish({"output": action_input}, text)
# Otherwise, return an AgentAction with the specified action and
# input
return AgentAction(action, action_input, text)
# If the necessary keys aren't present in the response, raise an
# exception
msg = f"Missing 'action' or 'action_input' in LLM output: {text}"
raise OutputParserException(msg)
except Exception as e:
# If any other exception is raised during parsing, also raise an
# OutputParserException
msg = f"Could not parse LLM output: {text}"
raise OutputParserException(msg) from e
@property
def _type(self) -> str:
return "conversational_chat"
Extends
Source
Frequently Asked Questions
What is the ConvoOutputParser class?
ConvoOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py.
Where is ConvoOutputParser defined?
ConvoOutputParser is defined in libs/langchain/langchain_classic/agents/conversational_chat/output_parser.py at line 12.
What does ConvoOutputParser extend?
ConvoOutputParser extends AgentOutputParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free