Prompts That Work

The "write the failing test first" debugging prompt

Make the model reproduce the bug before it touches the fix. Kills the confident patch that solves a problem you don't have.

Use case
Debugging
Works with
Claude, GPT-class, local Qwen3 14B+
▶ The prompt
There is a bug: {describe the wrong behavior, with the exact error message
or the exact wrong output}.

Here is the relevant code:
{code}

Do not fix anything yet.

First, write the smallest test that reproduces the bug. It must fail
against the current code for the same reason the bug happens, not for a
setup or import reason. Tell me exactly how to run it.

After I confirm it fails the way you expect, propose the fix. The fix is
done when that test passes and the existing tests still pass. Do not
refactor anything the fix does not require.

The classic AI debugging failure: you describe a bug, the model says “I see the issue!” with total confidence, and hands you a patch for a different bug than the one you have. You apply it, nothing changes, and now you are debugging two things.

This prompt borrows the oldest rule in the book: reproduce first. If the model cannot write a test that fails the way your bug fails, it does not understand the bug, and you just found that out for the price of one test instead of one broken patch.

Why it works

  • The reproduction is a comprehension check you can run. A model’s explanation of a bug can sound right and be wrong. A failing test is either failing for your reason or it is not. No vibes involved.
  • “Not for a setup or import reason” matters more than it looks. The lazy failure mode is a test that errors before it ever reaches the buggy path, which proves nothing and feels like progress.
  • The done condition is stated up front. “Test passes, existing tests still pass, no drive-by refactor” gives the model a finish line, and models with finish lines wander less.

What good output looks like

A test short enough to read in one glance, a one-line command to run it, and a prediction: “this should fail with a KeyError on line 4.” When the prediction matches what you see, the fix that follows is nearly always right. When it does not match, you have saved yourself the afternoon.

Where it works (and doesn’t)

Great on Claude and GPT-class models. Local 14B models can do it on self-contained code but struggle when reproducing needs mocks or fixtures; give them the smallest slice of code you can. And it obviously assumes the bug is reproducible in a test at all. For the heisenbug that only shows up in production on Tuesdays, no prompt is saving you.

As a bonus, the regression test is not scaffolding. It goes in the suite, and this bug never ships twice.