Skip to main content
Structured output makes model responses easier to parse and integrate. Depending on the selected model, use JSON object mode or a strict JSON schema.

Request a JSON object

Tell the model to produce JSON and set response_format. Some models require an explicit instruction containing the word “JSON.”

Use JSON schema

On models that support strict structured output, send response_format.type = json_schema with a named schema:

Validate at the boundary

Even strict output can be interrupted by content filtering, output limits, network failure, or provider-specific behavior. Your application should:
  1. check the HTTP response and finish status;
  2. parse JSON with size and depth limits;
  3. validate against the same schema used in the request;
  4. reject unknown fields when they are unsafe;
  5. apply domain validation, such as ranges and cross-field rules;
  6. handle refusals and truncated output separately from schema failures.

JSON mode versus schema

Never interpolate model-produced JSON into SQL, shell commands, HTML, or authorization rules without context-specific escaping and validation.
Last modified on July 13, 2026