Task Statement 3.5·Domain 3 — 20% of exam
Iterative Refinement Techniques
Apply iterative refinement techniques for progressive improvement
Official Exam Guide Objectives
The objectives below are quoted from Anthropic's Claude Certified Architect – Foundations exam guide, v1.1. Read the exam guide summary for the full blueprint.
Knowledge of
- Concrete input/output examples as the most effective way to communicate expected transformations when prose descriptions are interpreted inconsistently
- Test-driven iteration: writing test suites first, then iterating by sharing test failures to guide progressive improvement
- The interview pattern: having Claude ask questions to surface considerations the developer may not have anticipated before implementing
- When to provide all issues in a single message (interacting problems) versus fixing them sequentially (independent problems)
Skills in
- Providing 2-3 concrete input/output examples to clarify transformation requirements when natural language descriptions produce inconsistent results
- Writing test suites covering expected behavior, edge cases, and performance requirements before implementation, then iterating by sharing test failures
- Using the interview pattern to surface design considerations (e.g., cache invalidation strategies, failure modes) before implementing solutions in unfamiliar domains
- Providing specific test cases with example input and expected output to fix edge case handling (e.g., null values in migration scripts)
- Addressing multiple interacting issues in a single detailed message when fixes interact, versus sequential iteration for independent issues
What You Need to Know
Nobody gets the output they wanted on the first attempt, and the exam is less interested in that fact than in what you do next. There are named techniques for steering Claude Code, they suit different failure modes, and the testable skill is picking the right one rather than trying all of them.
The Technique Hierarchy
They are not interchangeable. Each answers a different symptom, and an exam item gives you the symptom and asks for the technique, so learn them by symptom rather than by name:
1. Concrete input/output examples (most effective for inconsistent interpretation)
Where a transformation described in prose comes back done differently each time, the instinct is to describe it more carefully. That does not work, because the problem is not that the description was unclear — it is that any description leaves room to interpret.
Show two or three transformations instead, input beside output:
Input:
getUserData(userId: string): Promise<UserData>
Expected output:
getUserData(userId: string): Promise<Result<UserData, ApiError>>Input:
fetchOrders(customerId: string): Promise<Order[]>
Expected output:
fetchOrders(customerId: string): Promise<Result<Order[], ApiError>>A pattern demonstrated twice generalises more reliably than a pattern described at any length, because there is nothing left to infer about intent. Two or three cases are enough to establish it. This is where to start whenever the complaint is inconsistency.
Same prompt, three shapes — examples make it one, step 1: A prose instruction is run three times
Choosing which examples to show
The two or three pairs should not be variations of one case. Each should carry a different decision, and the useful rule for picking them is: show the cases where a reasonable implementer would guess wrong. A single pair gives the model an instance to copy, not a rule to infer; pairs of identical shape leave it unclear which features matter.
Take the instruction "normalise the customer records: clean up the names and standardise the phone numbers". Three pairs settle what that sentence never raised:
in : {"name": " john SMITH ", "phone": "(415) 555-0134"}
out: {"name": "John Smith", "phone": "+14155550134"}
in : {"name": "o'brien, MARY-JANE", "phone": "415.555.0199 x22"}
out: {"name": "Mary-Jane O'Brien", "phone": "+14155550199;ext=22"}
in : {"name": "ACME LOGISTICS LTD", "phone": "+44 20 7946 0958"}
out: {"name": "ACME Logistics Ltd", "phone": "+442079460958"}| Question the prose left open | Pair that answers it |
|---|---|
| Stray whitespace, mixed case, national number format | First |
| Comma-inverted names, hyphens and apostrophes, phone extensions | Second |
| International numbers; company names are not title-cased like personal names | Third |
This is the same mechanism as few-shot prompting (Task Statement 4.2), applied in a Claude Code conversation rather than in an API prompt.
2. Test-driven iteration (most effective for complex transformations)
Write the tests before the change and let them state the requirement:
- The ordinary case, transformed the way you actually want it
- The awkward ones — nulls, empty collections, values sitting exactly on a boundary
- The error cases — invalid input or missing data, and what should happen instead (a specific error, a default value)
- Anything with a timing or throughput requirement attached
Then hand over the failures. A failing assertion is feedback with no interpretive surface at all — it names what was expected and what arrived, and nothing about that can be read two ways.
FAIL: preservesNullsThroughMigration
Expected: {"middleName": null}
Actual: {"middleName": ""}Nothing needs adding to that. The gap is stated in the output.
A failing test leaves nothing to interpret, step 1: Prose feedback — can you fix the null handling
The loop is: write the suite first, have Claude implement against it, run it, paste the failures back, and repeat until everything passes. Set against a requirement written in prose, the suite wins on every count:
| Prose requirement | Test suite | |
|---|---|---|
| Ambiguity | High | None: a test passes or it does not |
| Who judges the output | You, by reading it | The suite |
| Protection against regressions | None | Built in: a fix that breaks an earlier case fails visibly |
| Edge cases | Easily forgotten | Listed before any code exists |
Paste the failure, do not describe it
"The null handling still isn't right" gives Claude nothing new, so the next attempt is a guess. The raw output does the work:
FAILED tests/test_migrate.py::test_null_middle_name
assert result["full_name"] == "Ada Lovelace"
AssertionError: assert 'Ada None Lovelace' == 'Ada Lovelace'
FAILED tests/test_migrate.py::test_missing_phone
KeyError: 'phone' at migrate.py:64Failure text carries four facts: the exact input, the expected value, the actual value and the location. A summary in your own words loses all four. (Structured tool errors in Task Statement 2.2 rest on the same principle.) Paste the failures only; handing back the whole test file each round adds bulk without adding signal, because the passing tests say nothing about the gap.
One failing case for one mishandled edge case
The exam guide names a narrower use of the same idea: "specific test cases with example input and expected output to fix edge case handling (e.g., null values in migration scripts)". When a stem says the script mishandles nulls, the answer is a concrete case showing the null input and the output you expect, not an instruction to "handle nulls carefully". Tests written after the implementation are weaker for the same reason they are easier: the code already written frames what gets tested, so the edge cases it never considered stay unexplored.
3. Interview pattern (most effective for unfamiliar domains)
When the domain is unfamiliar, the risk is not that Claude will misunderstand you — it is that you will forget to ask for something you did not know mattered. Inverting who asks the questions surfaces it.
Instead of prescribing a solution:
"Add a caching layer in front of the orders API"
Use the interview pattern:
"I want to put a caching layer in front of the orders API. Before you write anything, ask me what you need to know — requirements, edge cases, constraints I may not have thought about."
What comes back tends to be the things experience would have prompted: how invalidation works (TTL, write-through or event-driven), what TTL suits the data, how much staleness is tolerable per endpoint, whether the cache is shared or per user (and whether tenants must be kept apart), what consistency readers need, whether cached values are personalised and could be served to the wrong person, whether a cold key needs protection against a stampede of simultaneous requests, and whether an unavailable cache should fail open (serve from the origin) or fail closed. You had thought about "add a cache"; half of those answers change the design.
Two additions make the prompt sharper: ask Claude to concentrate on decisions that would be expensive to change later, and tell it not to propose an implementation until you have answered.
When to interview, and when not to
Use it when the domain is unfamiliar, when an early wrong decision would be costly, or when you cannot state the requirement precisely. Do not use it when the requirement is already clear: the questions then only add delay, and you end up answering "whatever you think" to things that do not matter.
Interview pattern or plan mode?
Both come before implementation, and they point in different directions. Plan mode (Task Statement 3.4) has Claude read the codebase and propose an approach. The interview draws requirements out of the developer.
| What is unknown | Reach for |
|---|---|
| The code | Plan mode |
| The requirements | Interview pattern |
| Both | Interview first, then plan |
Two different gaps, two different fixes, step 1: Examples — a transmission gap
Batch vs Sequential Feedback
Delivery matters as much as content, and the deciding question is whether the fixes touch each other. The working test: does fixing A change what the right fix for B is? If yes, they interact. For independent issues the mirror test is whether they could ship in separate pull requests.
Single message (batch) when fixes interact with each other:
Where changing the error handling also changes the logging format and the response shape, all three belong in one message. Sent separately, each fix is made without sight of the others, so the second contradicts the first and the third has to undo both.
Three changes needed (they interact with each other):
1. Error responses must include an error code field
2. Logging must include the error code in structured format
3. The client SDK type definitions must reflect the new error code fieldSequential iteration when issues are independent:
Where the naming convention and the indentation have nothing to do with each other, send them one at a time. Bundled, they compete for attention and it becomes ambiguous which instruction governs which part of the file.
First message: "Rename the exported functions to camelCase"
[let it finish]
Second message: "Now switch indentation to two spaces"Batch what interacts, sequence what doesn't, step 1: Interacting issues, sent one at a time
Two further examples of the split. "The pagination is off by one, the sort order flips on the second page, and the total count excludes filtered rows" is three symptoms of one piece of query-building logic: reported one at a time you get three patches that fight each other, where the fix for the second undoes the first and the fix for the third brings the first bug back. "The README has a broken link, the retry backoff should be exponential, and the log timestamps are local instead of UTC" is three unrelated areas: taken one at a time, each change stays small enough to review and can be reverted on its own.
| Interacting: one message | Independent: sequential | |
|---|---|---|
| Size of the change | Larger, but coherent | Small each time |
| What goes wrong if you choose the other way | Split up, the fixes thrash and reintroduce each other's bugs | Bundled, the diff is hard to review and a regression cannot be pinned on one change |
| How to verify | Test the combined behaviour | Verify each before raising the next |
Coupling is the only criterion. How long each fix takes, how severe it is and which file it lives in do not decide the grouping: interaction follows the shared data structure, not the file boundary, so an error shape and the client types that mirror it sit in different files and still belong in one message.
Example-Based Communication in Practice
Moving from prose to examples follows a repeatable sequence:
- Observe inconsistency: the same instruction produces a different result on each run.
- Switch to examples: supply two or three before/after pairs that pin the transformation exactly.
- Verify generalisation: try a case the examples did not cover, to confirm the pattern transferred rather than the instances being copied. With the two
Resultpairs above,deleteAccount(accountId: string): Promise<void>is a good hold-out: it should come back asPromise<Result<void, ApiError>>on every run. - Add edge case examples if needed: where the ordinary case is right and an unusual one is not, demonstrate the unusual one specifically.
Volume adds nothing here. A pair covering the normal case plus one that pins down a genuinely awkward variant is sufficient; beyond that you are mostly re-demonstrating a pattern already established, at the cost of the context it occupies.
When Each Technique Applies
| Situation | Technique |
|---|---|
| Prose description interpreted differently each time | Concrete input/output examples |
| Complex transformation with many edge cases, or behaviour that must be verifiably correct | Test-driven iteration |
| One edge case mishandled (nulls, empty values, unusual characters such as non-ASCII text) | A specific failing case with its expected output |
| Working in an unfamiliar domain; you do not know what to specify | Interview pattern |
| The code is unfamiliar, not the requirement | Plan mode (Task Statement 3.4) |
| Multiple issues that affect each other | Batch feedback (one message) |
| Multiple independent issues | Sequential feedback |
| The behaviour must happen every time, without exception | A hook, not more iteration |
The last row marks the limit of this whole task statement. Refinement improves what Claude produces; it cannot guarantee it. The exam guide separates "hooks for deterministic guarantees" from "prompt instructions for probabilistic compliance" (Task Statement 1.5), and another round of feedback is still a prompt.
Deep Dive
The technique hierarchy above is about what to say when refining Claude Code's output. Claude Code also has session-level mechanics that support the same iterative loop — focusing context, branching to compare approaches, and undoing an iteration that went the wrong way.
/compact with custom instructions to focus an iteration session
/compact [instructions] replaces conversation history with a summary, optionally focused on what you specify. For more control during a long refinement session, run /compact <instructions> — for example, /compact Focus on the API changes — so the summary that survives compaction is the part still relevant to the current iteration, not a generic recap.
Sourcescode.claude.com › sessionscode.claude.com › best-practicesfetched 2026-07-30
Session forking to compare divergent fixes
Branching creates a copy of the conversation so far and switches you into it, leaving the original intact. From the CLI, combine --continue or --resume with --fork-session to create a new session ID rather than reusing the original — useful when you want to try two different fixes for the same interacting-issues batch without losing the baseline conversation.
Sourcecode.claude.com › sessionsfetched 2026-07-30
Checkpoints and /rewind for reverting a bad iteration
Every user prompt creates a new checkpoint automatically. Run /rewind, or press Esc twice on an empty prompt, to open the rewind menu, which offers restoring code and conversation together, conversation only, or code only. This is "local undo" that complements — but doesn't replace — git. Tracking is per file and starts with Claude's own file-editing tools: "Once Claude has edited a file with its file editing tools in your conversation, /rewind undoes changes that Bash commands make to that file afterward. A file that only Bash commands changed isn't tracked and stays as it is." A file created or deleted only by a shell command therefore has to be recovered with git. Snapshots are kept for the 100 most recent checkpoints in a session.
Sourcecode.claude.com › checkpointingfetched 2026-11-19
Writer/Reviewer pattern as a check on self-correction
A fresh context improves code review because Claude won't be biased toward code it just wrote. The documented Writer/Reviewer pattern has one session implement while a second, independent session reviews the implementation and the first session then addresses that feedback — the same split works for tests, with one Claude writing tests and another writing code to pass them. This is a useful cross-check after several rounds of self-driven iteration, when you want an opinion untainted by the reasoning that produced the current draft.
Sourcecode.claude.com › best-practicesfetched 2026-07-30
The Explore-Plan-Implement-Commit workflow as the iteration scaffold
The recommended four-phase workflow — Explore, Plan, Implement, Commit — gives iterative refinement a shape: explore and plan happen before the first draft, so the early rounds of refinement (examples, tests, the interview pattern) apply during Implement, against a plan that already accounted for edge cases and constraints.
Sourcecode.claude.com › best-practicesfetched 2026-07-30
Quick Reference
| Situation | Technique |
|---|---|
| Prose interpreted differently each run | Concrete input/output examples (2-3 pairs) |
| Complex transformation, many edge cases | Test-driven iteration — share test failures |
| One edge case mishandled (e.g. nulls in a migration) | One specific test case: the null input and its expected output |
| Unfamiliar domain, might miss considerations | Interview pattern — let Claude ask questions first |
| Unknown code vs unknown requirements | Plan mode vs interview; both unknown → interview, then plan |
| Fixes interact with each other | Batch feedback in a single message |
| Fixes are independent | Sequential feedback, one at a time |
| Interacting or independent? | Does fixing A change the right fix for B? Could they ship in separate PRs? |
| Behaviour must hold every time | A hook — iteration is still a prompt |
| A rewind leaves a Bash-only change in place | Expected: such files are not tracked; recover with git |
| Long session losing focus | /compact <instructions> — targeted summary |
| Comparing two divergent fixes | --fork-session (with --continue/--resume) or /branch |
| An iteration went the wrong way | /rewind or Esc-Esc — restore code, conversation, or both |
| Want an unbiased second opinion | Writer/Reviewer pattern — fresh session reviews, no shared reasoning context |
| Scaffold for the whole cycle | Explore → Plan → Implement → Commit |
Exam Traps
The remaining wrong answers this task statement dangles are each taken apart where the technique is taught above: describing a failure instead of pasting it, interviewing when the requirement is already clear, writing the tests after the implementation, splitting by file or severity instead of by coupling, and using another round of feedback to enforce a guarantee.
How This Is Tested
Batch versus sequential is the sharpest distinction in this task statement and tends to get an item of its own. The other stems give a symptom and ask for the technique.
| Stem signal | Answer | Wrong-answer pattern beside it |
|---|---|---|
| Three attempts at a data-cleaning transformation, three interpretations | Two or three concrete input/output pairs, each chosen where a reasonable implementer would guess wrong | Rewrite the prose longer or more emphatically; start an interview |
| A migration script mishandles nulls | One specific test case with the null input and its expected output | "Tell it to handle nulls carefully"; a prose list of every edge case |
| Fixes keep regressing earlier cases, or the result must be verifiably correct | Write the suite first (behaviour, edge cases, performance), then paste the failures | Summarise the failures; add more prose; write the tests after the code |
| Adding caching to a system in a domain the developer does not know | Interview pattern first | Examples or a test suite, which need a requirement the developer cannot yet state |
| The developer knows the requirement but not the codebase | Plan mode (Task Statement 3.4) | Interview pattern |
| Four bugs in the same pagination logic | One detailed message with all of them | One message per bug |
| A documentation typo, a backoff bug and a timezone bug | Sequentially, verifying each | One combined message "to save rounds" |
| A rule must hold on every run, without exception | A hook (Task Statement 1.5) | Another, firmer round of feedback |
Practice Scenario
Your migration script's ordinary rows transform correctly now that two before-and-after pairs are in the prompt, but each round of feedback fixes one awkward case and regresses another — nulls, empty collections, rows sitting exactly on the cutoff date. The script also has to finish inside a twenty-minute window. What's the most effective next step?
Practice Questions
Exam simulator
Question 1 of 13
Scenario · Developer Productivity with Claude
You asked Claude, in two paragraphs of prose, to convert print-style log calls to structured logging. Across three runs the field names drift (userId, user_id, uid), and error objects are sometimes stringified and sometimes nested. Your written description has not changed between runs. What change would most effectively make the output consistent?