Debugging
Paste the exact error, cut the bug down to the smallest failing code, ask for causes before fixes, and reset after two failed attempts.
-
How Do You Stop ChatGPT From Guessing at Bug Fixes? Tell it not to fix anything yet. Level 2: Context
- 1The symptom
- 2Likely causes
- 3A check that tells them apart
- 4Then the fix
-
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. Level 2: Context
- The whole fileIt guesses which part matters
- The failing functionLess to suspect
- The smallest code that failsWith input, expected and actual output
- One failing testRun it to prove the fix
-
What Should You Paste Into ChatGPT to Fix an Error? Paste the exact error text, the full stack trace, the command you ran, and the code at the failing line. Level 2: ContextDo
- The exact error and full trace
- The command you ran
- The code at the failing line
- Take out any secrets first
Don't- "It doesn't work"
- Your guess at the cause
- A screenshot with no explanation
-
What Do You Do When ChatGPT Keeps Giving the Same Wrong Fix? Stop after two failed attempts. Level 2: Context
- 1A fix fails
- 2Another variation fails
- 3Stop and write a handoff
- 4New chat, with what failed
Stuck again? Hand off again
Debugging works best as a sequence
These four cards follow the order of a real bug. First, give the evidence: the exact error and the command you ran. If that's not enough, cut it down to a small reproduction. Then ask for causes and a way to test them before you accept any change. And if it starts going in circles, stop and start again with a clean handoff. Most failed debugging sessions skip straight to asking for the fix, which gets you code that looks plausible but hasn't been checked.
Chat and Codex debug differently
In Chat, the text you paste is all ChatGPT has, so what you leave out it has to guess. Codex can run things itself. OpenAI's bug-fix example asks it to reproduce the bug locally, propose a patch and run checks. That gives you a much stronger result, as long as you read the output. Remember that a new chat clears the conversation but not your files, so undo failed edits before you start again.
How do I debug code with ChatGPT?
Paste the exact error and full stack trace, the command you ran, the failing code, and what you expected. Replace any secrets first. Ask for the cause before the fix, and re-run your reproduction steps after the fix to confirm that it worked.
Why does ChatGPT suggest fixes that don't work?
In Chat, it can't run your project, so it may be reasoning from an incomplete picture. It also tends to build on earlier attempts in the same thread. Give it the missing evidence, or use Codex, which can reproduce the bug and run checks.
What do I do if ChatGPT keeps repeating the same wrong answer?
Stop after two failed attempts. Ask for a handoff listing the confirmed facts and each fix that failed, undo the failed edits, and paste the handoff into a new chat. Tell it not to suggest those fixes again.
Can I send ChatGPT a screenshot of an error?
Yes. On the web, attach, paste or drag the image into the composer. In Codex, use codex -i screenshot.png with your prompt. OpenAI says not to rely on the image alone, so say what to look at. If you can copy the text, send that too.