Structured output with tool use and JSON schemas
How strict tool use and JSON outputs (output_config.format) guarantee schema-valid structure but not correct values, how to read tool_use input, and how to design extraction schemas with required, nullable, "other" and "unclear" fields plus prompt normalization rules.
Enforce structured output using tool use and JSON schemas
~7 min read · 13 practice questions ·
What the exam expects
- Replace "respond only with JSON" prompting with an extraction tool whose
input_schemadescribes the record,strict: true, and code that reads thetool_useblock'sinput. - Choose between strict tool use and JSON outputs via
output_config.format(not the deprecatedoutput_format), and know that both guarantee schema-valid syntax but not semantically correct values. - Pick the structured-output route for an extraction call, including when
tool_choicemust guarantee that a tool is called. - Design schemas: required vs optional, nullable fields so Claude need not fabricate,
"other"plus a detail string and"unclear"enum values, and no unsupported keywords such asminimumunder strict mode. - Put format normalization rules in the prompt beside the schema, and detect
max_tokensandrefusalresponses that may not match the schema.
Key terms: strict tool use (strict: true on a tool; grammar-constrained sampling keeps tool inputs schema-valid); JSON outputs (output_config.format with type: "json_schema", constraining Claude's reply text); constrained decoding (sampling restricted to schema-valid tokens); nullable field (a type array such as ["string", "null"]); semantic error (schema-valid output with wrong values).
Key facts
- Detail
strict: trueconstrains sampling so tool inputs matchinput_schema
tool_use.input- Detail
- Already an object conforming to
input_schema
- Detail
output_config.format,type: "json_schema"; result in the text block
output_format- Detail
- Deprecated; 400 error without the beta header
- Detail
additionalPropertiesmust befalse
- Detail
minimum,maximum,multipleOf,minLength,maxLength: 400 error
- Detail
stop_reasonrefusalormax_tokens
- Detail
- 20 strict tools, 24 optional parameters, 16 union-type parameters per request
- Detail
- Not prevented by strict schemas
- Why does a strict extraction tool remove
json.loads()failures that "respond only with JSON" prompting cannot? - When should you use
output_config.formatinstead of a strict tool? - Why make an extraction field nullable rather than required non-null?
- Which two stop reasons mean a structured response might not match its schema?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Claude Certified Architect - Foundations pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 30 lessons of the Claude Certified Architect - Foundations guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (13 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams
Practice for the Claude Certified Architect - Foundations exam
Certifyforce is an independent study resource and is not affiliated with, endorsed by or sponsored by Anthropic. Claude is a trademark of Anthropic.