Ask AI for Debugging Help the Right Way
AI assistants like ChatGPT, Claude, and Gemini are very good at spotting bugs, explaining errors, and suggesting fixes. But the quality of their help depends almost entirely on what you give them. "My code doesn't work, fix it" with 300 pasted lines gets a guess. A clear, focused question gets a real answer.
This lesson gives you a simple template for debugging questions, a way to use AI that helps you learn instead of just copying fixes, and the safety rules to follow when pasting code.
What You'll Learn
- The five things to include in every debugging question
- A copy-and-paste debugging prompt template
- Why asking for an explanation first beats asking for a fix
- How to handle a fix that does not work
- What never to paste into an AI chat
The five things AI needs
Remember the note from the previous lesson? That is most of a good debugging question. Include:
- The goal: what the code is supposed to do, in one sentence.
- The code: your minimal example, not your whole project.
- The exact error: the full error message, copied, not paraphrased. Or, if there is no error, the expected vs actual output.
- The input: the data that triggers the bug.
- What you already tried: so it does not suggest the same thing again.
Also mention the language and version if it matters, and any library you are using.
The strong question often gets the right answer on the first try.
| Criteria | Weak question | Strong question |
|---|---|---|
| Goal | Missing | "Count words starting with a vowel" |
| Code | The whole 300-line file | The 6 lines that show the bug |
| Error or result | "It doesn't work" | "Expected 3, got 1" |
| Input | Missing | The exact list used |
| Already tried | Missing | "Checked the loop runs 5 times" |
Weak question
- Goal
- Missing
- Code
- The whole 300-line file
- Error or result
- "It doesn't work"
- Input
- Missing
- Already tried
- Missing
Strong question
- Goal
- "Count words starting with a vowel"
- Code
- The 6 lines that show the bug
- Error or result
- "Expected 3, got 1"
- Input
- The exact list used
- Already tried
- "Checked the loop runs 5 times"
The debugging prompt template
Copy this and fill it in:
I'm learning [language]. My code should [goal in one sentence].
Here is a minimal example that shows the problem:
[paste code]
When I run it with this input: [input]
I expected: [expected result]
But I got: [actual result or the full error message]
I already tried: [what you tried]
Please first explain what is causing the problem in simple terms.
Then show the smallest change that fixes it, and explain why it works.
The last two lines are the most important part of the template. Here is why.
Ask for the cause before the fix
If you only ask for a fix, you get new code to paste. It might work. It might fix the symptom while hiding the real problem. Either way, you learn nothing, and next time you are stuck again.
Asking for the cause first changes everything:
- You can check whether the explanation matches the error you saw.
- You learn the pattern, so you recognize it next time.
- The AI tends to reason more carefully when it has to explain before fixing.
Asking for the smallest change matters too. AI assistants often rewrite large parts of your code, changing names, style, and structure. That makes it hard to see what actually fixed the bug, and it can introduce new problems. One small, explained change is easy to understand and easy to check.
- AskGoal, minimal code, error, input, what you tried
- UnderstandRead the explanation. Does it match the error?
- Apply one changeOnly the smallest fix
- TestRun it with the original input and more
When the fix does not work
It happens often, and it is normal. Do not just say "still broken." Give the AI the new information:
I applied your change. Now I get this new error: [paste it]. Here is the updated code: [paste it].
If you go around several times without progress:
- Ask for possible causes, not a fix: "List three different things that could cause this, and how I could check each one." This stops the AI from repeating the same idea.
- Start a fresh chat with a clean summary of the problem. Long debugging chats fill up with failed attempts, and the AI can get stuck on its earlier wrong ideas.
- Check your assumptions: Are you running the file you think you are? Did you save it? Is the input really what you think it is?
What never to paste
Code often contains things that should not leave your computer. Before pasting, remove or replace:
- Passwords, API keys, and tokens. Replace them with
YOUR_KEY_HERE. A leaked key can be used by others and can cost real money. - Personal data: real names, emails, addresses, or customer records used as test data. Use made-up examples instead.
- Code you are not allowed to share: your employer's or a client's private code may be covered by an agreement. Check the rules first.
Shrinking to a minimal example helps here too: a small, made-up example rarely contains anything sensitive.
Key Takeaways
- Every debugging question needs the goal, minimal code, exact error or expected vs actual, the input, and what you tried.
- Use the template so you never forget a piece.
- Ask for the cause first, then the smallest fix, with an explanation. You learn more and catch bad fixes.
- When a fix fails, give the new error, ask for several possible causes, or start a fresh chat.
- Never paste keys, passwords, personal data, or code you are not allowed to share.

