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

    Chat LangChain

    What can I help with?

    Enter to sendยทShift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-coredecisionsbase
    Moduleโ—Since v1.8

    base

    Base class for decision models.

    Attributes

    Functions

    Classes

    Type Aliases

    View source on GitHub
    attribute
    Question
    attribute
    logger
    function
    ensure_config
    function
    run_in_executor
    class
    ClassifierRequest
    class
    ClassifierResponse
    class
    RunnableConfig
    class
    RunnableSerializable
    class
    BaseDecisionModel
    typeAlias
    State: TypeAlias

    A discriminated union of question types accepted by decision models.

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

    Run a function in an executor.

    Complete input for one decision model invocation.

    Keeping the state and questions in the Runnable input ensures both values participate in composition, batching, and tracing.

    Typed answers and metadata returned from one classification request.

    Access every answer through answers, or use nouls, choices, scores, and boxes for views filtered by answer type. Each mapping preserves the question IDs supplied to ClassifierRequest.questions.

    Runnable that can be serialized to JSON.

    Root state accepted by decision models.

    State is a string, JSON object, or JSON array. LangChain BaseMessage objects and message sequences can appear at the root or at any depth inside objects and arrays. LangChain standard media blocks (for example {"type": "image", "base64": ..., "mime_type": ...}) may appear anywhere in the state. Each provider documents which media it supports and how it sends state its API cannot accept natively.

    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"]}

    Answer typed questions about text, messages, or structured state.

    A decision model evaluates shared state against one or more questions and returns typed answers: a probability for a Noul, a selected label for a Choice, an expected level for a Score, and a location for a Box. Answers keep their probability distributions and confidence so applications can choose their own thresholds.

    Subclasses implement _classify, and optionally _aclassify, to call a provider. This class handles callbacks, tracing metadata, and token-usage reporting.

    Implement a decision model
    from langchain_core.decisions import BaseDecisionModel, ClassifierResponse
    
    class MyDecisionModel(BaseDecisionModel):
        model: str = "my-model"
    
        @property
        def _provider(self) -> str:
            return "my_provider"
    
        def _classify(self, state, questions):
            body = my_client.classify(state=state, questions=questions)
            return ClassifierResponse.model_validate(body)