Debug Error Detective
Added Apr 1, 2026
About This Prompt
Debugging is often the most frustrating part of development, especially when error messages are cryptic or misleading. This prompt turns the AI into a debugging partner that goes beyond fixing the immediate error to help you understand the root cause and prevent similar issues. The requirement to explain in plain English demystifies complex error messages, while the prevention suggestions help you write more defensive code going forward. The hidden issues check is particularly valuable because production bugs often mask underlying problems that surface later as harder-to-diagnose failures.
Variables to Customize
[LANGUAGE]
Programming language
Example: Python 3.11
[PROJECT_TYPE]
Type of project
Example: FastAPI web application
[ERROR_MESSAGE]
The full error message and stack trace
Example: TypeError: 'NoneType' object is not subscriptable at line 45 in user_service.py
[TRIGGER_CONTEXT]
What you were doing when the error occurred
Example: calling the /api/users/{id} endpoint with a valid user ID that exists in the database
[CODE_SNIPPET]
The relevant code around the error
Example: user = await db.fetch_one(query) return user['email']
[ENVIRONMENT_DETAILS]
Your development environment
Example: Python 3.11, FastAPI 0.104, asyncpg, PostgreSQL 15
Tips for Best Results
- Include the full stack trace, not just the error message line
- Mention any recent changes that might have introduced the bug
- Provide your database schema if the error involves data access
Example Output
## Plain English Explanation
Your code is trying to access the 'email' key on a variable that is None (null). This means `db.fetch_one(query)` returned None instead of a user record.
## Root Cause
The `fetch_one` method returns None when no rows match the query, but your code assumes it always returns a valid row. Even though you say the user ID exists, the query might be using a different column or the connection might be hitting a different database/schema.
## Fix
```python
user = await db.fetch_one(query)
if user is None:
raise HTTPException(status_code=404, detail=f'User {id} not found')
return user['email']
```