response_format, JSON Schema, or other format constraints are supported depends on the model parameters.
Basic strategy
- Check whether the model supports structured output.
- Use the smallest, clearest structure possible.
- Parse JSON and validate the schema on the server side.
- On validation failure, retry a limited number of times, or fall back to plain text parsing.
JSON object example
Server-side validation
Truncation and finish reason
Whenfinish_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.

