Debugging Assistant Prompt (Gemini)
Most debugging sessions fail not because the fix is hard to find but because the problem is poorly defined. This prompt forces you to structure the bug report before asking the AI, which dramatically improves the quality of the response. The five-section output format (root cause, mechanism, fix, verification, prevention) ensures you get a complete answer rather than just a code snippet. This variant is formatted for Gemini: Optimised for Gemini 1.5 Pro and Gemini Ultra. Uses Google AI markdown formatting conventions.
# Gemini AI Prompt
You are a helpful AI assistant powered by Google Gemini.
## Instructions
You are an expert debugging assistant. Analyse the following bug report and provide a root cause analysis.
Language/Framework: {{language_and_framework}}
Error message:
{{error_message}}
Steps to reproduce:
{{steps_to_reproduce}}
Relevant code:
```{{language}}
{{code}}
```
Environment details: {{environment}}
Please provide:
1. **Root cause** — the precise reason the error occurs, not just a description of the symptom
2. **Why this happens** — the mechanism that triggers the bug
3. **Fix** — the minimal code change required, with a diff
4. **Verification** — how to confirm the fix worked (test case or manual check)
5. **Prevention** — how to avoid this class of bug in the future
## Output Format
Provide a well-structured response using Markdown headers and code blocks where appropriate.Variables
{{language_and_framework}}e.g., Node.js 20 with Express 4.18{{error_message}}Full error message including stack trace{{steps_to_reproduce}}Numbered list of steps that reliably trigger the bug{{code}}The relevant code section around the error{{language}}Language for syntax highlighting (e.g., javascript, python){{environment}}OS, runtime version, relevant env vars (e.g., Node 20, macOS 14)Example
language_and_framework: Node.js 20 with Express 4.18
error_message: TypeError: Cannot read properties of undefined (reading 'id') at /app/routes/users.js:12
steps_to_reproduce: 1. Send GET /users/999 where user 999 does not exist
code:
router.get('/:id', async (req, res) => {
const user = await db.findUser(req.params.id);
res.json({ id: user.id, name: user.name });
});
environment: Node 20, PostgreSQL 15**Root Cause:** db.findUser() returns undefined when no record is found, and the code unconditionally accesses user.id without checking for null/undefined first.
**Why this happens:** PostgreSQL returns zero rows for a non-existent ID. The ORM returns undefined instead of throwing, so the error is deferred to the property access on the next line.
**Fix:**
```diff
- const user = await db.findUser(req.params.id);
- res.json({ id: user.id, name: user.name });
+ const user = await db.findUser(req.params.id);
+ if (!user) return res.status(404).json({ error: 'User not found' });
+ res.json({ id: user.id, name: user.name });
```
**Verification:** Send GET /users/999 — should now return HTTP 404 with `{"error":"User not found"}`.Related Tools
FAQ
- What if the error message is not helpful?
- Include the full stack trace even if it looks cryptic. The AI can often identify the root cause from the call stack alone. Also add console.log statements before the failing line and include their output.
- Can I debug performance issues with this prompt?
- Yes. Replace the error_message field with "Performance: operation takes 8 seconds, expected < 200ms" and include profiling output or a slow query log in the relevant code field.
- Should I redact sensitive data from the code before sharing?
- Yes. Replace real credentials, API keys, and personal data with placeholder values like YOUR_API_KEY and [email protected] before pasting into any AI tool.
Related Prompts
Most debugging sessions fail not because the fix is hard to find but because the problem i...
Debugging Assistant Prompt (ChatGPT)Most debugging sessions fail not because the fix is hard to find but because the problem i...
Debugging Assistant Prompt (Claude)Most debugging sessions fail not because the fix is hard to find but because the problem i...
Debugging Assistant Prompt (LLaMA / Ollama)Most debugging sessions fail not because the fix is hard to find but because the problem i...
Code Review PromptThis prompt structures code reviews into five clear categories so the AI produces actionab...
Unit Test Generation PromptAI-generated tests are most valuable when they catch edge cases that developers miss. This...