Iterative refinement techniques
What this covers
- Use concrete input/output examples where prose is being read inconsistently
- Drive iteration from test failures
- Decide whether to batch fixes or sequence them
- Use the interview pattern to surface considerations you did not know to specify
- Choose a test suite over prose or examples when a fixed edge case keeps regressing, because only a suite is re-run
- Apply interaction rather than ownership as the test for batching two fixes
Key terms
- Few-shot examples
- A small set of examples included in a prompt to show the model the expected behavior.
Examples beat description
When a prose description of a transformation keeps producing inconsistent results, the fix is usually not more prose. Two or three concrete input/output examples communicate the expected transformation far more precisely than a paragraph describing it.
This holds for edge cases too. Null handling in a migration script is much better specified by an example pair showing the input and the expected output than by a sentence about nulls.
Test-driven iteration
Write the suite first — expected behavior, edge cases, performance requirements — then iterate by sharing failures. Each failure is specific, reproducible, and unambiguous, which makes it far better iteration fuel than a description of what seems wrong.
A suite is re-run after every change. Instructions and examples in a message are read once, but a test checks the same requirement again each time the suite runs. Add a regression test when a previously fixed edge case keeps returning.
The interview pattern
Have Claude ask you questions before implementing. This surfaces considerations you had not thought to raise — cache invalidation, failure modes, edge conditions — and it's most valuable in domains you don't know well, precisely because that's where you don't know what you've failed to specify.
Batch or sequence?
The deciding factor is whether the problems interact.
- Interacting issues go in a single detailed message. Fixing them one at a time means each fix is made without knowledge of the others, and they undo each other.
- Independent issues are better sequenced. Smaller steps, clearer attribution when something regresses.
Interaction is the test, not ownership: two defects raised by two teams that touch the same code still go together.
Set limits on an automated loop
"Apply a fix, re-run the failing tests, refine until they pass" is reasonable by hand and risky to automate without a limit. Otherwise, only the runner timeout stops the loop. The job can consume all available runner time and block every change waiting behind it in a merge queue.
Choose the maximum number of passes before the run starts. Cap the passes and report the outcome even when tests still fail. “Still failing after three passes” gives the author useful information; an endless run doesn't.
input/output examplestest-driven iterationinterview pattern
Field note — common misconceptions
- MythThat a clearer paragraph beats two worked examples
- ActuallyTwo or three input/output pairs specify a transformation more precisely than prose does.
- MythThat every batch of issues should be sent at once
- ActuallySend interacting problems together and independent ones separately; interaction is the test.
- MythThat the interview pattern is for when you are unsure what you want
- ActuallyIt is most valuable where you know least, because that is where you cannot tell what is missing.
Guided review
Review this lesson as a study deck
Review the lesson's main ideas in five guided slides, then test yourself with three flashcards.
Open Task 3.5 study deckCross-domain reasoning
Connect this idea
Evaluation continues through delivery
Clear criteria, examples, repeated testing, continuous integration, independent review, and human review all provide evidence that a change works as intended.
- 3.6 · Integrate Claude Code into CI/CD pipelines
- 4.1 · Design prompts with explicit criteria to improve precision and reduce false positives
- 4.2 · Apply few-shot prompting to improve output consistency and quality
- 4.6 · Design multi-instance and multi-pass review architectures
- 5.5 · Design human review workflows and confidence calibration
Applied practice
Practice this lesson in a lab
Use a related lab to create a decision, implementation or diagram, evidence record, and review.
- Lab 6 · Claude Code configuration hierarchy
Place guidance, reusable procedures, scoped rules, and enforcement in the mechanism that fits each one.