Structured outputs across providers
Module 4.5 taught the why. This lesson covers the how across all three major providers.
Same shipping label format, three different printers. You need to know which buttons make each printer behave.
All three providers support enforced JSON outputs:
- OpenAI:
response_format={"type": "json_schema", "json_schema": {...}} - Gemini:
response_mime_type="application/json"+response_schema= - Anthropic: tool use with a tool that takes a typed input matching your schema
Anthropic example (tool-as-schema pattern):
tool = {
"name": "save_resume",
"description": "Save extracted resume fields",
"input_schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"skills": {"type": "array", "items": {"type": "string"}},
},
"required": ["name", "skills"],
},
}
message = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=400,
tools=[tool],
tool_choice={"type": "tool", "name": "save_resume"},
messages=[{"role": "user", "content": "Aman, Python and React."}],
)
print(message.content[0].input)
The model is forced to call save_resume with structured args matching the schema.
Quick recall
3 prompts · think before you flip
Prompt 1 of 3
How does OpenAI enforce JSON schemas?
Quiz time
1 question · tap an answer to check it
1. The most reliable structured output mode in Anthropic is
Finished lesson 5.6?
Mark complete to update your module progress and unlock the streak.
Loading