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.
Choice: z.infer<typeof choiceSchema>const response = await model.invoke({
state: "Stripe fails whenever I connect my account.",
questions: {
department: {
type: "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.",
},
},
},
});
const department = response.choices.department;
if (department.confidence >= 0.7) {
routeTo(department.choice);
} else {
routeToHumanTriage();
}