"My code does not work, what is wrong?" is the debugging prompt most people send, and it earns the answer it deserves: a generic list of things often wrong with code. Having seen neither your code, your error message nor your setup, the AI guesses at likely problems and leaves you to find which guess is yours.
A debugging prompt is only as good as the evidence inside it. This guide shows how to build one with the free Prompt Builder on Ovatly: six guided fields, assembled into a clean headed prompt for your AI chat tool. It also covers the limit that matters most: the answer can be wrong, so the workflow ends with testing, not copying.
Contents
- Quick answer
- Why vague debugging prompts fail
- The six fields, mapped to a bug
- How to build the prompt, step by step
- Worked example: an assembled debugging prompt
- Limitations and honest expectations
- Common mistakes
- FAQs
- Conclusion
Quick answer
Build the prompt in the Prompt Builder like this: task states the job ("Find why this function throws an error when the list is empty"); context carries the evidence (failing code, the complete error message copied exactly, what you expected instead); role names the expertise ("an experienced Python developer"); output format asks for cause first, then corrected code, then a short explanation; constraints, one per line, set the limits ("Do not rewrite unrelated code", "Explain every change you make"). Copy the assembled prompt into your chat tool, then test the suggested fix before trusting it.
Why vague debugging prompts fail
Debugging is diagnosis, and diagnosis runs on evidence. An error message names a line and a type; the code shows what executes; your expectation shows where reality and intent diverged. Remove any one of the three and the answer degrades. Without the error text, the AI hunts through every failure mode. Without the code, it comments on a program it invented. Without your expectation, it cannot tell a bug from a behaviour you dislike.
Structure is the other half: in a wall of pasted text, the error message sits buried and the request is easy to miss. Headed sections fix that: the builder arranges the fields in a fixed order (Role, Task, Context, Tone, Output format, Constraints) and skips empty sections, so evidence lands in a labelled place and the request stands out.
The six fields, mapped to a bug
- Role sets the expertise. "You are an experienced JavaScript developer who knows React" tells the model which language and framework to reason in, instead of fixes for the wrong stack.
- Task is the job, stated narrowly. "Find the cause of this error" and "Rewrite this to be faster" are different jobs; the prompt wants the first, symptom named.
- Context is the evidence locker, and for debugging the key field. It holds the failing code, the exact error message, the triggering input, and what you expected to happen. Paste the error message from your terminal, not paraphrased: its wording and line numbers are clues a summary throws away.
- Tone is usually "direct and technical" for code help. It discourages filler and keeps answers technical.
- Output format controls the answer's shape. Asking for "cause first, then corrected code, then a brief explanation" prevents a full rewritten file arriving with no indication of what was wrong.
- Constraints are the guardrails, one per line so each becomes a bullet: "Change as little code as possible", "If the cause is not in this code, say what else you need". The last one matters: it lets the AI ask for evidence instead of inventing an answer.
How to build the prompt, step by step
- Open the Prompt Builder and, following the tool's own order, fill in the task first: what you want the AI to do with this bug.
- Fill the context field with the evidence: the smallest code that shows the failure, the complete error message copied exactly, the triggering input, and the behaviour you expected.
- Add the role (language and framework expertise), set tone to direct and technical, and set the output format (cause, corrected code, explanation).
- List constraints one per line, including an instruction to say so if evidence is insufficient.
- Copy the assembled prompt into your chat tool and send it. When the answer arrives, apply it somewhere safe, run the code and tests, and confirm the error is gone.
Worked example: an assembled debugging prompt
Suppose a small script fails on an empty list. The fields: role "You are an experienced Python developer"; task "Find why this function throws an error when the list is empty"; context holding the function, the exact error line IndexError: list index out of range, and the expectation that an empty list returns zero; tone "Direct and technical"; output format "Likely cause first, then the corrected function, then a short explanation"; constraints "Change as little code as possible" and "Explain every change".
The builder assembles those fields in its fixed order, in the same headed shape as its own documented example output:
## Role
You are an experienced Python developer
## Task
Find why this function throws an error when the list is empty
## Context
[the failing function pasted here]
Error: IndexError: list index out of range
Expected: an empty list returns zero
## Tone
Direct and technical
## Output format
Likely cause first, then the corrected function, then a short explanation
## Constraints
- Change as little code as possible
- Explain every change
Note what the builder did and did not do. It arranged your words under headings and turned your two constraint lines into bullets. It did not read your code, spot the bug or improve your phrasing; it does not reword your text at all. The diagnosis happens later, in the chat tool, and depends on the evidence in your context field.
Limitations and honest expectations
The hard limit comes first: AI code help can be wrong. A suggested fix can be fluent and incorrect, and it can fix the error while breaking a case you did not mention. Treat every suggestion as a hypothesis: run it, test the original failing input and a few neighbouring ones, and read the diff before it goes near production code.
The builder's limits matter too. It is template assembly, not AI writing: nothing is sent to a model or generated, and it will not polish a muddled task into a clear one. If your context holds the wrong version of the function, the assembled prompt is beautifully structured and wrong. Respect your own boundaries when pasting code into any chat tool: leave out passwords, keys and private data.
Finally, some bugs are not prompt-shaped: intermittent failures may need logs and a debugger, not a better question.
Common mistakes
- Paraphrasing the error message. "It says something about an index" discards the exact clue. Copy the message exactly, including line numbers.
- Pasting the whole project. A thousand lines bury the failure. Reduce to the smallest code that still shows the bug.
- Asking for a rewrite instead of a diagnosis. "Make this better" returns different code, bug possibly intact. Ask for the cause first.
- No constraints. Without "change as little as possible", expect a full rewrite you cannot compare with your original.
- Copying the fix without running it. The prompt starts the debugging; it does not end it. An untested AI fix is an untested fix.
FAQs
Does the Prompt Builder look at my code or fix it? No. The builder is a template: it arranges your own words into headed sections. Your code goes into the context field as pasted text; the assembled prompt goes into your chat tool, and the AI there answers.
Where do the error message and the code go? In the context field. Paste the failing code and the complete, exact error message, copied rather than retyped or summarised. Add what you expected, and what happened instead.
Can I trust the fix the AI suggests? Not without testing it. AI code help can be wrong, and a wrong fix can sound as confident as a right one. Apply the change in a copy or branch, run the code, and check the original error is gone and nothing else broke.
Which fields matter most for a debugging prompt? Task and context. A prompt with only a task and no context usually performs worse, and debugging is the extreme case: without the code and the error text, nothing can be debugged. Role, tone and format sharpen it further.
Can I reuse a debugging prompt? Yes. Save the assembled prompt; next time, swap task and context for the new bug. The Prompt Variable Filler tool is even better here, since only the code and error change.
Conclusion
Good debugging help is earned with evidence: the code, the exact error, your expectation, and constraints that keep the answer surgical. The Prompt Builder gives that structure for free, provided you remember it only arranges your words, and the fix you get back still has to survive being run. For bigger jobs, the companion guide on how to chain prompts makes diagnosis one checked step in a longer sequence. More guides like these live in the AI and Prompt Tools guides.