AI Prompt to Debug an Error Message
Copy this AI prompt to get ranked likely causes, ways to confirm each one and the smallest fix for an error message in your code.
Published · 2 min read
Most debugging questions fail for the same reason: the person asking leaves out the one detail that explains the problem. An assistant cannot see your screen, so it needs the exact error text, what you expected, what you changed and which versions you use. This prompt collects those details up front and asks for a ranked list of causes instead of one confident guess.
The prompt
I am getting an error in my [language or framework] project and I need help finding the cause. Error message (exact text): [paste the full error and stack trace] What I expected to happen: [expected behaviour] What happens instead: [actual behaviour] What I changed just before it started: [recent change, or "nothing that I know of"] Environment: [operating system, language and library versions] Relevant code: [paste only the part of the code involved] Do not rewrite my whole program. List the three most likely causes, starting with the most probable, tell me how to confirm each one, and then suggest the smallest fix.
Replace the highlighted brackets with your own details before you send it.
When this prompt helps
Use it when a build fails, a page shows a blank screen, a request returns an unexpected status or a program stops with a stack trace you do not understand. It is also a useful discipline when you are stuck: writing out what you expected and what you changed often reveals the cause before the assistant answers.
How to use it
- Copy the error exactly. Retyping it from memory loses the line numbers and file names that matter most.
- Include only the code the error points to, plus anything it calls. Too much code buries the clue.
- Work through the causes in order. Confirm each one with the check the assistant suggests before you change anything.
- If the first fix does not work, reply with the new error message rather than starting a new conversation.
A filled-in example
I am getting an error in my React project. Error message: "Unexpected token } in JSON at position 48". What I expected: the settings file loads. What happens instead: the page stays blank. What I changed: I edited settings.json by hand.
For this case a strong answer would put a trailing comma or a stray bracket first, and suggest checking the file with a validator. You can do that yourself by pasting the file into the JSON Formatter, which points to the place where the structure breaks.
Tips for better results
- Say what you already tried so the assistant does not repeat it.
- Remove secrets, tokens and personal data from logs before you paste them.
- Ask "how can I confirm this?" for every cause. A cause you cannot test is only a theory.
- After the fix works, ask why it failed. Understanding the reason is what stops the same bug returning.
Variations to try
- For a performance problem, replace the error with timing numbers and ask for likely bottlenecks.
- For an intermittent bug, describe how often it happens and ask for ways to log more information.
- Ask for a short test case that would catch the bug in future.