Friday, August 21, 2026

    Enforce structured output using tool use and JSON schemas

    Domain 4 — Prompt Engineering & Structured Output · 20% of the exam

    Task statement 4.3

    Enforce structured output using tool use and JSON schemas

    What you should be able to do
    • Use tool use with a JSON schema to guarantee schema-compliant output.
    • Distinguish what schema enforcement fixes (syntax) from what it cannot (semantics).
    • Choose between auto, any and forced tool selection for an extraction path.
    • Design fields so the model can say it did not find something instead of inventing it.
    Exam traps (5)

    Ask for JSON in the prompt and parse the reply.

    Parsing is then a runtime gamble against prose, fences and trailing commas, and the failures cluster on exactly the long complex documents you care about.

    Define the schema as a tool input and read the structured call.

    Treat a schema-valid response as a correct one.

    Schemas constrain shape, not truth: line items that do not sum, values in the wrong field and confidently wrong dates all validate perfectly.

    Schema removes syntax errors. Semantic correctness needs its own validation step.

    Mark every field required so nothing is skipped.

    When the source genuinely lacks the value the model must produce something to satisfy the contract, so the schema manufactures a plausible fabrication.

    Make a field optional where the document may not carry it, and give ambiguity somewhere to go.

    Use a closed enum so values stay clean.

    Anything outside the list gets forced into the nearest member, which reads as a confident classification of something that was never in the taxonomy.

    Add an explicit unclear value, and an other plus detail pair so the category can extend honestly.

    Leave tool_choice on auto for an extraction endpoint.

    The model may answer in prose instead of calling the tool, so the pipeline intermittently receives no structured output at all.

    Use any to guarantee a call when the document type is unknown, and forced selection when one extraction must run first.

    Where the guide and the current docs differ (1)

    how strong the schema guarantee is

    Answer this: Tool use with a JSON schema is the most reliable approach for guaranteed schema-compliant output.

    The docs now say: The guarantee is documented for strict tool use — adding strict: true is what ensures tool calls always match the schema exactly. Read it

    Primary sources
    Know cold
    • JSON schema
    • Structured output
    • tool_choice
    • Nullable field
    • Hallucination

    21 practice questions in the bank are tagged to this task statement.

    Practise this task in context: open it inside the interactive study guide, which carries the concept cards, the mock quiz and the practice simulation.

    Blueprint-aligned independent practice. Koko's scenarios and company facts are fictional and synthetic. This aid does not reproduce official exam questions or Anthropic's undisclosed scoring model, and is not affiliated with or endorsed by Anthropic.