Join WhatsApp
Sample output Ā· AI-generated

1. Root cause
Line 2 reads order["coupon"] directly. Orders created without a coupon do not have that key at all, so Python raises KeyError: 'coupon' instead of treating it as empty.

2. Fix
```python
def get_discount(order):
coupon = order.get("coupon")
if not coupon:
return 0
return COUPONS.get(coupon, 0)
```

3. Why it works
dict.get returns None when the key is missing, so orders without a coupon get a discount of 0. Using COUPONS.get also handles unknown coupon codes instead of crashing.

4. Test
```python
def test_order_without_coupon_has_no_discount():
assert get_discount({"id": 7, "total": 40}) == 0
```

5. Watch for
Line 9 reads order["customer"]["email"] the same way. Guest checkouts may not have a customer object.

Text prompt Ā· ChatGPT Ā· Claude Ā· Gemini

Debug code prompt that finds the root cause before fixing

Paste your code and the error message to get the real cause explained first, then a small fix and a test for it.

You are a senior [language] developer helping me debug.

What the code should do: [expected behaviour]
What happens instead: [actual behaviour]
Full error message and stack trace:
[paste error]
Environment: [language version, framework, operating system]
What I already tried: [list]

Code:
```
[paste the smallest code that shows the problem]
```

Answer in this order:
1. Root cause: explain in 2 to 4 sentences why the bug happens. Point to the exact line.
2. Fix: the smallest change that solves it, as a code block. Do not rewrite unrelated code.
3. Why the fix works.
4. A test case that would have caught this bug.
5. Anything else in the code that may cause a similar problem.

If you are not sure about the cause, list the 2 most likely causes and what I should check to tell them apart.
Type
Text
Fill in
7 blanks
Copies
Be the first

Updated Ā· By

Tip: Before pasting, try to reproduce the bug with the fewest lines possible; often you find the cause yourself while doing it.

1. CopyTap "Copy prompt" above.
2. Fill the blanksReplace each [bracket] with your own details.
3. Paste + refinePaste it into the chat, then ask for changes.

Why this prompt works

This debug code prompt asks for the root cause before the fix, which stops the AI from guessing and wrapping your code in try-except blocks that hide the real problem. Giving the expected and actual behaviour, the full stack trace and what you already tried narrows the search a lot.

"The smallest change" keeps the fix easy to review, and the test case makes sure the same bug cannot quietly return. The last line, asking for two likely causes when unsure, gives you a way forward instead of a confident wrong answer.

How to use this prompt

  1. Tap "Copy prompt".
  2. Replace every part in [square brackets] with your own details.
  3. Paste it into ChatGPT or Claude and send.
  4. Ask a follow-up like "make it shorter" or "give me 3 more options" to fine-tune it.

Variations to try

Debug a failing test

ChatGPT Claude Gemini
This [language] test fails and I do not know if the bug is in the test or the code. Test: [paste test]. Code under test: [paste code]. Failure output: [paste output]. Tell me which one is wrong, why, and the smallest fix.
Type
Text
Fill in
4 blanks
Copies
Be the first

Debug a slow or hanging program

ChatGPT Claude Gemini
My [language] program sometimes hangs at [step]. Here is the code: [paste]. Logs before it hangs: [paste logs]. List possible causes such as deadlocks, infinite loops or blocking network calls, and give me logging or debugging steps to confirm which one it is.
Type
Text
Fill in
4 blanks
Copies
Be the first

Explain a confusing error message

ChatGPT Claude Gemini
Explain this error in plain English for a beginner: [paste error]. Say what usually causes it in [language or framework], how to find the line that triggers it, and give one small example that reproduces it.
Type
Text
Fill in
2 blanks
Copies
Be the first

Make it your own

  • Replace "senior [language] developer" with your stack, for example "senior Django developer".
  • Add "Explain like I am new to programming" if you are learning.
  • Paste related files (models, config) when the error points outside the code you shared.

Common problems and fixes

  • The AI rewrites the whole file. Keep "smallest change" and "do not rewrite unrelated code" in the prompt.
  • The fix works on your machine but not in production. Add the production environment details, versions and any config differences.
  • You paste secrets with the code. Replace API keys, passwords and tokens with placeholders before pasting.

FAQ

Should I paste my whole project?

No. Paste the smallest piece of code that shows the bug, plus the error. Large pastes make answers less focused.

What if the AI's fix does not work?

Paste the new error and say "this did not work, here is what happened". Ask it to list other possible causes.

More Coding prompts

See all
ChatGPT Claude Text prompt

Explain code prompt for beginners, line by line

Paste any snippet and get a plain-English summary, a line-by-line walkthrough and the concepts you need to understand it.

4 prompts
ChatGPT Claude Text prompt

Unit test prompt for edge cases in pytest or Jest

Get a list of test cases for a function, then ready-to-run tests for normal input, edge cases and errors in your framework.

3 prompts
ChatGPT Claude Text prompt

Refactor code prompt for cleaner, more readable functions

Clean up a messy function while keeping its behaviour the same, with a short list of every change and the reason for it.

4 prompts
ChatGPT Claude Text prompt

SQL query prompt: describe your tables, get the query

Describe your tables and the question you want answered, and get a correct query for your database with a short explanation.

4 prompts
ChatGPT Claude Text prompt

Regex prompt that writes and explains a pattern with tests

Describe what you want to match and get a working pattern for your language, explained piece by piece, with examples that should and should not match.

4 prompts
ChatGPT Claude Text prompt

Code review prompt for bugs, security and readability

A structured review of a pull request or snippet, with issues sorted by severity, each tied to a line and a suggested fix.

3 prompts
ChatGPT Claude Text prompt

API design prompt for clean REST endpoints and errors

Plan a REST API for a feature: endpoints, example requests and responses, status codes, error format and the decisions behind them.

4 prompts
ChatGPT Claude Text prompt

Vibe coding prompt: write an app spec before you build

Turn an app idea into a clear spec with features, screens, data and build steps that an AI coding assistant can follow one step at a time.

4 prompts