LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corelanguage_modelsbaseBaseLanguageModelmodel_post_init
    Method●Since v1.4

    model_post_init

    Copy
    model_post_init(
        self,
        _context: Any,
        ,
    ) -> None
    View source on GitHub

    Parameters

    NameTypeDescription
    _context*Any

    Pydantic validation context (typically None).

    Pydantic V2 lifecycle hook called automatically after __init__.

    Seeds metadata["lc_versions"] with the installed langchain-core (and langchain, if installed) versions so that every LLM trace carries the package versions that produced it.

    Partner packages should not override this method. Instead, they should define a @model_validator(mode="after") that calls _add_version to append their own version to the same dict.

    Validator naming

    Each subclass's validator must have a unique name. Pydantic replaces — rather than chains — same-named model_validator methods in child classes. For example, a BaseChatOpenAI subclass should use _set_<partner>_version, not _set_version, to avoid silently dropping the parent's entry.