Skip to main content
Structured output makes the model return strictly in a JSON structure, ready to parse directly in your program.

JSON mode (basic)

Notes:
  • It only guarantees valid JSON is returned, but field names / types may not match what you expect.
  • You must hint “return JSON” in the prompt, or the model may refuse due to safety policy.

JSON Schema (strict)

strict: true makes the model apply token-level constraints during generation, so the output is 100% schema-compliant.

Supported models

  • OpenAI: gpt-5.5 / gpt-5.4-mini / the o3 series.
  • Claude: supported indirectly (prompt guidance + tool enforcement).
  • Gemini: equivalent constraints via responseSchema.

Python (Pydantic)

The OpenAI Python SDK provides a parse method that takes a Pydantic model directly:

Gemini

Claude

Claude has no dedicated response_format, but you can achieve an equivalent effect with tool enforcement:

Notes

  • JSON Schema constraints slightly increase latency and cost (the model re-validates during generation).
  • Even with strict on, make the schema as explicit as possible (use enum, pattern, min/max, etc.).
  • Nesting depth ≤ 5, ≤ 100 fields, arrays ≤ 5000 elements; the exact limits are set by the upstream.