Home / Class/ StructuredChatOutputParserWithRetries Class — langchain Architecture

StructuredChatOutputParserWithRetries Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  c80bcf01_deef_c746_2289_cf3c30f352fb["StructuredChatOutputParserWithRetries"]
  6701f111_459b_a5ab_36de_5950dae06e0e["AgentOutputParser"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|extends| 6701f111_459b_a5ab_36de_5950dae06e0e
  2857bb68_61ce_bbf0_3d7f_30a049157b64["output_parser.py"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|defined in| 2857bb68_61ce_bbf0_3d7f_30a049157b64
  8264a738_c889_35f2_2eeb_d81ea3fd64b5["get_format_instructions()"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|method| 8264a738_c889_35f2_2eeb_d81ea3fd64b5
  a7391953_9a9c_49a0_f325_c37255835024["parse()"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|method| a7391953_9a9c_49a0_f325_c37255835024
  7850eb6b_4ff2_ae25_c1cf_3960dec240d3["from_llm()"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|method| 7850eb6b_4ff2_ae25_c1cf_3960dec240d3
  49be185e_5d63_0024_cebc_61edf8f39ed5["_type()"]
  c80bcf01_deef_c746_2289_cf3c30f352fb -->|method| 49be185e_5d63_0024_cebc_61edf8f39ed5

Relationship Graph

Source Code

libs/langchain/langchain_classic/agents/structured_chat/output_parser.py lines 62–112

class StructuredChatOutputParserWithRetries(AgentOutputParser):
    """Output parser with retries for the structured chat agent."""

    base_parser: AgentOutputParser = Field(default_factory=StructuredChatOutputParser)
    """The base parser to use."""
    output_fixing_parser: OutputFixingParser | None = None
    """The output fixing parser to use."""

    @override
    def get_format_instructions(self) -> str:
        return FORMAT_INSTRUCTIONS

    @override
    def parse(self, text: str) -> AgentAction | AgentFinish:
        try:
            if self.output_fixing_parser is not None:
                return self.output_fixing_parser.parse(text)
            return self.base_parser.parse(text)
        except Exception as e:
            msg = f"Could not parse LLM output: {text}"
            raise OutputParserException(msg) from e

    @classmethod
    def from_llm(
        cls,
        llm: BaseLanguageModel | None = None,
        base_parser: StructuredChatOutputParser | None = None,
    ) -> StructuredChatOutputParserWithRetries:
        """Create a StructuredChatOutputParserWithRetries from a language model.

        Args:
            llm: The language model to use.
            base_parser: An optional StructuredChatOutputParser to use.

        Returns:
            An instance of StructuredChatOutputParserWithRetries.
        """
        if llm is not None:
            base_parser = base_parser or StructuredChatOutputParser()
            output_fixing_parser: OutputFixingParser = OutputFixingParser.from_llm(
                llm=llm,
                parser=base_parser,
            )
            return cls(output_fixing_parser=output_fixing_parser)
        if base_parser is not None:
            return cls(base_parser=base_parser)
        return cls()

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

Frequently Asked Questions

What is the StructuredChatOutputParserWithRetries class?
StructuredChatOutputParserWithRetries is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/structured_chat/output_parser.py.
Where is StructuredChatOutputParserWithRetries defined?
StructuredChatOutputParserWithRetries is defined in libs/langchain/langchain_classic/agents/structured_chat/output_parser.py at line 62.
What does StructuredChatOutputParserWithRetries extend?
StructuredChatOutputParserWithRetries extends AgentOutputParser.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free