Overview
Structured outputs enforce JSON Schema validation on model responses, ensuring consistent, type-safe outputs. This eliminates parsing errors and hallucinated fields, simplifying downstream integrations.Request Format
Useresponse_format with type: "json_schema":
Response Format
The model returns JSON matching your schema:Schema Configuration
name
Schema identifier (required):
strict
Enforce strict validation (default: false):
true: Reject responses that don’t match schema exactlyfalse: Allow minor deviations
schema
JSON Schema object defining the structure:
JSON Schema Support
Supported JSON Schema features:- Basic types:
string,number,integer,boolean,array,object - Constraints:
enum,minLength,maxLength,minimum,maximum - Nested objects and arrays
requiredfieldsadditionalPropertiescontrol
Model Support
View Structured Output Models
For a complete list of models supporting structured outputs, visit anannas.ai/models and filter by
json_mode capability.- OpenAI: GPT-4, GPT-4 Turbo, GPT-5 Mini, GPT-5, o1, o3
- Anthropic: Claude 3 Opus, Claude 3 Sonnet, Claude Sonnet 4.5
- Other providers: Check
/v1/modelsforjson_modecapability
Best Practices
- Property descriptions: Guide the model with clear descriptions
- Use strict mode: Set
strict: truefor production - Keep schemas simple: Simpler schemas yield more reliable results
- Required fields: Explicitly mark required fields
- Type constraints: Use
enumfor limited options
Example: Type-Safe Response
Streaming with Structured Outputs
Structured outputs work with streaming:Error Handling
Common errors:- Unsupported model: Error with
unsupported_parametertype - Invalid schema: Request rejected before completion
- Schema violation: Response fails validation in strict mode
Comparison: JSON Object vs JSON Schema
JSON Object Mode
Simple JSON output without validation:JSON Schema Mode
Strict validation with schema:See Also
- API Overview - Request format
- Parameters -
response_formatparameter