ChatGPTDebuggingLevel 2: Context

How Do You Give ChatGPT a Bug It Can Actually Fix?

Cut the problem down to the smallest code that still fails, then give ChatGPT that code, the exact input, the output you expected and the output you got. The best version is a single failing test, because you can then prove the fix worked by running it.

Prompt to copy
Here's a minimal reproduction of a bug. Everything unrelated has been removed.

```[language]
[paste the smallest code that still fails]
```

Run it with: [exact command]
Input: [exact input]
Expected: [exact expected output]
Actual: [exact actual output or error]
Versions: [language, key libraries]
Things I've ruled out: [anything you've tried]

Explain why this happens in the code above, and point to the specific line. Give the smallest fix. Then give me a test that fails before the fix and passes after it.
  1. The whole fileIt guesses which part matters
  2. The failing functionLess to suspect
  3. The smallest code that failsWith input, expected and actual output
  4. One failing testRun it to prove the fix
A rule of thumb, not an OpenAI figure. The smallest failing example leaves little room for a wrong guess.

Try it now

  1. 1Copy the failing code into a scratch file. Delete one piece at a time, and re-run after each delete. If the bug disappears, put that piece back.
  2. 2Stop when nothing more can go, then fill in the prompt above and send it in New chat.
  3. 3Run the test it gives you on the old code, then on the fixed code. It worked if it fails first and passes second.

Use it when

When a first paste got you a wrong fix, the file is long, or the bug depends on specific data. It's also worth doing before you ask anyone for help, whether that's ChatGPT or a teammate.

Skip it when

Bugs that only appear when systems interact, such as race conditions or a config mismatch across services, may vanish once you cut them down. Use Codex there instead, and let it read the repo and try to reproduce the bug in place. Don't spend an hour reducing a bug that Codex could trace in a few minutes.

Why it works

Each line you remove is one less thing for ChatGPT to suspect. It also saves room. OpenAI's pricing page lists the GPT Instant input maximum at about 12 pages of text on Free and about 40 on Go and Plus, and its Codex pricing tips begin with controlling the size of your prompts.

A reproduction also gives you a way to check the answer. OpenAI's Prompting guide says to re-run reproduction steps after a fix. Its tested pull request use case shows why: the sample has a seeded run that's expected to fail and a corrected run that should pass, and the reproduce command succeeds only if both things happen. A failure you can trigger on demand is what separates a real fix from one that only looks right.

And often, you'll spot the bug yourself as you cut the code down.

Example

Your 400-line report generator gives the wrong monthly total. After cutting it down, you have five lines: two rows of sample data and a groupby that drops a row with a null date. Expected total: 300. Actual: 200. With those five lines, ChatGPT no longer needs to think about your PDF export or database layer, and you can check its explanation in seconds.

Going further

In Codex, you can ask it to do the reducing. Set it to read-only first with codex --sandbox read-only --ask-for-approval on-request, then ask: "Find the smallest steps that reproduce this bug, and write them down. Don't change any code." Once you trust the steps, switch back and ask for the fix. To see exactly what context Codex is sending to the model, OpenAI's commands page lists codex debug prompt-input, which prints the model-visible prompt input as JSON. That helps when you suspect it's working from something other than what you think.

Common mistakes

  • Reducing so far that the bug is gone, then asking about code that works. Re-run after each delete.
  • Describing expected output as "correct" or "the right number". Give the actual value.
  • Replacing real input with neat samples. If the bug needs a null or an odd character, keep it.
  • Stopping after the fix without a test, so the same bug can come back unnoticed.

Sources

Checked 6 November 2026. Products change often, so confirm details with the vendor.

Related

Beyond the course