Set response_format
JSON mode is useful for a simple object. JSON Schema adds a schema name, field structure, required properties, and a way to reject extra properties.
A strict schema reduces defensive parsing, but it never replaces application-side validation.
JSON Schema response format
json
{
"model": "openai/gpt-5.6-sol",
"messages": [{"role": "user", "content": "Extract an order summary."}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "order_summary",
"strict": true,
"schema": {
"type": "object",
"properties": {"items": {"type": "array"}, "total": {"type": "number"}},
"required": ["items", "total"],
"additionalProperties": false
}
}
}
}Design the schema
- Keep fields and descriptions concise and domain-specific.
- Set additionalProperties: false where unknown fields are not acceptable.
- Version schemas in your own code instead of changing a consumer contract invisibly.
Handle the result
Validate returned JSON with the same validator used by your API or database.
If a model or route does not accept the requested format, surface a controlled error and select a compatible option through the model catalogue.