Debug an Error Message With Full Context
Give the AI the error, the code, and what you've tried so it can diagnose the likely root cause instead of guessing.
Make it yours
Fill in each variable and watch the prompt update. Anything still in {{braces}} needs your input before you use it.
Fill in the blanks
0 of 7 filledLanguage or framework.
Versions, runtime, OS, or tools that might matter.
What should happen.
What happens instead.
Fixes you've already tried.
The full error text or stack trace.
The smallest code snippet that shows the problem.
You are a senior {{language}} developer helping me debug. Environment: {{environment}} What I expected: {{expected_behavior}} What actually happens: {{actual_behavior}} What I've already tried: {{attempts}} Error message / stack trace: """ {{error_message}} """ Relevant code: """ {{code}} """ Please: 1. Explain in plain words what the error means. 2. List the 2–3 most likely root causes, ranked by likelihood, and the evidence for each. 3. For the top cause, give a minimal fix and show only the changed lines. 4. Suggest one quick check (a print, log, or command) to confirm the diagnosis before I change anything. If the information I gave isn't enough to be confident, tell me exactly what else you need rather than guessing.
Example
Example input
You are a senior JavaScript (React) developer helping me debug.
Environment: React 18 app built with Vite, running in Chrome
What I expected: The page shows a list of user names fetched from our API.
What actually happens: The page is blank on first load and the console shows an error.
What I've already tried: Confirmed the API endpoint returns a JSON array of users when called directly.
Error message / stack trace:
"""
TypeError: Cannot read properties of undefined (reading 'map')
at UserList (UserList.jsx:12:20)
"""
Relevant code:
"""
function UserList() {
const [users, setUsers] = useState();
useEffect(() => {
fetch("/api/users").then((r) => r.json()).then(setUsers);
}, []);
return <ul>{users.map((u) => <li key={u.id}>{u.name}</li>)}</ul>;
}
"""
Please:
1. Explain in plain words what the error means.
2. List the 2–3 most likely root causes, ranked by likelihood, and the evidence for each.
3. For the top cause, give a minimal fix and show only the changed lines.
4. Suggest one quick check (a print, log, or command) to confirm the diagnosis before I change anything.
If the information I gave isn't enough to be confident, tell me exactly what else you need rather than guessing.Example output
What the error means: On line 12 the code calls .map on users, but at that moment users is undefined, and undefined has no .map method.
Likely root causes:
- Initial state is undefined (most likely).
useState()starts asundefined. The component renders once before the fetch finishes, so the first render crashes. This matches "blank on first load." - API response shape differs. If the API returns
{ users: [...] }instead of an array,users.mapwould fail after loading. Less likely, since you confirmed it returns an array. - Fetch error. A failed request isn't caught, but it wouldn't produce this specific error on its own.
Fix for cause 1:
const [users, setUsers] = useState([]);
Starting with an empty array means the first render shows an empty list, then fills in when data arrives.
Quick check first: Add console.log("users:", users); just before the return. If the first log shows undefined, cause 1 is confirmed.
Why it works
Most "fix my error" prompts fail because the model only sees the error. This template supplies expected vs. actual behavior, environment, and what you've already tried, which rules out dead ends and points toward the real cause.
Asking for ranked causes with evidence encourages the model to reason about the problem rather than jump to the first fix, and the "quick check" step lets you verify the diagnosis yourself — important because AI suggestions can be plausible but wrong.
Techniques used
- Contextual promptingGive the AI the background it can't guess — who you are, your goal, your audience, your constraints — so answers fit your real situation.Learn the technique
- Instruction promptingWrite clear, explicit, positive instructions — action, scope, constraints, format — so the AI knows exactly what done looks like.Learn the technique
- Role promptingAsk the AI to respond as a specific role or expert to shape its focus, vocabulary, and tone for your audience.Learn the technique