Code Review AI Prompt: Catch Bugs Before Production

🚀 Code Review AI Prompt: Catch Bugs Before Production

Transform your code reviews with this expert-crafted AI prompt. Catch security vulnerabilities, performance issues, and bugs before they hit production.

Code Review Prompt Infographic showing 5 pillars of code review

🎯 The Prompt

You are an expert senior software engineer conducting a thorough code review. Analyze the following code for:

1. Bugs & Logic Errors - Identify potential runtime issues, edge cases, or incorrect assumptions
2. Security Vulnerabilities - Flag injection risks, authentication gaps, data exposure
3. Performance Bottlenecks - Point out inefficient algorithms, memory leaks, or N+1 queries
4. Maintainability - Highlight unclear naming, missing documentation, or code smells
5. Best Practices - Check against SOLID principles, DRY, and language conventions

For each issue found:
- Explain WHY it's a problem (with real impact)
- Provide the SPECIFIC line(s) of code
- Suggest a CONCRETE fix with improved code

If the code is well-written, explicitly state what they did right and why it matters.

Here's the code to review:
[PASTE YOUR CODE HERE]

💡 Real-World Example

Scenario: A junior dev submitted this Python function for processing user uploads:

def save_file(file, user_id):
    filename = file.filename
    file.save(f"/uploads/{user_id}/{filename}")
    return f"/uploads/{user_id}/{filename}"
⚠️ What the prompt catches:

  • Security: No validation = path traversal attack (../../../etc/passwd)
  • Reliability: No directory creation = crash if folder doesn’t exist
  • Safety: No file type restrictions = executable uploads
  • Performance: Synchronous save = blocks request thread

Improved version suggested by the AI:

import os
from pathlib import Path
from werkzeug.utils import secure_filename

ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'pdf'}

def save_file(file, user_id: str) -> str:
    # Sanitize filename
    filename = secure_filename(file.filename)
    if not filename or '.' not in filename:
        raise ValueError("Invalid filename")
    
    # Validate extension
    ext = filename.rsplit('.', 1)[1].lower()
    if ext not in ALLOWED_EXTENSIONS:
        raise ValueError(f"File type .{ext} not allowed")
    
    # Create user directory safely
    user_path = Path(f"/uploads/{secure_filename(user_id)}")
    user_path.mkdir(parents=True, exist_ok=True)
    
    # Save with size check
    file_path = user_path / filename
    file.save(str(file_path))
    
    return str(file_path)
Result: Production-ready code with security, error handling, and type safety.

🔥 Pro Tips for Maximum Results

1. Add Context

Tell the AI your tech stack (“React 18 with TypeScript”) for framework-specific advice

2. Specify Seniority Level

“Review as a staff engineer” vs “Review for a bootcamp student” changes tone/depth

3. Include Test Cases

Paste failing tests to get targeted fixes that solve your specific problem

4. Ask for Trade-offs

Add: “Note the trade-off between time-to-ship and long-term maintainability”

5. Stack-Specific Rules

Append: “Check for React hooks dependencies, Python type hints, Go error handling”

📊 Why This Prompt Works

Element Benefit
🔍 Structured categories Ensures comprehensive coverage of all critical areas
📚 “Why it’s a problem” Educational, builds understanding not just fixes
💻 Concrete fixes Actionable output, not just vague criticism
🌟 Positive reinforcement Recognizes good patterns to repeat

🎯 Perfect For

  • Solo developers who need a second pair of eyes
  • Code reviewers who want to speed up their process
  • Tech leads mentoring junior developers
  • Interview prep — practice explaining code issues
  • Legacy code audits — quickly assess technical debt

💬 Try It Now

Copy the prompt above, paste it into ChatGPT, Claude, or your favorite AI, and drop in some code you’ve been working on. You’ll be amazed at what it catches!

Want more prompts like this?

Join 5,000+ developers getting weekly AI prompts delivered to their inbox.