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
- Python
- Node.js
- Raw JSON Schema
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 supportjson_schema, use json_object mode with a system prompt instructing the model to return JSON.
Schema Design Tips
Always set additionalProperties: false
Always set additionalProperties: false
Prevents the model from including unexpected fields that could break downstream parsers.
List all fields in required
List all fields in required
With
strict: true, every property must appear in required. Optional fields should use a union type like ["string", "null"].Use enums for categorical fields
Use enums for categorical fields
Enums are strictly enforced and reduce hallucination on fields with a known set of values.
Keep schemas flat when possible
Keep schemas flat when possible
Deeply nested schemas increase the chance of refusal on complex inputs. Flatten where the structure allows.