4.3 · D423 questions · 5 free

Structured output with tool use & JSON schemas

Enforce structured output using tool use and JSON schemas.

This subtopic (4.3) sits in Prompt Engineering & Structured Output (D4) on Anthropic's Claude Certified Architect — Foundations (CCA-F) exam. The bank holds 23 practice questions here — 4 easy, 12 medium, and 7 hard — with 5 free to try, answers and explanations included. 3 of the free questions are below; the rest are in the practice stream.

What the exam tests here

  • JSON schemas eliminate syntax errors but not semantic errors
  • tool_use with JSON schemas — most reliable for schema-compliant structured output
  • optional vs required schema fields — nullable prevents fabricated values
  • tool_choice auto vs any vs forced named tool
Practice this subtopic — 5 freeFree questions with answers ↓

Free practice questions: Structured output with tool use & JSON schemas

Question 1 of 3 · free · easy

Your CI/CD pipeline uses --output-format json with a strict schema to structure PR comments. A review returns valid JSON but marks a passing test suite as failing. What does this reveal?

Show answer & explanation

Correct answer: C. JSON schemas prevent syntax errors but cannot prevent semantically incorrect values.

Constrained decoding guarantees structurally valid JSON — required fields, correct types, no parse errors. It cannot enforce that a value is factually correct. A schema cannot distinguish a correct 'failing' verdict from an incorrect one; semantic accuracy depends on the model's reasoning, not schema enforcement.

Question 2 of 3 · free · hard

Your CI/CD pipeline invokes Claude Code with --output-format json and a --json-schema that requires each PR comment to contain file, line, severity (enum: low/med/high), and message. The first week, every response parses cleanly, yet developers complain that roughly 30% of comments flag real code as bugs or cite lines that do not contain the referenced symbol. What does this outcome reveal about the schema enforcement?

Show answer & explanation

Correct answer: C. The schema guarantees structural validity of each PR comment but cannot constrain whether the line number or bug claim is semantically accurate against the actual diff.

Schemas constrain shape, not truth. 'Structural validity ... cannot constrain' captures this: fields validate yet content can still be wrong. 'Outer envelope ... bypass validation' invents a nesting bug that does not exist. 'Fails silently ... with streaming' invents a streaming interaction; schema enforcement is orthogonal to SSE. 'CLAUDE.md instructions override schema' is wrong: project memory cannot relax enum validation, which is enforced mechanically.

Question 3 of 3 · free · medium

Your CI/CD pipeline uses Claude to generate PR comments as structured JSON. You define a tool whose input_schema matches the desired comment shape and call it with tool_choice set to force that tool. In which field of the API response does the validated structured data appear?

Show answer & explanation

Correct answer: D. In the tool_use block's input field, after the model emits stop_reason tool_use.

When tool_choice forces a specific tool, Claude stops with stop_reason tool_use and the validated structured data appears in the tool_use block's input field. The content[0].text pattern belongs to output_config structured outputs, not the forced-tool-use approach used here.

2 more free questions on this subtopic in the practice stream, plus 18 in the full bank. Keep practicing →

Related reading (Anthropic docs)