Structured Outputs and Constrained Decoding
In this article
- Explain what constrained decoding does to the table of next-token probabilities before each pick, and why the model still chooses among the values the schema allows.
- List the failures a schema-constrained reply rules out, and the ones that can still arrive.
- Choose native structured output or prompt-only JSON for a provider, given which schema keywords it enforces.
- Tell a final answer from a tool call, and say when each one fits.
- Terms defined here: schema-constrained generation, refusal, tool call, tool result.
Overview
Code that acts on a model's reply needs it in one fixed, checkable form, a schema. A request can describe that schema in the prompt, or hand it to the provider to enforce while the reply is being written, and the two leave different failures open. Take Brightline's ticket sorter, an invented example: a model puts each support ticket of this home-internet provider in billing, technical, account or other and says whether a person must see it now, and routing code sends the ticket to a team's queue and alerts a person when it is escalated. That code needs this schema, with both fields required and no others. The reply has the shape {"category": ..., "escalation": ...}, and the escalation field takes one of two forms, {"escalate": true, "reason": ...} for a yes with a reason or {"escalate": false} for a no. Afterwards you can say what the enforcing does at each step, what it rules out and leaves, and when to rely on the prompt alone.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- Two ways to ask for JSON
- How the constraint works
- What the guarantee covers
- Prompt-only JSON as the fallback
- Final answer or tool call
- Sources
- Check yourself, 5 questions