Skip to content

Structured Outputs

Structured outputs make the model emit JSON that conforms to a schema you supply — no parsing failures, no missing fields.

The simplest form. Set response_format to json_object:

{
"model": "...",
"messages": [...],
"response_format": { "type": "json_object" }
}

The model is guaranteed to return syntactically valid JSON. Shape is up to your prompt.

For guaranteed shape, pass a schema:

response = client.chat.completions.create(
model="...",
messages=[{"role": "user", "content": "Extract: Jane Doe, jane@example.com"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "contact",
"strict": True,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"type": "string"},
},
"required": ["name", "email"],
"additionalProperties": False,
},
},
},
)

When strict: true, output is constrained to match the schema exactly — no extra fields, no missing required keys.

The SDK can derive the schema from a Pydantic model via client.chat.completions.parse() (or responses.parse()).