Home / Class/ ConvoOutputParser Class — langchain Architecture

ConvoOutputParser Class — langchain Architecture

Architecture documentation for the ConvoOutputParser class in output_parser.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74["ConvoOutputParser"]
  d9685a4b_26b0_bca9_f857_03bb2ffc9dd4["AgentOutputParser"]
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74 -->|extends| d9685a4b_26b0_bca9_f857_03bb2ffc9dd4
  4769be81_bcb9_b904_3228_724d54112009["output_parser.py"]
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74 -->|defined in| 4769be81_bcb9_b904_3228_724d54112009
  2a8b74db_dfd0_9d9a_7bf3_38d930ef750e["get_format_instructions()"]
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74 -->|method| 2a8b74db_dfd0_9d9a_7bf3_38d930ef750e
  f63d1c23_a516_2b6f_bcef_278c3d7fb4f5["parse()"]
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74 -->|method| f63d1c23_a516_2b6f_bcef_278c3d7fb4f5
  510a3bb5_eab9_8ee6_d8f2_1bee44ce27dc["_type()"]
  e86d251f_95c1_f0bd_1920_8d5f67bb0e74 -->|method| 510a3bb5_eab9_8ee6_d8f2_1bee44ce27dc

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/conversational/output_parser.py lines 10–48

class ConvoOutputParser(AgentOutputParser):
    """Output parser for the conversational agent."""

    ai_prefix: str = "AI"
    """Prefix to use before AI output."""

    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:
        """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)

    @property
    def _type(self) -> str:
        return "conversational"

Frequently Asked Questions

What is the ConvoOutputParser class?
ConvoOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/conversational/output_parser.py.
Where is ConvoOutputParser defined?
ConvoOutputParser is defined in libs/langchain/langchain_classic/agents/conversational/output_parser.py at line 10.
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