BrainyBeeBrainyBee
ExploreBlogStart Studying
HomeClaude Certified Architect - Foundations (CCAR-F)Domain 4 Project — build an extraction pipeline, then the reviewer that judges it
Hands-on Lab954 words

Domain 4 Project — build an extraction pipeline, then the reviewer that judges it

Claude Certified Architect - Foundations (CCAR-F) › Domain 4: Prompt Engineering & Structured Output

Domain 4 Project — build an extraction pipeline, then the reviewer that judges it

Six stages that turn halfway through. You build a document extraction pipeline — schema, validation, retry, examples — and then you build the thing that judges output: a code reviewer with criteria precise enough to apply the same way twice, and an architecture that does not let the author mark its own work.

Domain 4 is 20% of the exam, and its sharpest line runs through the middle of this project: tool use eliminates syntax errors and leaves semantic ones untouched. Stage 1 gives you a response that validates perfectly. Stage 2 is where you discover it is wrong.

The advanced rating is honest — this is the longest of the five projects, and stages 4.4 and 4.6 both ask you to build something that checks something else.

The project at a glance

Domain
4 · Prompt Engineering & Structured Output (20%)
Stages
6, one per task statement
Difficulty
Advanced
Total time
215 minutes
You need
Python 3.10+, the anthropic SDK, an API key, and a dozen messy documents
Based on
Exam guide Preparation Exercise 3

What you will be able to do

  • Design a JSON schema that makes fabrication unnecessary, and say which fields must be nullable and why
  • Distinguish a validation failure a retry can fix from one it cannot, before spending the attempts
  • Write few-shot examples aimed at measured failures, and explain why the reasoning matters more than the pairs
  • Replace a confidence-based review filter with categorical criteria, and anchor severity to concrete examples
  • Choose between the synchronous and batch APIs from the workflow's latency, and calculate the submission frequency an SLA needs

Before you start

The SDK setup from Domain 1, plus something to extract from:

bash
mkdir ccarf-domain-4 && cd ccarf-domain-4 python3 -m venv .venv && source .venv/bin/activate pip install anthropic export ANTHROPIC_API_KEY=your-key-here mkdir documents

The documents matter more than the code. Put a dozen real ones in that directory — invoices, papers, reports, whatever you have — and make sure they are genuinely inconsistent. You specifically want:

  • at least two that are missing a field the others have, because stage 4.3's whole lesson is what a required field does to those
  • at least two with a different structure for the same information — inline citations against a bibliography, a table where another used prose — because those are what stage 4.2's examples are aimed at
  • at least one whose numbers do not add up, because stage 4.4's semantic validation has nothing to catch otherwise

A clean, uniform corpus will make every stage of this project appear to work and teach you none of it.

Stage 4.5 submits 100 documents to the Batches API. Duplicating your dozen is fine — the stage is about custom_id correlation and failure handling, not about having 100 distinct sources.

Build it in this order

The pipeline is built first, then the reviewer that judges output, then batching — because you batch a pipeline that works, and 100 documents through a broken one is 100 wrong answers at a discount.

Six stages

  1. 1

    4.3 · A schema that cannot be answered wrongly · 40 min

    BUILD — An extraction tool whose input_schema IS your output shape: required fields where the source always has them, nullable ones where it may not, an enum with an unclear value, and an other-plus-detail pair for categories you did not anticipate. Run it over documents that are missing fields on purpose. WHY — tool_use with a JSON schema is the reliable way to get structured output, and schema design is where fabrication is prevented. A required field the source lacks is a guaranteed invented value — the model has no other way to satisfy you. YOU SHOULD SEE — Null coming back for genuinely absent fields rather than something plausible, and unclear appearing where the document really is ambiguous. TRAP — Marking everything required because it feels rigorous. It is the single most reliable way to make an extractor lie, and the exam asks about it directly. STUCK? — For each required field, find one real document that lacks it. If you can, the field is not required — it is optional and you were hoping.

Stage 4.3 in full

The schema is the output shape

With tool use, you do not ask for JSON and hope. You define a tool whose INPUT parameters are the shape you want, and read the result out of the tool_use block. The model fills the parameters; the arguments are your answer.

python
EXTRACT = { "name": "record_invoice", "description": "Record the fields extracted from one invoice document.", "input_schema": { "type": "object", "properties": { "invoice_number": {"type": "string"}, "issued_on": {"type": ["string", "null"], "description": "ISO 8601 date, or null if the document does not state one"}, "supplier": {"type": ["string", "null"]}, "stated_total": {"type": ["number", "null"]}, "currency": { "type": "string", "enum": ["GBP", "USD", "EUR", "other", "unclear"], }, "currency_detail": { "type": ["string", "null"], "description": "The currency as written, when currency is other or unclear", }, "line_items": { "type": "array", "items": { "type": "object", "properties": { "description": {"type": "string"}, "amount": {"type": "number"}, }, "required": ["description", "amount"], }, }, }, "required": ["invoice_number", "currency", "line_items"], }, }

Four decisions in there, and each is examined:

Why each field is shaped that way

issued_on is nullable AND not required

Two separate mechanisms, and this field uses both. Omitting it from required means it may be absent; allowing null in type means it may be present and empty. The exam guide calls both optional (nullable) — know that they are different, because omitting from required is the one that is safe everywhere.

currency is an enum with unclear

An ambiguous document has somewhere honest to go instead of being forced into the nearest listed value.

other plus currency_detail

An unanticipated category is RECORDED rather than lost. The enum stays closed; the information does not.

only three required

An invoice with no number is not an invoice. Everything else is a hope, and a hope in the required list is a fabrication instruction.

A required field the source lacks is a guaranteed invention

This is the most reliable way to make an extractor lie, and it does not look like lying — the response validates, the field is populated, and the value is plausible. The model has no way to say absent when the schema does not allow it. For every field you mark required, find one real document that lacks it; if you can, it is optional.

If a schema is rejected, drop the type array before anything else

input_schema is standard JSON Schema, but the documentation records limitations — and strict tool use narrows them further. A type array like [string, null] is the least portable thing in the schema above. If the API refuses it, express optionality the other way: leave the field out of required and give it a plain type. That form is accepted everywhere and carries the same meaning for extraction.

Run it, deliberately, over the broken ones

python
def extract(document_text): response = client.messages.create( model="claude-opus-5", max_tokens=4096, tools=[EXTRACT], tool_choice={"type": "tool", "name": "record_invoice"}, messages=[{"role": "user", "content": document_text}], ) for block in response.content: if block.type == "tool_use": return block.input return None

The forced tool_choice is deliberate: with auto the model may reply in prose, and a pipeline that sometimes gets prose has to handle two shapes. Here the document type is known, so forcing the specific tool is right. Stage 4.5 revisits this — when the type is unknown, any is the setting, because the model must pick the schema.

Now run it over the two documents you chose for missing fields. null is the correct answer and you should see it. If you see a plausible date instead, the field is required and this is the lesson.

Multiple choice · Medium

An extraction pipeline uses tool_use with a strict JSON schema. Every response validates. A reviewer nonetheless finds invoices where the line items do not add up to the recorded total. What does this show?

Prove stage 4.3 before moving on

  • Run the missing-field documents and confirm you get null, not a plausible value.
  • Feed it something in an unlisted currency and confirm you get other with the detail captured, rather than the nearest listed match.
  • Keep every extraction. Stage 4.4 validates these exact outputs, and the ones that are wrong today are the fixtures you need.

When you get stuck

Every stage above ends with a STUCK? line — the first thing worth checking, which is usually the thing actually wrong.

Past that, in the app: the Help button in this page's toolbar sends the tutor the section you are currently reading, together with the project's title, so you can ask "why does this not work" without pasting anything in. It knows which stage you are on.

  • Test on the awkward documents, not the clean ones. Every stage of this project appears to work on a uniform corpus and teaches nothing there.
  • Keep the failures. Each stage's bad outputs are the next stage's fixtures — a pipeline you cannot re-run against yesterday's mistakes cannot be shown to have improved.
  • Separate the two error classes out loud. Ask of every failure whether the shape is wrong or the meaning is wrong. The whole domain hangs off that distinction, and so do most of its questions.

Where the depth lives

This page is for building. The reading is elsewhere, and repeating it here would put the same claims in three places to drift apart:

  • The Domain 4 roadmap — what the domain is about, the order to learn it in, and where it catches people
  • 6 flashcard decks, 47 cards — one card per published objective
  • 47 Domain 4 questions — judgement under exam conditions, inside the six production scenarios

Nobody has run this yet

The code and commands here were written against the documented behaviour and checked against the reference — but no stage has been executed end to end. If something does not behave as described, trust what your terminal says over what this page does, and please report it. The row carries a needs_human_run_through stamp so this page can be found again once someone has worked it through.

Sources

  • CCAR-F Exam Guide v1.0, section 6 — Domain 4's six task statements, which are this project's six stages.
  • CCAR-F Exam Guide v1.0, section 8 — Preparation Exercise 3 (Build a Structured Data Extraction Pipeline), whose five steps supply four of these stages.
  • Anthropic Messages API reference — tool_use with JSON schemas, the documented JSON Schema limitations, the three tool_choice settings, and the Message Batches API with custom_id correlation.

What is quoted, and what is argued

The task statements and the exercise skeletons are the exam guide's. Product behaviour is documented behaviour, checked against the reference rather than restated from memory. The stage ordering, the traps and the teaching are this hive's reading of that material — useful preparation, not an official statement about what the exam contains.

All Claude Certified Architect - Foundations (CCAR-F) Study Resources

Related Notes

  • Domain 4: Prompt Engineering & Structured Output150 words
  • CCAR-F: how the exam is dealt194 words
  • Scenario 1: Customer Support Resolution Agent225 words
  • Scenario 2: Code Generation with Claude Code185 words
  • Scenario 3: Multi-Agent Research System199 words
  • Scenario 4: Developer Productivity with Claude197 words
  • Scenario 5: Claude Code for Continuous Integration168 words
  • Scenario 6: Structured Data Extraction185 words
  • Domain 1: Agentic Architecture & Orchestration169 words
  • Domain 1 Project — build a support agent, then make it a team1,191 words
  • Domain 2 Project — build tools your agent actually picks correctly919 words
  • Domain 2: Tool Design & MCP Integration157 words

Ready to study Claude Certified Architect - Foundations (CCAR-F)?

Practice tests, flashcards, and all study notes — free, no sign-up.

Start Studying

Ready to study Claude Certified Architect - Foundations (CCAR-F)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free
Claude Certified Architect - Foundations (CCAR-F) ResourcesExplore All HivesBlogHome

© 2026 BrainyBee. Free AI-powered exam prep.