Tutorials · Chapter D (4/4) · ~10 min
Structured output lab
Try it → see it → read → next
Return **JSON your code can parse** — schema when machines consume, free text when humans read.
Try tools: Code & developers
Try yourself
Playground
Structured output lab
JSON schema when code consumes the answer — free text when humans read it.
App parses user tier from response
Recap
What you just did
You chose JSON schema vs free text per use case.
Read
Pattern
response = client.chat.completions.create(
model="gpt-4o-mini",
response_format={"type": "json_schema", "json_schema": TIER_SCHEMA},
messages=[{"role": "user", "content": user_text}],
)
data = json.loads(response.choices[0].message.content)