import { ... } from "@langchain/core/decisions";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.
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.
Fields shared by every decision model.
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.
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.
Fields a provider supplies to build a ClassifierResponse.
A discriminated union of answers returned by decision models.
The answer type a question produces. A Choice answer's choice is typed
as one of the question's labels.
Answers keyed by question ID, typed from the questions that were asked.
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.
Location of what a Box question describes.
confidence is the certainty from 0 to 1, or undefined when the
provider does not report it.
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.
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.
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.
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.
Any value expressible in JSON.
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.
Probability, from 0 to 1, that a Noul question's answer is yes.
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.
A discriminated union of question types accepted by decision models.
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.
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.
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.
A value allowed below the root of State.