The 2025 Stack Overflow survey found 66% of developers overrun their estimates debugging AI-generated code, and industry talks report that a majority of initial LLM refactor suggestions contain at least one flaw.
Tier: Core · Workflow area: Verification & Trust
The skill is not avoiding AI output — it is a fast triage discipline: diff-vs-intent review, boundary tests at the edges, and a deliberate repair-vs-regenerate decision instead of an open-ended debugging spiral.
Skip this playbook for throwaway scripts and prototypes where wrong behavior is cheap and visible.
Diff-vs-intent pass (5 minutes, no execution). Read the diff against what you asked for, hunting three specific defect classes that dominate AI output:
pd.read_json(orient="records_strict"), redis.expire_at_ms(...)). Hover/jump-to-definition on every unfamiliar symbol.Optional, an exception swallowed into a log line, a default parameter added.Boundary probe. Generated code is usually right in the middle and wrong at the edges. Write (or generate, then read) tests for: empty input, single element, exact boundary values, unicode/None/zero, and the largest realistic input. For example, for a generated pagination helper:
def test_last_page_partial():
assert paginate(items=list(range(25)), page=3, size=10) == list(range(20, 25))
def test_page_past_end_returns_empty():
assert paginate(items=list(range(25)), page=9, size=10) == []
def test_empty_items():
assert paginate(items=[], page=1, size=10) == []
Off-by-one at the last partial page is the single most common seeded defect in AI pagination/chunking/windowing code.
Equivalence check for "behavior-preserving" refactors. Never accept the claim on inspection alone. In a fresh session (so the model cannot defend its own work), run:
Here is a before/after diff of a refactor claimed to be behavior-preserving.
List every input for which the two versions could differ: exceptions raised,
ordering, mutation of arguments, laziness/eagerness, floating-point, locale,
timezone, and concurrency behavior. Output a table: input scenario | before |
after | same or different. Do not assess style.
Then pin the suspicious rows with tests, or use snapshot/approval tests over recorded production-like inputs when the surface is wide.
Decide: repair or regenerate. Apply the two-strike rule:
expire_at_ms, which does not exist in redis-py. Use only methods from redis-py 5.x Redis class."Record the failure mode. Add one line to your team's assistant instructions file (CLAUDE.md, .github/copilot-instructions.md) so the same class of defect is caught earlier next time, e.g. "Always paginate with explicit min(end, len(items)) bounds; never assume full pages."
Repair is for localized defects you fully understand; everything else is regenerate-with-a-better-prompt. The expensive failure mode is a long repair session on code built on the wrong approach.
/explain on the diff first, then paste the equivalence-check prompt; jump-to-definition catches hallucinated APIs instantly in-IDE.run the new tests and show failures), then use a fresh session for the adversarial equivalence pass so it is not grading its own homework.assertAlmostEqual, broad pytest.raises(Exception)). Read every generated assertion.