Home / Class/ Generation Class — langchain Architecture

Generation Class — langchain Architecture

Architecture documentation for the Generation class in generation.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e24b5be2_a888_4700_a118_b05d34a03395["Generation"]
  f3658565_d05c_7f49_b7f8_622b7ef34f33["Serializable"]
  e24b5be2_a888_4700_a118_b05d34a03395 -->|extends| f3658565_d05c_7f49_b7f8_622b7ef34f33
  f6b7d3d5_cc5d_7670_342a_fb0bc7ef1c38["generation.py"]
  e24b5be2_a888_4700_a118_b05d34a03395 -->|defined in| f6b7d3d5_cc5d_7670_342a_fb0bc7ef1c38
  5bcac42e_d00e_d0c2_9de5_d3fd43995ea3["is_lc_serializable()"]
  e24b5be2_a888_4700_a118_b05d34a03395 -->|method| 5bcac42e_d00e_d0c2_9de5_d3fd43995ea3
  48427344_2382_5e95_dc10_9d940d7c59a6["get_lc_namespace()"]
  e24b5be2_a888_4700_a118_b05d34a03395 -->|method| 48427344_2382_5e95_dc10_9d940d7c59a6

Relationship Graph

Source Code

libs/core/langchain_core/outputs/generation.py lines 11–52

class Generation(Serializable):
    """A single text generation output.

    Generation represents the response from an "old-fashioned" LLM (string-in,
    string-out) that generates regular text (not chat messages).

    This model is used internally by chat model and will eventually be mapped to a more
    general `LLMResult` object, and then projected into an `AIMessage` object.

    LangChain users working with chat models will usually access information via
    `AIMessage` (returned from runnable interfaces) or `LLMResult` (available via
    callbacks). Please refer to `AIMessage` and `LLMResult` for more information.
    """

    text: str
    """Generated text output."""

    generation_info: dict[str, Any] | None = None
    """Raw response from the provider.

    May include things like the reason for finishing or token log probabilities.
    """

    type: Literal["Generation"] = "Generation"
    """Type is used exclusively for serialization purposes.

    Set to `'Generation'` for this class.
    """

    @classmethod
    def is_lc_serializable(cls) -> bool:
        """Return `True` as this class is serializable."""
        return True

    @classmethod
    def get_lc_namespace(cls) -> list[str]:
        """Get the namespace of the LangChain object.

        Returns:
            `["langchain", "schema", "output"]`
        """
        return ["langchain", "schema", "output"]

Extends

Frequently Asked Questions

What is the Generation class?
Generation is a class in the langchain codebase, defined in libs/core/langchain_core/outputs/generation.py.
Where is Generation defined?
Generation is defined in libs/core/langchain_core/outputs/generation.py at line 11.
What does Generation extend?
Generation extends Serializable.

Analyze Your Own Codebase

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

Try Supermodel Free