Building with AI

Structured outputs

3 min readintermediateUpdated 28 Sept 2026
1 · In one line

Structured outputs constrain a model response to a declared schema so software receives expected fields and types instead of free-form prose.

1 · What it is

Structured outputs turn a response format into a machine-readable contract. The developer supplies a schema describing properties, data types, required fields, arrays, and allowed values. Instead of hoping a prompt produces the right shape, the serving system restricts generation to responses that conform to the supported schema.

One implementation uses constrained decoding. After each token, the decoder calculates which tokens could still lead to valid output and blocks the rest. That is stronger than JSON mode, which ensures parseable JSON but not a particular set of keys or types. The result can be parsed directly into application objects when the SDK supports it.

The contract has boundaries. A valid amount field can still contain the wrong number. A safety refusal or a response cut short by a token limit may take a different path. Schema support also differs across providers and usually covers only a subset of JSON Schema. Applications still validate business rules, check important facts, and handle exceptional responses.

2 · Why it exists

Software cannot safely depend on prose that changes shape from one response to the next.

Keys can vanishValid JSON can still omit a field the application expects.
Labels go off-listA category field may come back with a value the application never allowed.
Values can be wrongMatching a schema checks structure, not whether the content inside each field is true.
3 · How it works

Follow meeting notes into a typed action-item object.

Constrained decoding produces a schema-shaped object Meeting notes and a JSON Schema enter a highlighted constrained-decoding gate, producing a typed action-item object with a separate exception path. REQUEST MEETING NOTES“Maya will ship the fixby Friday…” JSON SCHEMAowner: stringtask: stringdue: string | nullall fields required KEY MECHANISMConstrained decodingafter every token:allow only schema-valid next tokensblock invalid continuations PARSED OBJECT{owner: “Maya”,task: “ship fix”,due: “Friday”} EXCEPTION PATHrefusal · truncation · error Shape is enforced. Business rules and factual values still need application checks.
The schema restricts the response shape; the application still checks meaning and handles exceptional outcomes.
  1. 1 · defineThe developer declares field names, types, required properties, and allowed values in a supported schema.
  2. 2 · sendThe application submits the schema with the user's unstructured input.
  3. 3 · constrainDuring generation, the decoder permits only next tokens that can still produce a schema-valid result.
  4. 4 · parseThe client parses the response into a typed object and handles refusals or incomplete generations separately.

Schema-valid means the container is shaped correctly; it does not mean every value is factually correct.

4 · Where it's used
WhoWhat they askWhat it works with
Operations team“Turn these notes into assigned tasks”An array of owner, task, and due-date objects
Ecommerce app“Extract the requested product options”Allowed product IDs, quantities, and variants
Support workflow“Classify this ticket and set its priority”Enumerated category and priority fields
Data pipeline“Pull invoice values from this document”Required vendor, amount, currency, and date fields
5 · What it solves, and what it doesn't
solves
  • It can guarantee schema adherence for supported schemas when generation completes normally and is not a refusal.
  • Programs can skip the validate-and-retry loop for badly formatted replies.
  • Function calling can use a strict schema when the output represents arguments for a tool.
doesn't solve
  • The model can still put an incorrect fact or classification inside a valid field.
  • Safety refusals and interrupted generations require explicit handling outside the normal object path.
  • Providers support subsets of JSON Schema, so an arbitrary schema may need simplification.
6 · Go deeper

Sources used

This explainer is written in original language. The links below support its factual claims.

  1. officialIntroducing Structured Outputs in the API, OpenAI · read 27 Sept 2026
  2. docsStructured model outputs, OpenAI · read 27 Sept 2026
  3. docsStructured outputs, Google AI for Developers · read 27 Sept 2026
  4. docsHow to use structured outputs with Azure OpenAI in Microsoft Foundry Models, Microsoft · read 27 Sept 2026
  5. officialJSON Schema — object, JSON Schema · read 27 Sept 2026