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.
from langchain_core.decisions import Choice
response = classifier.invoke(
{
"state": "Stripe fails whenever I connect my account.",
"questions": {
"department": Choice(
instructions="Which team should handle this request?",
criteria={
"billing": "Payment, invoice, or subscription issues.",
"technical": "Product bugs or integration failures.",
"sales": "Pricing or purchasing questions.",
},
)
},
}
)
department = response.choices["department"]
if department.confidence >= 0.7:
route_to(department.choice)
else:
route_to_human_triage()Wire discriminator for a categorical question.
Candidate labels mapped to their descriptions.
Descriptions may be text, structured JSON, or None. Include an other or
none_of_the_above label when the supplied alternatives may not cover every input.
Complete categorical judgment to make about the input state.