Structured outputs
Have the model answer in JSON that matches your schema.
Give a JSON Schema, and the answer is JSON that follows it. Use this when your code parses the answer, for example to extract fields from text or to fill a form.
With a schema
The OpenAI SDKs build the schema from a Pydantic model or a Zod object and parse the answer for you:
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
completion = client.chat.completions.parse(
model="raon-1-mini-preview",
messages=[{"role": "user", "content": "Make up a person who lives in Seoul."}],
response_format=Person,
)
print(completion.choices[0].message.parsed)| API | Where the schema goes |
|---|---|
| Chat Completions | response_format: {"type": "json_schema", "json_schema": {...}} |
| Responses | text.format: {"type": "json_schema", "name": ..., "schema": {...}} |
| Messages | output_config: {"format": {"type": "json_schema", "schema": {...}}} |
The model still reasons first. The reasoning stays in its own field, and only the answer follows the schema.
JSON mode
response_format: {"type": "json_object"} on Chat Completions asks for any valid JSON object, without a schema. Say in the prompt which keys you want.
Tips
- Give each field a clear name, and a
descriptionwhere the meaning is not obvious. The model fills fields from these. - Leave enough output tokens for both reasoning and JSON:
max_tokensormax_completion_tokenson Chat Completions,max_tokenson Messages, andmax_output_tokenson Responses. Check for truncation usingfinish_reason: "length",stop_reason: "max_tokens", orstatus: "incomplete"andincomplete_details, respectively. Parse and validate the answer before using it.

