Structured Outputs
Overview
Structured outputs allow you to constrain the model’s response to follow a specific JSON schema. This ensures the model returns data in a predictable format that can be reliably parsed and processed by your application.
Structured outputs are supported by OpenAI (GPT-4.1, GPT-5.x) and Gemini models. Claude and gpt-oss models do not currently support structured outputs.
Getting started
To use structured outputs, include the response_format parameter in your request with a json_schema type:
Python
JavaScript
cURL
Example response
When using structured outputs, the model’s response will be a JSON string that conforms to your schema:
You can parse the content as JSON in your application:
Supported models
Structured outputs are supported by the following model families:
API reference
Request parameters
The response_format parameter controls how the model formats its response:
JSON schema object
Schema definition
The schema object follows the JSON Schema specification. Common properties include:
Best practices
When using structured outputs, keep these recommendations in mind:
Set strict: true to ensure the model’s response strictly adheres to your schema. This is especially important when your application depends on specific fields being present.
Use additionalProperties: false at each level of your schema to prevent the model from adding unexpected fields to the response.
Keep your schemas focused and specific. Complex schemas with many nested levels may increase latency and token usage.
Include clear descriptions in your system or user messages to help the model understand what data to extract or generate for each field.
Error handling
If the model cannot generate a valid response that matches your schema, you may receive an error or a response that doesn’t fully conform to the schema. Always validate the parsed JSON against your expected structure: