Structured Outputs now available in the API
We've launched Structured Outputs — a new feature that ensures model-generated outputs exactly match JSON Schemas you provide.
How it works
Set response_format with type: "json_schema" and provide your schema:
response = client.chat.completions.create(
model="gpt-4o-2024-08-06",
messages=[{"role": "user", "content": "Extract: John is 30 years old"}],
response_format={
"type": "json_schema",
"json_schema": {
"name": "person",
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
},
"required": ["name", "age"]
}
}
}
)
The model will always return valid JSON matching your schema. No more parsing errors!
12.8k views71 replies210 likes
Log in to reply to this topic.