Base class for decision models.
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.
Custom values
The TypedDict has total=False set intentionally to:
merge_configsvar_child_runnable_config (a ContextVar that automatically passes
config down the call stack without explicit parameter passing), where
configs are merged rather than replaced# 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.
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)