AI CompendiumA public chart of the language
Home / Prompting & Structure / Structured Output
Prompting & Structure

Structured Output

also called JSON mode, Schema-constrained output

Making the model return data your code can parse.

Definition

Constraining output to a schema — JSON, a specific set of enum values — either by prompt, by a JSON mode, or by grammar-constrained decoding that makes invalid output impossible.

For anything programmatic, use schema enforcement rather than polite requests. "Please return valid JSON" fails a small percentage of the time; that percentage is a production incident.

The distinction that matters in production is between requesting a shape and enforcing it. A schema constraint makes invalid output impossible, whereas asking politely leaves a small failure rate — and a small failure rate multiplied by daily volume is a recurring incident rather than a rare one.

How people use it
An integration breaking once a week.
"Stop parsing free text. Switch to structured output with a schema and the flakiness disappears."
Worked examples

Stopping the weekly parse failure

An integration fails roughly once a week on malformed JSON.

A one-in-a-thousand failure looks harmless in testing and produces an alert every few days in production. Move to a schema-constrained mode and the class of failure disappears; the remaining errors become transport errors, which are retryable.

Constraining rather than describing

Classification output must be one of a fixed set of labels.

Declare the enum rather than listing the labels in prose. The model cannot invent a ninth category, which removes an entire downstream branch — the code that handled the invalid label — along with the bug reports it generated.

Sources
  • docsControlled generation ↗Google Cloud Vertex AI docs · 2026

    Constraining generation to a supplied schema for extraction, classification and agent steps — distinct from merely asking for JSON politely.

  • docsFunction calling ↗OpenAI API docs · 2026

    The application-managed tool cycle spelled out: define the function with a JSON Schema, receive the call, execute it yourself, return the output.

Related terms