CertSafari
    Anthropic Claude Certified Architect – Foundations (CCAR-F)· Lessons

    Domain 3 · Lesson 17/30

    Iterative refinement in Claude Code: examples, tests and interviews

    Apply iterative refinement techniques for progressive improvement

    16 min read
    3.33% of exam
    6 sources
    Published 20 Oct 2026
    Docs as of 14 Oct 2026

    What you will be able to do

    • Use 2–3 concrete input/output examples when a prose description of a transformation keeps getting read in different ways
    • Write a test suite covering behaviour, edge cases and performance before implementation, then iterate by giving Claude the actual failures
    • Use the interview pattern to bring up design considerations before building in an unfamiliar domain
    • Decide whether to report failures in one detailed message or one at a time, depending on whether their fixes interact

    Key concept

    Iterating against a concrete target — Claude improves fastest when each round is checked against something it can actually test, such as example outputs, a failing test or an answered question, instead of a description it has to interpret. Each refinement technique gives Claude that target sooner or in a sharper form.

    1.Why the first attempt is rarely the last

    Iterative refinement means improving Claude's output over several rounds, where each round gives Claude better information than the one before. The weak version is familiar: Claude writes something, you say "that's not quite right", and it guesses again. The strong version replaces each vague correction with something Claude can check its work against, so every round narrows the gap rather than moving it somewhere else.

    Compare two requests for the same function. "Implement a function that validates email addresses" leaves Claude to decide what valid means. The improved version names cases, user@example.com is true, invalid is false, user@.com is false, and tells Claude to run the tests after implementing. The second prompt contains its own definition of done, so Claude can find and fix its own mistakes before you ever see them.

    Vague requests against requests that give Claude a target to iterate on
    Vague requestRefined requestWhat Claude can now check
    implement a function that validates email addresseswrite a validateEmail function with example test cases, then run the testsNamed inputs with their expected true/false results
    the build is failingpaste the error, fix it, verify the build succeeds, address the root causeWhether the real error is gone and not just suppressed
    fix the login bugusers report login fails after session timeout; write a failing test that reproduces it, then fix itA reproducing test that must go from red to green

    Repeated vague correction has a cost of its own. Each failed attempt stays in the conversation, so after a few rounds the context is full of approaches that didn't work. Claude Code's guidance is blunt about this: after two failed corrections, run /clear and write a better initial prompt that includes what you learned. The techniques below are what that better prompt usually contains.

    Checkpoint 1 of 8· Match them up

    Each vague request below was rewritten so that Claude has something to check its work against. Match each vague request to what its refined version lets Claude check.

    Tap a term, then the definition that fits it.

    Sources1

    2.Concrete input/output examples for transformations

    For transformations, such as reshaping records, converting formats or migrating schemas, a description in words is often the weakest way to state what you want. "Handle nulls properly" or "map empty cells sensibly" each allow several reasonable readings, and Claude picks one. Once you see that a prose description is being read inconsistently, show the transformation itself: 2–3 concrete inputs, each paired with the exact output it should produce. This applies few-shot examples to interactive Claude Code work. Examples taken from your real data and covering the edge cases leave Claude no room to guess.

    The null middle-name case shows why examples work better than prose. "Handle nulls properly" doesn't say whether a null should become an empty string, stay null, get a default value or be skipped, and dropping the record is one of the readings Claude already chose. A single record pair, middle_name: null in and middle_name: "" out, answers that question completely. The other tempting fixes fail for different reasons. A try/except that logs and continues suppresses the symptom instead of fixing the root cause, and the records still don't migrate. Regenerating the whole script in a fresh session goes back to the same schema description that produced the bug, so the null handling is just as likely to come out wrong again.

    The same reasoning applies before any code exists. Suppose a CSV-to-JSON converter where empty cells, quoted commas and duplicate headers all need exact handling. A longer prose specification is still open to interpretation. Building on a parsing library's defaults gives you that library's behaviour, not yours. A few sample rows, one with an empty cell and one with a quoted comma, each written out with the exact JSON it must become, fix the rules in a form Claude can test against.

    Start small. One example is often enough. Add a second or third only if the output still doesn't match, and pick each new one to cover a different edge case so Claude doesn't pick up an accidental pattern, for example that every row in your examples happens to have a middle name.

    Checkpoint 2 of 8· Check yourself

    You are building a CSV-to-JSON converter with Claude. Twice, Claude has handled empty cells and quoted commas differently from what your written spec meant. What should you give Claude next?

    Checkpoint 3 of 8· Exam question

    A data engineer is iterating with Claude Code on a migration script that transforms legacy customer records into a new schema. After the first pass, records with a null middle-name field are being dropped instead of migrated with an empty string. What is the most effective way to fix this specific edge case handling?

    Checkpoint 4 of 8· Exam question

    A team lead wants Claude Code to implement a CSV-to-JSON conversion utility whose column-to-field mapping rules are difficult to describe precisely in words, since the exact handling of empty cells, quoted commas, and duplicate headers matters. Which approach best sets up an effective iterative refinement loop before implementation begins?

    Sources123

    3.Test-driven iteration: write the tests, then share the failures

    Test-driven iteration turns your requirements into an executable suite before any implementation exists, then uses the suite's failures to drive each round. The suite should cover three things: expected behaviour, edge cases, and performance requirements. Once it exists, "done" stops being a matter of opinion. Claude implements, runs the suite, reads the failures and fixes them, and repeats until everything passes.

    A test-first prompt: concrete success criteria, then an instruction to write tests before implementingtext
    Add rate limiting to the /api/search endpoint.
    
    The rate limiter should:
    - Allow 100 requests per minute per API key
    - Return 429 status when limit exceeded
    - Reset limits after 60 seconds
    - Track different API keys independently
    
    Use a TDD approach: write comprehensive tests first, then implement the rate limiting logic to pass them.

    Every criterion in that prompt can be checked by a test: a request count, a status code, a reset window, independence between keys. That is what makes the loop work without you watching. Claude can iterate on the implementation without supervision, using test failures to find and fix problems, and when you review the result, the tests and the implementation arrive together.

    When you are the one passing results back, give Claude the actual failure: the assertion, the expected and actual values, the traceback. Do not give it your summary of the failure. "The tests are failing" puts Claude back to guessing. A pasted failure says exactly which input broke and how. Edge cases found later work the same way. A bug report becomes a failing test with a specific input and its expected output, and that test stays in the suite, so the bug can't come back unnoticed.

    Checkpoint 5 of 8· Put it in order

    Put the rounds of a test-driven iteration loop for a new rate limiter in order.

    1. 1.Have Claude implement the rate-limiting logic to pass the tests
    2. 2.Run the suite and read the actual failures: the assertion, the expected and actual values, and the traceback
    3. 3.Fix what the failures point to and run the suite again, repeating until every test passes
    4. 4.Have Claude write a full test suite from those criteria before any implementation exists
    5. 5.State checkable success criteria: 100 requests per minute per API key, a 429 status over the limit, a reset after 60 seconds, and separate limits for each key

    Sources4

    4.The interview pattern for unfamiliar domains

    Examples and tests assume you already know what correct looks like. In an unfamiliar domain you often don't. You may not know what questions to ask, what good looks like, what has been tried before, or which problems to avoid. The interview pattern reverses the usual direction of the conversation: before writing any code, Claude questions you, so that considerations you hadn't thought of come up while they are still cheap to deal with.

    An interview prompt that asks for questions first and a written spec as the outputtext
    I want to build [brief description]. Interview me in detail using the AskUserQuestion tool.
    
    Ask about technical implementation, UI/UX, edge cases, concerns, and tradeoffs. Don't ask obvious questions, dig into the hard parts I might not have considered.
    
    Keep interviewing until we've covered everything, then write a complete spec to SPEC.md.

    Take an architect building a real-time collaborative editor for the first time. Left alone, Claude would make choices based on common practice. An interview instead gets the architect to decide on a cache invalidation strategy, how conflicting edits are resolved, and what happens when a client drops mid-edit, before any of those choices are built into code. Asking Claude to prioritise questions whose answers would change the architecture puts the expensive decisions first. Small changes to a spec can lead to very different implementations, and once code exists it is harder for an agent to undo earlier changes.

    Each technique fits a different situation. The interview pattern is for when you don't yet know the requirements. Examples and tests are for when you know them but haven't stated them in a checkable form. An interview often ends in a spec, and the spec's cases become the test suite.

    Checkpoint 6 of 8· Check yourself

    An architect is building a real-time collaborative editor for the first time. They don't yet know how cache invalidation, conflicting edits or clients dropping mid-edit should be handled. What should they ask Claude to do before any code is written?

    Sources15

    5.One message for interacting issues, one at a time for independent ones

    When a test run returns several failures, how you report them affects the next round. The rule depends on one question: do the fixes interact?

    Independent issues go one at a time. A currency-formatting bug and a missing file extension are in unrelated code. Fixing one tells you nothing about the other, and putting them in one request mixes two changes that should each be confirmed separately. Report the first with its exact failure, confirm the fix, then report the second. Each prompt does one thing well, and if a later run breaks, you know which change caused it. The same applies to a rounding error, an off-by-one error and a missing null check that come from unrelated parts of a function. Hiding a failure to "avoid distracting" Claude is not the same thing: sequential means all of them get fixed, one after another, not that some get dropped.

    Interacting issues go in one detailed message. Some failures share a cause, or their fixes affect the same code. A small test package shows the pattern. mean() calls add and divide internally, so its failing test is downstream of the two real bugs, and once those are fixed, test_mean passes without any change to mean(). Reporting the mean failure by itself invites an unnecessary fix to code that was never broken. When fixes interact, put every related failure, and how you think they relate, into one message so Claude can plan a single coherent change rather than patching each symptom in turn.

    Choosing how to report multiple failures
    SituationHow to reportWhy
    Failures in unrelated code pathsOne message per issue, in sequence, with the exact failure textEach fix can be confirmed alone, and a later break points to one change
    One failure is downstream of anotherAll failures together, with how you think they relateFixing the root cause may clear the downstream failure, so there's no need to over-fix
    Fixes would change the same codeAll failures in one detailed messageFixing them separately could make one fix undo or conflict with another

    Checkpoint 7 of 8· Check yourself

    In a checkout module, orderTotal() calls applyDiscount() and addTax() internally. The latest run fails all three tests: test_applyDiscount, test_addTax and test_orderTotal. How should you report these failures to Claude?

    Checkpoint 8 of 8· Exam question

    A test run against a newly generated report-export module in Claude Code produces two failures: a currency-formatting mismatch in the summary totals and a completely unrelated failure where the export filename generator omits the file extension on Windows paths. How should these two failures be presented to Claude for the next iteration?

    Sources163

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “write a validateEmail function. example test cases: user@example.com is true, invalid is false, user@.com is false. run the tests after implementing”
      ↩︎ Why the first attempt is rarely the last
      “After two failed corrections, /clear and write a better initial prompt incorporating what you learned.”
      ↩︎ Why the first attempt is rarely the last
      “write a failing test that reproduces the issue, then fix it”
      ↩︎ Why the first attempt is rarely the last
      “a verification subagent or a dynamic workflow that checks its own findings has a fresh model try to refute the result”
      ↩︎ Concrete input/output examples for transformations
      “Don't ask obvious questions, dig into the hard parts I might not have considered.”
      ↩︎ The interview pattern for unfamiliar domains
      “the build fails with this error: [paste error]. fix it and verify the build succeeds.”
      ↩︎ One message for interacting issues, one at a time for independent ones
      “Always provide verification (tests, scripts, screenshots).”
      ↩︎ Key concept
      “a verification subagent or a dynamic workflow that checks its own findings has a fresh model try to refute the result”
      ↩︎ Exam trap 2
      “address the root cause”
      ↩︎ Exam trap 3
      “the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don’t suppress the error”
      ↩︎ Checkpoint
      “write a validateEmail function. example test cases: user@example.com is true, invalid is false, user@.com is false. run the tests after implementing”
      ↩︎ Prediction
    2. 2.
      “Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”
      ↩︎ Concrete input/output examples for transformations
    3. 3.
      “Start with one example (one-shot). Only add more examples (few-shot) if the output still doesn't match your needs.”
      ↩︎ Concrete input/output examples for transformations
      “Break into multiple prompts (chaining). Each prompt should do one thing well.”
      ↩︎ One message for interacting issues, one at a time for independent ones
      “Simple instructions haven't produced consistent results”
      ↩︎ Exam trap 1
      “Break into multiple prompts (chaining). Each prompt should do one thing well.”
      ↩︎ Exam trap 4
      “Simple instructions haven't produced consistent results”
      ↩︎ Checkpoint
    4. 4.
      “Claude can iterate on the implementation without your supervision, using test failures to identify and fix problems.”
      ↩︎ Test-driven iteration: write the tests, then share the failures
      “Specify success criteria rather than vague goals like "improve" or "fix"”
      ↩︎ Test-driven iteration: write the tests, then share the failures
      “Use a TDD approach: write comprehensive tests first, then implement the rate limiting logic to pass them.”
      ↩︎ Checkpoint
    5. 5.
      “You may not know what questions to ask, what good looks like, what historical work has been done, or what potholes to avoid.”
      ↩︎ The interview pattern for unfamiliar domains
      “Interview me one question at a time about anything ambiguous, prioritize questions where my answer would change the architecture.”
      ↩︎ The interview pattern for unfamiliar domains
    6. 6.
      “mean() calls add and divide internally, so once those are fixed test_mean starts passing on its own without any direct edit to mean().”
      ↩︎ One message for interacting issues, one at a time for independent ones
      “One of the failures (test_mean) is downstream of the other two, which quietly teaches the agent not to over-fix”
      ↩︎ Checkpoint

    Spotted a mistake, or was something unclear? Tell us.