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_modelsllms
    Module●Since v0.1

    llms

    Attributes

    Functions

    Classes

    Type Aliases

    View source on GitHub
    attribute
    logger
    function
    get_llm_cache
    function
    dumpd
    function
    convert_to_messages
    function
    ensure_config
    function
    get_config_list
    function
    run_in_executor
    function
    create_base_retry_decorator
    function
    get_prompts
    function
    aget_prompts
    function
    update_cache
    function
    aupdate_cache
    class
    BaseCache
    class
    AsyncCallbackManager
    class
    AsyncCallbackManagerForLLMRun
    class
    BaseCallbackManager
    class
    CallbackManager
    class
    CallbackManagerForLLMRun
    class
    BaseLanguageModel
    class
    LangSmithParams
    class
    Generation
    class
    GenerationChunk
    class
    LLMResult
    class
    RunInfo
    class
    ChatPromptValue
    class
    PromptValue
    class
    StringPromptValue
    class
    RunnableConfig
    class
    BaseLLM
    class
    LLM
    typeAlias
    Callbacks: list[BaseCallbackHandler] | BaseCallbackManager | None
    typeAlias
    LanguageModelInput

    Base interface for traditional large language models (LLMs) to expose.

    These are traditionally older models (newer models generally are chat models).

    Get the value of the llm_cache global setting.

    Return a dict representation of an object.

    Convert a sequence of messages to a list of messages.

    Ensure that a config is a dict with all keys present.

    Get a list of configs from a single config or a list of configs.

    It is useful for subclasses overriding batch() or abatch().

    Run a function in an executor.

    Create a retry decorator for a given LLM and provided a list of error types.

    Get prompts that are already cached.

    Get prompts that are already cached. Async version.

    Update the cache and get the LLM output.

    Update the cache and get the LLM output. Async version.

    Interface for a caching layer for LLMs and Chat models.

    The cache interface consists of the following methods:

    • lookup: Look up a value based on a prompt and llm_string.
    • update: Update the cache based on a prompt and llm_string.
    • clear: Clear the cache.

    In addition, the cache interface provides an async version of each method.

    The default implementation of the async methods is to run the synchronous method in an executor. It's recommended to override the async methods and provide async implementations to avoid unnecessary overhead.

    Async callback manager that handles callbacks from LangChain.

    Async callback manager for LLM run.

    Base callback manager.

    Callback manager for LangChain.

    Callback manager for LLM run.

    Abstract base class for interfacing with language models.

    All language model wrappers inherited from BaseLanguageModel.

    LangSmith parameters for tracing.

    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.

    GenerationChunk, which can be concatenated with other Generation chunks.

    A container for results of an LLM call.

    Both chat models and LLMs generate an LLMResult object. This object contains the generated outputs and any additional information that the model provider wants to return.

    Class that contains metadata for a single execution of a chain or model.

    Defined for backwards compatibility with older versions of langchain_core.

    Users can acquire the run_id information from callbacks or via run_id information present in the astream_event API (depending on the use case).

    Chat prompt value.

    A type of a prompt value that is built from messages.

    Base abstract class for inputs to any language model.

    PromptValues can be converted to both LLM (pure text-generation) inputs and chat model inputs.

    String prompt value.

    Base LLM abstract interface.

    It should take in a prompt and return a string.

    Simple interface for implementing a custom LLM.

    You should subclass this class and implement the following:

    • _call method: Run the LLM on the given prompt and input (used by invoke).
    • _identifying_params property: Return a dictionary of the identifying parameters This is critical for caching and tracing purposes. Identifying parameters is a dict that identifies the LLM. It should mostly include a model_name.

    Optional: Override the following methods to provide more optimizations:

    • _acall: Provide a native async version of the _call method. If not provided, will delegate to the synchronous version using run_in_executor. (Used by ainvoke).
    • _stream: Stream the LLM on the given prompt and input. stream will use _stream if provided, otherwise it use _call and output will arrive in one chunk.
    • _astream: Override to provide a native async version of the _stream method. astream will use _astream if provided, otherwise it will implement a fallback behavior that will use _stream if _stream is implemented, and use _acall if _stream is not implemented.

    Input to a language model.

    Configuration for a Runnable.

    Note

    Custom values

    The TypedDict has total=False set intentionally to:

    • Allow partial configs to be created and merged together via merge_configs
    • Support config propagation from parent to child runnables via var_child_runnable_config (a ContextVar that automatically passes config down the call stack without explicit parameter passing), where configs are merged rather than replaced
    Example
    # Parent sets tags
    chain.invoke(input, config={"tags": ["parent"]})
    # Child automatically inherits and can add:
    # ensure_config({"tags": ["child"]}) -> {"tags": ["parent", "child"]}