Skip to main content

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

Use response_format with type: "json_schema":

Response Format

The model returns JSON matching your schema:
Parse the content as JSON:

Schema Configuration

name

Schema identifier (required):

strict

Enforce strict validation (default: false):
  • true: Reject responses that don’t match schema exactly
  • false: 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
  • required fields
  • additionalProperties control

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.
Structured outputs are supported on:
  • 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/models for json_mode capability
Query available models:

Best Practices

  1. Property descriptions: Guide the model with clear descriptions
  2. Use strict mode: Set strict: true for production
  3. Keep schemas simple: Simpler schemas yield more reliable results
  4. Required fields: Explicitly mark required fields
  5. Type constraints: Use enum for limited options

Example: Type-Safe Response

Streaming with Structured Outputs

Structured outputs work with streaming:
Accumulate content deltas and parse the complete JSON when the stream completes.

Error Handling

Common errors:
  1. Unsupported model: Error with unsupported_parameter type
  2. Invalid schema: Request rejected before completion
  3. 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