Home / Class/ CombiningOutputParser Class — langchain Architecture

CombiningOutputParser Class — langchain Architecture

Architecture documentation for the CombiningOutputParser class in combining.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d["CombiningOutputParser"]
  012baf05_a3c2_4ba2_f15a_5d6471c083bf["combining.py"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|defined in| 012baf05_a3c2_4ba2_f15a_5d6471c083bf
  c2b116c3_5465_840c_ba20_4925e9145122["is_lc_serializable()"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|method| c2b116c3_5465_840c_ba20_4925e9145122
  c1014e6c_aabc_713c_d29c_33a80ae166a5["validate_parsers()"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|method| c1014e6c_aabc_713c_d29c_33a80ae166a5
  ec7b0626_bbd8_e547_8b1f_77f0f664f0b6["_type()"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|method| ec7b0626_bbd8_e547_8b1f_77f0f664f0b6
  55b88d9a_a080_c1a3_8c08_29993b47474a["get_format_instructions()"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|method| 55b88d9a_a080_c1a3_8c08_29993b47474a
  6fa67ddf_f6f5_bb8c_52cb_43fdd5e9381b["parse()"]
  f373b1cd_1b87_d3b3_7e97_939ce0c3ce4d -->|method| 6fa67ddf_f6f5_bb8c_52cb_43fdd5e9381b

Relationship Graph

Source Code

libs/langchain/langchain_classic/output_parsers/combining.py lines 12–58

class CombiningOutputParser(BaseOutputParser[dict[str, Any]]):
    """Combine multiple output parsers into one."""

    parsers: list[BaseOutputParser]

    @classmethod
    @override
    def is_lc_serializable(cls) -> bool:
        return True

    @pre_init
    def validate_parsers(cls, values: dict[str, Any]) -> dict[str, Any]:
        """Validate the parsers."""
        parsers = values["parsers"]
        if len(parsers) < _MIN_PARSERS:
            msg = "Must have at least two parsers"
            raise ValueError(msg)
        for parser in parsers:
            if parser._type == "combining":  # noqa: SLF001
                msg = "Cannot nest combining parsers"
                raise ValueError(msg)
            if parser._type == "list":  # noqa: SLF001
                msg = "Cannot combine list parsers"
                raise ValueError(msg)
        return values

    @property
    def _type(self) -> str:
        """Return the type key."""
        return "combining"

    def get_format_instructions(self) -> str:
        """Instructions on how the LLM output should be formatted."""
        initial = f"For your first output: {self.parsers[0].get_format_instructions()}"
        subsequent = "\n".join(
            f"Complete that output fully. Then produce another output, separated by two newline characters: {p.get_format_instructions()}"  # noqa: E501
            for p in self.parsers[1:]
        )
        return f"{initial}\n{subsequent}"

    def parse(self, text: str) -> dict[str, Any]:
        """Parse the output of an LLM call."""
        texts = text.split("\n\n")
        output = {}
        for txt, parser in zip(texts, self.parsers, strict=False):
            output.update(parser.parse(txt.strip()))
        return output

Frequently Asked Questions

What is the CombiningOutputParser class?
CombiningOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/output_parsers/combining.py.
Where is CombiningOutputParser defined?
CombiningOutputParser is defined in libs/langchain/langchain_classic/output_parsers/combining.py at line 12.

Analyze Your Own Codebase

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

Try Supermodel Free