Skip to main content
Structured output is useful for classification, extraction, and workflow arguments. Whether response_format, JSON Schema, or other format constraints are supported depends on the model parameters.

Basic strategy

  1. Check whether the model supports structured output.
  2. Use the smallest, clearest structure possible.
  3. Parse JSON and validate the schema on the server side.
  4. On validation failure, retry a limited number of times, or fall back to plain text parsing.

JSON object example

Do not rely on the prompt alone to guarantee the format. Even with HTTP 200, catch empty content, truncated JSON, type errors, and missing fields.

Server-side validation

Truncation and finish reason

When finish_reason indicates a length limit, the JSON may be missing closing braces. Do not attempt to silently concatenate untrusted JSON; increase the reasonable output limit, reduce the schema, or re-request. In tool call scenarios, read the tool parameters rather than treating the content as JSON.

Schema design suggestions

  • Keep field names short and unambiguous.
  • Limit enums to the necessary range.
  • Avoid deep nesting and unbounded arrays.
  • Use strings for amounts, times, and identifiers, and validate their format separately.
  • State explicitly which fields allow null.
  • Do not let the model decide permissions, final prices, or security policy.
Next: Tool calls, Chat Completions, Model parameters, Request reliability.