AITraining2U

Programs

Resources

Case Studies

Quick Links

Enquire Now
Starter Domain 3 · Prompt Engineering & Structured Output ~35 min

Get guaranteed JSON two different ways

Separate structured outputs from tool-use schema enforcement.

There are two distinct mechanisms for making Claude emit conforming JSON, and they suit different jobs. Build the same extraction with both, then articulate when each is right.

What to build

  1. Define a target schema: invoice number, date, line items, total.
  2. Implementation A: use output_config with a JSON Schema so the response body conforms.
  3. Implementation B: define a tool with strict schema enforcement and read the tool input.
  4. Run both over ten messy documents.
  5. Record which one you would use for a data pipeline and which for an agent that must also act.
  6. Feed a document missing the total and observe what each produces.

Done when

  • Both implementations parse without a try/except around json.loads.
  • You can state the case for each mechanism in one sentence.
  • You have seen what happens when the source document lacks a required field.
  • Neither implementation asks the model politely for JSON in the prompt.

The trap this exercise teaches

Prompting "respond only in JSON" and parsing defensively. That is the pre-schema workaround; the schema mechanisms make conformance structural.

Before you start

The theory behind this build is covered in Structured outputs: two distinct features. If any step below is unfamiliar, read that first — the exercise assumes it. Primary source: Claude Docs — Structured outputs.

Check yourself against the exam

This exercise sits in Domain 3, which is 20% of the CCAR‑F exam. Once you have built it, run a domain drill in the study app and see whether the questions read differently.