Skip to content

CCAR-F · Domain 4: Prompt Engineering & Structured Output · 20% of the exam

Task 4.3: Enforce structured output using tool use and JSON schemas

Extraction tools and JSON schemas for output that always parses, strict schemas and tool_choice, nullable and enum-with-other fields, and the semantic errors that a valid schema still lets through.

Study it

  • Structured output: extraction tools, strict schemas, tool_choice and nullable fields

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the Anthropic documentation page that proves it.

Question 1 · choose 1

Your invoice extraction tool's JSON schema lists po_number as a required string. About a third of invoices have no purchase order number, and audits find plausible-looking PO numbers that appear nowhere in those invoices. How should you change the schema?

  1. AAdd a pattern to po_number so that values must match the company's PO format
  2. BMake po_number optional and nullable, returning null when the invoice has none
  3. CKeep the field required and add "never invent a PO number" to the extraction prompt
  4. DTurn on strict: true for the tool so that the extracted values have to conform to the schema
Show the answer and why
  • AAdd a pattern to po_number so that values must match the company's PO format

    Incorrect

    A fabricated number can match the format perfectly; a pattern checks shape, not truth.

  • BMake po_number optional and nullable, returning null when the invoice has none

    Correct

    When a field can be absent from the source, a nullable field gives Claude a valid way to say so instead of filling the gap.

  • CKeep the field required and add "never invent a PO number" to the extraction prompt

    Incorrect

    The schema still demands a value; the instruction fights the schema and does not always win.

  • DTurn on strict: true for the tool so that the extracted values have to conform to the schema

    Incorrect

    Strict mode guarantees the output matches the schema, and this schema still requires a PO number, so fabrication continues.

Design fields that may be missing from the source as optional and nullable. Required fields push the model to produce a value, which is how plausible fabrications appear.

Question 2 · choose 2

Your team switched its receipt extraction to strict tool use (strict: true on the tool definition). Which TWO statements about what this change does and does not give you are correct? (Choose TWO.)

  1. AIt does not check business rules, such as line items adding up to the total, so semantic validation is still needed
  2. BA refusal still comes back in the shape of the schema, so the parser never sees an unexpected response
  3. CValidation after extraction can be dropped, because a schema-valid result is also a correct one
  4. DString enum values always come back in exactly the capitalization written in the schema
  5. ETool inputs are constrained to the schema, so they parse and have the required fields and the declared types
Show the answer and why
  • AIt does not check business rules, such as line items adding up to the total, so semantic validation is still needed

    Correct

    A schema constrains structure and types; whether values are correct or consistent is outside what it can enforce.

  • BA refusal still comes back in the shape of the schema, so the parser never sees an unexpected response

    Incorrect

    On a refusal the response may not match the schema, so the pipeline must check stop_reason.

  • CValidation after extraction can be dropped, because a schema-valid result is also a correct one

    Incorrect

    Valid structure says nothing about whether the right value landed in the right field.

  • DString enum values always come back in exactly the capitalization written in the schema

    Incorrect

    The documentation notes that enum casing is not guaranteed, so values should be compared case-insensitively.

  • ETool inputs are constrained to the schema, so they parse and have the required fields and the declared types

    Correct

    Strict tool use uses grammar-constrained sampling to guarantee schema-valid tool inputs.

Schema-enforced output removes syntax and type errors, but not semantic errors such as totals that do not add up or values in the wrong field. Keep semantic validation, handle refusals, and compare enums case-insensitively.

Question 3 · choose 1

With structured outputs, your schema lists properties in the order title, notes, author, where only title and author are required. The output arrives as title, author, notes, which breaks a parser that expects schema order. What explains this?

  1. ARequired properties are placed before optional ones
  2. BProperty order in structured outputs is random
  3. CThe parser is reading an older cached response
  4. DThe schema is invalid because optional fields must come last
Show the answer and why
  • ARequired properties are placed before optional ones

    Correct

    Structured outputs keep schema order within each group but put required properties before optional ones.

  • BProperty order in structured outputs is random

    Incorrect

    Order follows a defined rule.

  • CThe parser is reading an older cached response

    Incorrect

    The ordering is the documented behavior.

  • DThe schema is invalid because optional fields must come last

    Incorrect

    The schema is valid; the output ordering rule causes this.

Structured outputs place required properties first, then optional ones; mark all properties required or parse by key if order matters.

Question 4 · choose 1

After you deploy a new JSON schema with structured outputs, the first request takes noticeably longer than usual, while later requests are fast. Is something wrong?

  1. ANo; the first request always runs on a slower model
  2. BYes; the schema is too large and must be split
  3. CNo; the grammar compiles on first use, then is cached
  4. DYes; structured outputs are slow on every request
Show the answer and why
  • ANo; the first request always runs on a slower model

    Incorrect

    The model does not change.

  • BYes; the schema is too large and must be split

    Incorrect

    Size limits produce errors, not a one-time delay.

  • CNo; the grammar compiles on first use, then is cached

    Correct

    Compiled grammars are cached for 24 hours from last use.

  • DYes; structured outputs are slow on every request

    Incorrect

    Only the first use of a schema pays the compilation cost.

Structured outputs compile each schema into a grammar on first use and cache it for 24 hours since last use, so only the first request is slower.

Question 5 · choose 1

Your long extraction conversations use prompt caching together with a structured-output schema. You start adjusting the response schema between requests in the same thread, and cache hits disappear. Why?

  1. AStructured outputs disable caching for responses over 1,000 tokens
  2. BThe cache expires whenever any schema exists in the request
  3. CPrompt caching cannot be combined with structured outputs at all
  4. DChanging the format invalidates the thread's cache
Show the answer and why
  • AStructured outputs disable caching for responses over 1,000 tokens

    Incorrect

    There is no such rule.

  • BThe cache expires whenever any schema exists in the request

    Incorrect

    Only changes to the format parameter cause this.

  • CPrompt caching cannot be combined with structured outputs at all

    Incorrect

    They work together while the format stays the same.

  • DChanging the format invalidates the thread's cache

    Correct

    Structured outputs add a system prompt for the format, so a change invalidates the cache.

Changing the structured-output format invalidates the prompt cache for that conversation thread; keep the schema stable when cache reuse matters.

Question 6 · choose 1

Your HIPAA-eligible extraction pipeline uses structured outputs. A developer proposes an enum of real patient names in the schema to improve matching. What does the documentation say?

  1. AStructured outputs cannot be used in HIPAA workloads
  2. BKeep PHI out of schemas and in message content only
  3. CPHI in schemas is fine, since schemas are never stored
  4. DPHI is fine in enums but not in property names
Show the answer and why
  • AStructured outputs cannot be used in HIPAA workloads

    Incorrect

    They are HIPAA eligible when PHI stays out of the schema.

  • BKeep PHI out of schemas and in message content only

    Correct

    Compiled schemas are cached separately and do not get the same PHI protections.

  • CPHI in schemas is fine, since schemas are never stored

    Incorrect

    Schemas are cached for up to 24 hours.

  • DPHI is fine in enums but not in property names

    Incorrect

    The guidance covers enum values, const values and patterns as well.

Structured outputs are HIPAA eligible, but PHI must not appear in schema definitions, including property names, enums, consts and patterns.

Question 7 · choose 2

Your Pydantic model has a field with minimum: 100, a constraint the structured-outputs grammar does not support. You pass the model to an Anthropic SDK helper. Which TWO statements are correct? (Choose TWO.)

  1. AThe constraint is silently ignored everywhere
  2. BThe helper removes the constraint from the schema sent to Claude and notes it in the field's description
  3. CA helper that validates responses still checks the result against minimum: 100
  4. DThe request fails because minimum is unsupported
  5. EClaude is guaranteed to respect minimum: 100 through the grammar
Show the answer and why
  • AThe constraint is silently ignored everywhere

    Incorrect

    It is added to the description and enforced by validation.

  • BThe helper removes the constraint from the schema sent to Claude and notes it in the field's description

    Correct

    Unsupported constraints are dropped from the sent schema and described instead.

  • CA helper that validates responses still checks the result against minimum: 100

    Correct

    Validation runs against your original schema with all its constraints.

  • DThe request fails because minimum is unsupported

    Incorrect

    Helpers transform the schema so the request succeeds.

  • EClaude is guaranteed to respect minimum: 100 through the grammar

    Incorrect

    The grammar no longer contains the constraint; the description and validation stand in for it.

SDK helpers remove unsupported constraints, add them to field descriptions, and validate responses against the full original schema.

Practise domain 4 →Practise all domains →