Skip to main content
Structured Outputs let you enforce that a model’s response conforms to a JSON schema you define. Instead of asking the model to try to return JSON, the API guarantees the output matches your schema — no extra parsing, no malformed responses.
Structured Outputs are available on models that support response_format with json_schema (e.g. gpt-4o, gpt-4o-mini). For other models, use json_object mode with a system prompt.

JSON Mode vs. Structured Outputs

Use json_schema when downstream code depends on specific fields always being present.

Basic Example


Common Schema Patterns

Extraction

Pull structured records out of unstructured text.

Classification

Route or label inputs reliably.

Nested Objects

Schemas can be deeply nested.

JSON Object Mode (Fallback)

For models that don’t support json_schema, use json_object mode with a system prompt instructing the model to return JSON.
json_object mode guarantees valid JSON but not schema conformance. Always validate the output against your expected shape before using it in production.

Schema Design Tips

Prevents the model from including unexpected fields that could break downstream parsers.
With strict: true, every property must appear in required. Optional fields should use a union type like ["string", "null"].
Enums are strictly enforced and reduce hallucination on fields with a known set of values.
Deeply nested schemas increase the chance of refusal on complex inputs. Flatten where the structure allows.