Verification-Driven Agentic Coding
Agentic coding works best when the agent has a target it can check by itself.
Without a verification signal, the agent stops when the code looks plausible. With a signal, it can run the check, read the failure, change the code, and repeat until the output is actually better.
The Core Pattern
Section titled “The Core Pattern”- Ask the agent to inspect the relevant code path.
- Define the smallest check that proves the behavior.
- Write or identify that check before changing the implementation.
- Let the agent implement the fix.
- Make the agent run the check and show evidence.
For code, the check might be a failing unit test. For UI, it might be a screenshot comparison. For data work, it might be a fixture diff. For infrastructure, it might be a dry-run plan.
Good Verification Signals
Section titled “Good Verification Signals”| Signal | Best for | Example |
|---|---|---|
| Unit test | Pure functions, edge cases, regressions | npm test -- auth-refresh.test.ts |
| Integration test | API, database, service boundaries | pytest tests/api/test_login.py |
| Build/typecheck | Compile-time and contract errors | npm run build, tsc --noEmit |
| Lint/format | Mechanical consistency | npm run lint |
| Screenshot | Visual UI changes | Browser or Playwright screenshot after the edit |
| Fixture diff | Parsers, serializers, generated output | Compare generated JSON against expected output |
| Log replay | Debugging production-like failures | Pipe an error log into the task context |
| Dry run | Cloud, migration, deployment work | terraform plan, migration preview, --dry-run |
TDD Prompt
Section titled “TDD Prompt”Investigate this bug first. Do not change implementation yet.
Write the smallest failing test that reproduces the reported behavior.Run only that test and confirm it fails for the expected reason.Then implement the fix, rerun the test, and show the final command output.This works because the agent gets a concrete loop:
flowchart LR
A["Inspect code"] --> B["Create failing check"]
B --> C["Implement change"]
C --> D["Run check"]
D --> E{"Passes?"}
E -->|No| C
E -->|Yes| F["Return evidence"]
UI Prompt
Section titled “UI Prompt”Use the existing app locally.
Reproduce the UI issue, take a screenshot, apply the smallest fix,take another screenshot, and compare the result against the expected state.Do not call the task done unless the visual difference is resolved.For UI work, a text description is often not enough. Screenshots give the agent a readable result, especially when spacing, overflow, contrast, and layout are involved.
Evidence To Ask For
Section titled “Evidence To Ask For”Ask for evidence, not just a claim:
- the exact command it ran
- the relevant passing test output
- before/after screenshots for visual work
- the changed files
- any checks it could not run and why
Common Failure Modes
Section titled “Common Failure Modes”| Failure | What to do instead |
|---|---|
| Agent updates snapshots without explaining why | Ask it to prove the new output is correct |
| Agent runs the whole suite too early | Start with the smallest relevant test |
| Agent claims success without output | Require command output or screenshot evidence |
| Agent suppresses an error | Tell it to fix root cause, not silence the check |
| No runnable tests exist | Start with a smoke script, fixture, or manual checklist |
When To Skip This
Section titled “When To Skip This”Do not force a full TDD loop for small documentation edits, typo fixes, or obvious one-line changes. Use the cheapest meaningful check: build the docs, run markdown lint, or read the changed page.