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.Getting started
To use structured outputs, include theresponse_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:Supported models
Structured outputs are supported by the following model families:Post-processing
Post-processing steps let you apply automatic fixes to model responses after generation. You can specify an ordered list of steps in thepost_processing_steps parameter on any chat completions request. Steps run server-side on all LLM Gateway models in both US and EU regions.
Currently, JSON repair (json-repair) is the only supported step type.
JSON repair
JSON repair corrects common JSON errors — such as trailing commas, unescaped characters, and missing quotes — that LLMs occasionally produce. This is especially useful when using structured outputs or tool calling, where invalid JSON would otherwise require client-side retry logic.Getting started
Addpost_processing_steps to any chat completions request:
- Python
- JavaScript
What JSON repair fixes
The JSON repair step corrects the most common JSON errors produced by LLMs:
The step applies to both message content and tool call arguments in the response.
post_processing_steps runs independently of response_format, so you can combine JSON repair with a json_schema for maximum reliability.
If the JSON cannot be repaired, the request returns an HTTP 500 error. The raw malformed response is never passed through.
API reference
Request parameters
Theresponse_format parameter controls how the model formats its response:
JSON schema object
Schema definition
Theschema object follows the JSON Schema specification. Common properties include:
Post-processing parameters
Supported step types:
Best practices
When using structured outputs, keep these recommendations in mind: Setstrict: 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.