Home / Class/ BaseGenerationOutputParser Class — langchain Architecture

BaseGenerationOutputParser Class — langchain Architecture

Architecture documentation for the BaseGenerationOutputParser class in base.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5["BaseGenerationOutputParser"]
  d0bafc31_c5e2_3cc4_445b_1e80ff919ed1["BaseLLMOutputParser"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|extends| d0bafc31_c5e2_3cc4_445b_1e80ff919ed1
  abb7c122_ee7b_4c8f_ffaa_3d3d63c4fab7["BaseMessage"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|extends| abb7c122_ee7b_4c8f_ffaa_3d3d63c4fab7
  f12d594d_57eb_7d18_3649_39c89c3048be["base.py"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|defined in| f12d594d_57eb_7d18_3649_39c89c3048be
  91988ff9_0a57_8b4b_1691_9088a524ac4e["InputType()"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|method| 91988ff9_0a57_8b4b_1691_9088a524ac4e
  1a922074_2583_187a_9cac_99b18bb43bdd["OutputType()"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|method| 1a922074_2583_187a_9cac_99b18bb43bdd
  c9588ee5_3d79_a8ef_a529_d2e2781b8371["invoke()"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|method| c9588ee5_3d79_a8ef_a529_d2e2781b8371
  e561fce3_0cdc_c1a0_a8e2_47e9374329d0["ainvoke()"]
  7e9c2bbb_e497_e7d1_8c0f_e01706224ee5 -->|method| e561fce3_0cdc_c1a0_a8e2_47e9374329d0

Relationship Graph

Source Code

libs/core/langchain_core/output_parsers/base.py lines 70–133

class BaseGenerationOutputParser(
    BaseLLMOutputParser, RunnableSerializable[LanguageModelOutput, T]
):
    """Base class to parse the output of an LLM call."""

    @property
    @override
    def InputType(self) -> Any:
        """Return the input type for the parser."""
        return str | AnyMessage

    @property
    @override
    def OutputType(self) -> type[T]:
        """Return the output type for the parser."""
        # even though mypy complains this isn't valid,
        # it is good enough for pydantic to build the schema from
        return cast("type[T]", T)  # type: ignore[misc]

    @override
    def invoke(
        self,
        input: str | BaseMessage,
        config: RunnableConfig | None = None,
        **kwargs: Any,
    ) -> T:
        if isinstance(input, BaseMessage):
            return self._call_with_config(
                lambda inner_input: self.parse_result(
                    [ChatGeneration(message=inner_input)]
                ),
                input,
                config,
                run_type="parser",
            )
        return self._call_with_config(
            lambda inner_input: self.parse_result([Generation(text=inner_input)]),
            input,
            config,
            run_type="parser",
        )

    @override
    async def ainvoke(
        self,
        input: str | BaseMessage,
        config: RunnableConfig | None = None,
        **kwargs: Any | None,
    ) -> T:
        if isinstance(input, BaseMessage):
            return await self._acall_with_config(
                lambda inner_input: self.aparse_result(
                    [ChatGeneration(message=inner_input)]
                ),
                input,
                config,
                run_type="parser",
            )
        return await self._acall_with_config(
            lambda inner_input: self.aparse_result([Generation(text=inner_input)]),
            input,
            config,
            run_type="parser",
        )

Frequently Asked Questions

What is the BaseGenerationOutputParser class?
BaseGenerationOutputParser is a class in the langchain codebase, defined in libs/core/langchain_core/output_parsers/base.py.
Where is BaseGenerationOutputParser defined?
BaseGenerationOutputParser is defined in libs/core/langchain_core/output_parsers/base.py at line 70.
What does BaseGenerationOutputParser extend?
BaseGenerationOutputParser extends BaseLLMOutputParser, BaseMessage.

Analyze Your Own Codebase

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

Try Supermodel Free