LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Decisions
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

Chat LangChain

What can I help with?

Enter to send·Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextDecisionsBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/coredecisions
Module●Since v1.4

decisions

Copy
import { ... } from "@langchain/core/decisions";

Functions

function
parseClassifierResponse→ ClassifierResponse

Validates a provider's response and returns a ClassifierResponse.

Unknown answer types are rejected; unknown fields are dropped. Partial usage is completed with zero counts and a summed total_tokens.

function
parseQuestions→ Record<string, Question>

Validates a questions map.

Every question must match its type's schema, including required instructions and each type's minimum number of options, and unknown keys are rejected. The map itself is returned unchanged.

Classes

class
BaseDecisionModel

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 to call a provider. This class validates questions and handles callbacks, tracing metadata, and token-usage reporting.

Interfaces

interface
BaseDecisionModelFields

Fields shared by every decision model.

interface
ClassifierRequest

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.

interface
ClassifierResponse

Typed answers and metadata returned from one classification request.

Read every answer from answers, or use nouls, choices, scores, and boxes for views filtered by answer type. Each map preserves the question IDs supplied in ClassifierRequest.questions. The views are non-enumerable so they are not duplicated into traces or JSON.stringify output.

Q is the questions map that was asked. When it is known, answers and views are typed per question ID, and a Choice answer's choice is one of its labels.

interface
ClassifierResponseFields

Fields a provider supplies to build a ClassifierResponse.

Type Aliases

typeAlias
Answer: NoulAnswer | ChoiceAnswer | ScoreAnswer | BoxAnswer

A discriminated union of answers returned by decision models.

typeAlias
AnswerFor: T extends __type ? NoulAnswer : T extends __type ? ChoiceAnswer<Extract<keyof C, string>> : T extends __type ? ScoreAnswer : T extends __type ? BoxAnswer : never

The answer type a question produces. A Choice answer's choice is typed as one of the question's labels.

typeAlias
Answers: { [K in keyof Q]: AnswerFor<Q[K]> }

Answers keyed by question ID, typed from the questions that were asked.

typeAlias
Box: z.infer<typeof boxSchema>

Locate what the instructions describe in an image in the state.

The answer gives the edges of a box as fractions of the image height and width.

typeAlias
BoxAnswer: z.infer<typeof boxAnswerSchema>

Location of what a Box question describes.

confidence is the certainty from 0 to 1, or undefined when the provider does not report it.

typeAlias
BoxCoordinates: z.infer<typeof boxCoordinatesSchema>

Edges of a box as fractions of the image height and width, from 0 to 1.

top and bottom are measured from the top of the image, left and right from the left.

typeAlias
Choice: z.infer<typeof choiceSchema>

Select one label from a fixed set of alternatives.

Use Choice for categorical decisions with no inherent ordering, such as routing a support request, detecting a document type, or selecting an intent. The answer includes the selected label, a probability for every supplied label, and a confidence value.

criteria maps each label to its description, which may be text, JSON, or null. Include an other or none_of_the_above label when the alternatives may not cover every input.

typeAlias
ChoiceAnswer

Selected Choice label with its probability distribution and confidence.

choice is one of the labels supplied in Choice.criteria. probabilities keeps the complete distribution, keyed by label, so applications can use a confidence measure or risk policy different from the provider's. confidence is the certainty from 0 to 1 in the selected label. Each provider documents how it derives it; choose thresholds according to the consequences of an incorrect automated decision.

typeAlias
Content: z.infer<typeof contentSchema>

Text, a JSON object, or a JSON array used in question instructions.

As in State, LangChain standard media blocks may appear anywhere in instructions and criteria. Providers send them as media, or throw an error if their API does not accept that media in questions.

typeAlias
JsonValue: z.infer<typeof jsonValueSchema>

Any value expressible in JSON.

typeAlias
Noul: z.infer<typeof noulSchema>

Ask a binary question and receive the probability that its answer is yes.

Use Noul when the probability itself is useful to application code, such as deciding whether a message reports a bug or requests a refund. A value near 1 indicates strong support for yes, near 0 strong support for no, and near 0.5 uncertainty. Noul answers have no separate confidence.

Write the complete judgment in instructions, even when the question ID seems self-explanatory. Optional criteria define the yes and no outcomes.

typeAlias
NoulAnswer: z.infer<typeof noulAnswerSchema>

Probability, from 0 to 1, that a Noul question's answer is yes.

typeAlias
NoulCriteria: z.infer<typeof noulCriteriaSchema>

Optional descriptions for the two outcomes of a Noul question.

Criteria clarify what should count as yes and no when the instructions alone leave room for interpretation. Both values accept any JSON value, so callers can provide a short description or structured examples. The keys are literally true and false.

typeAlias
Question: z.infer<typeof questionSchema>

A discriminated union of question types accepted by decision models.

typeAlias
Score: z.infer<typeof scoreSchema>

Evaluate state against an ordered rubric.

Use Score when the answer lies on a spectrum whose levels can be described, such as severity, urgency, or customer frustration. criteria lists two or more levels, numbered from zero in their supplied order. The returned score is an expected value and may fall between integer levels; the full probability distribution remains available for custom decision logic.

typeAlias
ScoreAnswer: z.infer<typeof scoreAnswerSchema>

Expected Score value with its rubric, distribution, and confidence.

score is the expected position on the rubric and may be fractional, because it summarizes the distribution rather than selecting one level. legend holds the original rubric descriptions and probabilities the distribution, both keyed by zero-based level. confidence, from 0 to 1, is derived from the level distribution.

legend and probabilities are typed Record<string, ...> because JSON keys are strings; legend[0] still works.

typeAlias
State: string | BaseMessage | StateValue[] | __type

Root state accepted by decision models.

State is a string, JSON object, or JSON array. LangChain BaseMessage objects and message arrays can appear at the root or at any depth inside objects and arrays.

LangChain standard media blocks (for example { type: "image", data: ..., mimeType: ... }) may appear anywhere in the state. Each provider documents which media it supports and how it sends state its API cannot accept natively.

typeAlias
StateValue: string | number | boolean | null | BaseMessage | StateValue[] | __type

A value allowed below the root of State.

View source on GitHub