Chapter D · 4 of 4~10 min

Structured output lab

Return **JSON your code can parse** — schema when machines consume, free text when humans read.

Reviewed July 2026 · interactive lab

Paths & resources for this lesson

1Try it yourself

Playground

Structured output lab

JSON schema when code consumes the answer — free text when humans read it.

App parses user tier from response

2Read & reflect

Recap

#What you just did

You chose JSON schema vs free text per use case.

Teach

#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)

3Spark check

Continue learning · glossary & guides