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 request | Refined request | What Claude can now check |
|---|---|---|
| implement a function that validates email addresses | write a validateEmail function with example test cases, then run the tests | Named inputs with their expected true/false results |
| the build is failing | paste the error, fix it, verify the build succeeds, address the root cause | Whether the real error is gone and not just suppressed |
| fix the login bug | users report login fails after session timeout; write a failing test that reproduces it, then fix it | A 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.
Each refined request adds its own definition of done. For the email function that is example cases. For the build it is the real error plus a fix at the root cause. For the bug it is a failing test that reproduces it. Claude can then find and fix its own mistakes before handing the work back, instead of guessing again after a vague "that's not quite right".
“the build fails with this error: [paste error]. fix it and verify the build succeeds. address the root cause, don’t suppress the error”Source: code.claude.com
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?
When instructions in words keep being read inconsistently, show the transformation as concrete input/output pairs that Claude can test against. A longer spec can still be read more than one way. Library defaults give you the library's behaviour rather than yours. Tests that Claude writes from the same ambiguous spec encode Claude's own reading, so they can pass while the behaviour is still wrong.
“Simple instructions haven't produced consistent results”Source: claude.com
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?
Correct answer: A — Show Claude a sample legacy record whose middle-name field is null, along with the migrated record it should become, with that field as an empty string
- A. Correct. A concrete input record with a null middle name, paired with the exact output record showing an empty string, defines the intended behavior for this edge case and gives Claude an unambiguous target to fix and check against.
- B. A prose description that nulls are mishandled does not say which field is affected or what the migrated value must be. Claude has to guess the replacement, and it could pick a placeholder instead of the required empty string.
- C. Catching errors and continuing still leaves the null middle-name records out of the migrated data. The log would only document the dropped records, while the requirement is to migrate them with an empty string.
- D. Regenerating the script discards code that already works and gives Claude no new information about the expected null handling. The new version can drop or alter those records just as easily, and it may add unrelated defects.
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?
Correct answer: A — Write a few sample input rows with the exact JSON each should produce, including one row with an empty cell and one with a quoted comma, and give them to Claude before it writes the converter.
- A. Correct. Concrete input rows paired with the exact JSON they must produce, covering an empty cell and a quoted comma, state the mapping rules unambiguously where prose struggles. They give Claude a fixed target to implement against and to check each revision against.
- B. Incorrect. The mapping rules are described as hard to put precisely into words, and handling of empty cells, quoted commas and duplicate headers is where prose leaves room for interpretation. Refining a written description only repeats the ambiguity and gives the loop no concrete expected output.
- C. Incorrect. A library's default handling of empty cells, quoted commas and duplicate headers is generic and need not match the team's mapping rules. No expected output is supplied in advance, so the loop has nothing to check the converter against.
- D. Incorrect. The tests would encode Claude's own reading of a prompt that cannot pin down the rules, so they can pass while the behavior still differs from what the team wants. Expected outputs must come from the team, not from the implementer's assumptions.
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.
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.Have Claude implement the rate-limiting logic to pass the tests
- 2.Run the suite and read the actual failures: the assertion, the expected and actual values, and the traceback
- 3.Fix what the failures point to and run the suite again, repeating until every test passes
- 4.Have Claude write a full test suite from those criteria before any implementation exists
- 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
The tests come first, so 'done' is defined before any code exists. After that, each round is driven by real test failures, not by vague corrections, until the suite passes.
“Use a TDD approach: write comprehensive tests first, then implement the rate limiting logic to pass them.”Source: support.claude.com
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.
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?
Tests and input/output examples assume you already know what correct looks like, and here the architect doesn't. An interview brings decisions like cache invalidation and failure handling to the surface while they are still cheap to change. Letting Claude follow common practice builds its guesses into code, where they are harder to undo.
“Interview me one question at a time about anything ambiguous, prioritize questions where my answer would change the architecture.”Source: claude.com
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.
| Situation | How to report | Why |
|---|---|---|
| Failures in unrelated code paths | One message per issue, in sequence, with the exact failure text | Each fix can be confirmed alone, and a later break points to one change |
| One failure is downstream of another | All failures together, with how you think they relate | Fixing the root cause may clear the downstream failure, so there's no need to over-fix |
| Fixes would change the same code | All failures in one detailed message | Fixing 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?
These failures interact: test_orderTotal is probably downstream of the two helper bugs, and fixing those may make it pass with no change to orderTotal(). If you report everything together and say how the failures relate, Claude can plan one change at the root cause. Reporting orderTotal alone invites an unneeded fix to code that isn't broken. Sending the failures one at a time is for unrelated failures, and leaving a failure out means it might never get fixed.
“One of the failures (test_mean) is downstream of the other two, which quietly teaches the agent not to over-fix”Source: platform.claude.com
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?
Correct answer: A — Report each failure sequentially in its own message: first address the currency-formatting mismatch, and once confirmed fixed, the filename extension issue, because the two problems are independent.
- A. Correct. The CCAR-F exam guide's Task Statement 3.5 rubric distinguishes two cases: address multiple issues in a single detailed message when the fixes interact, but iterate sequentially -- fixing and confirming one before moving to the next -- when the issues are independent. The currency-formatting mismatch and the missing Windows file extension come from unrelated parts of the export module, so they are an independent pair and should be reported and fixed one at a time.
- B. Incorrect. Bundling both failures into one message is the right move only when the failures interact, where fixing one could affect or mask the other. These two defects are explicitly unrelated, a currency-formatting bug in the summary totals versus a missing file extension in the filename generator, which is exactly the case the guidance reserves for sequential iteration rather than a combined message.
- C. Incorrect. Sequential iteration means addressing each independent failure and confirming the fix before moving to the next one; it does not mean permanently withholding a known defect. Silently deferring the filename extension issue removes information Claude needs and risks the defect being forgotten, rather than simply resequencing when it gets fixed.
- D. Incorrect. Asking Claude to guess which failure is more severe and omitting the actual currency-formatting and filename-extension details removes the specific information Claude needs to diagnose and fix each issue, whether they are handled together or one at a time, and risks a misdiagnosis instead of speeding up the loop.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/best-practicesOfficial docs
“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“address the root cause”
↩︎ Concrete input/output examples for transformations“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.https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practicesOfficial docs
“Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns.”
↩︎ Concrete input/output examples for transformations - 3.https://claude.com/blog/best-practices-for-prompt-engineeringSecondary source
“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.
“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.
“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.
“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