Structured outputs make a large language model return data in a machine-readable format — usually JSON that conforms to a schema you supply — instead…
See why prose output breaks software and structure fixes it.
If you ask a model for information and it replies in a paragraph, your code has to parse that prose — and the format drifts between calls. One response says 'The sentiment is positive'; the next adds a preamble, or uses different words, or wraps JSON in an apology. Fragile string parsing follows, and it breaks in production.
Structured outputs solve this by making the model emit data in a fixed shape you define, so your code can consume it directly. The response becomes a contract, not a surprise.
Understand how a schema constrains the model to valid output.
The weak approach is to ask nicely in the prompt ('respond in JSON'). The model usually complies but sometimes doesn't — a stray sentence, a trailing comma, a missing field — and any of those crashes a parser.
Structured-output modes go further with constrained decoding: given your JSON Schema, the provider restricts which tokens the model can generate at each step so the result is guaranteed to be valid JSON matching the schema. You get the right fields, the right types, and the required keys every time, with no post-hoc repair.
Describe the exact shape you want with JSON Schema.
A JSON Schema names the fields, their types, which are required, and any constraints. Use enums to lock a field to a fixed set of values (sentiment must be positive, neutral, or negative), and required to ensure fields are always present. Clear field names and descriptions also guide the model toward the right values.
{
"type": "object",
"properties": {
"sentiment": { "type": "string", "enum": ["positive", "neutral", "negative"] },
"confidence": { "type": "number" }
},
"required": ["sentiment", "confidence"]
}The enum forces sentiment to one of three exact strings your code can switch on; required guarantees both fields appear; the number type keeps confidence numeric. Constrained decoding makes every response conform, so no validation branch is needed for shape.
Relate structured outputs to tool calling and avoid the usual errors.
Function calling is structured outputs in disguise: a tool's parameters are a JSON Schema, and the model's tool call is schema-constrained JSON your code executes. So the skill transfers — designing a good output schema and designing good tool arguments are the same craft, and both make the model a dependable part of a program.
Watch for: over-nesting or over-complicating the schema (simpler schemas are followed more reliably); confusing valid with correct — the model can return well-formed JSON that is factually wrong, so still validate the values, not just the shape; and using enums with unclear labels. Also remember constrained decoding guarantees format, not truth: pair it with clear instructions and, where it matters, verification of the content.
Structured outputs make an LLM return data in a defined format — typically JSON matching a schema — so software can consume it reliably instead of parsing prose. A structured-output mode uses constrained decoding to guarantee the output conforms to your JSON Schema, with the right fields, types, and required keys. Enums lock values, required ensures presence. It shares machinery with tool calling, and it guarantees format but not truth, so still validate the values.
Design a structured output for extracting an invoice: choose the fields and types, decide which are required, add an enum for the currency, and note one value-level check you would run because valid JSON does not guarantee the extracted numbers are correct.
What are structured outputs from an LLM?
Structured outputs return data in a fixed, defined shape so code can consume it directly, replacing fragile prose parsing.
How does a schema-constrained structured-output mode guarantee valid JSON?
By limiting allowed tokens to those that keep the output schema-valid, the provider guarantees correct structure without post-hoc repair.
How do you lock a field to a fixed set of values in JSON Schema?
An enum constrains a field to exact allowed values and required ensures presence, giving code predictable, switchable outputs.
What is a key limitation of structured outputs?
Constrained decoding fixes shape, not truth; clear instructions and value-level validation are still needed for correctness.