How Do I Effectively Review AI-Generated Code?

Key Takeaways

  • Shift Focus: Don't review syntax (linters do that); review architectural integrity.
  • Radical Skepticism: Treat AI code with more scrutiny than human code.
  • The Explain Rule: If the author can't explain the logic, the review is a "Request Changes."
  • Smell Detection: Actively look for "Magic Black Boxes" and "Prompt Drift."

Why AI Code Review is Different

Traditional code review is a conversation between two humans who both understand the context. AI code review is often a human reviewing a "Magic Black Box" that another human blindly prompted. This leads to Automation Bias, where bugs are missed because the code "looks clean."

The 5-Step Clean Vibe Review Process

1. Verify Architecture First

Does this implementation follow our team's established patterns? AI often proposes "tutorial patterns" that are too simple or "enterprise patterns" that are over-engineered.

  • Check: Does it respect our module boundaries?
  • Check: Does it use our standard libraries?

2. The Security Stress Test

AI is security-naive. It often skips input validation and uses insecure defaults.

  • Check: Are all user inputs validated?
  • Check: Is there any PII handled without encryption?
  • Check: Are there hardcoded secrets?

3. Detect "Vibe-Code Smells"

Look for the 15 smells identified in Clean Vibe Code (Appendix B). The most dangerous are:

  • Magic Black Box: Logic that works but is unnecessarily complex or opaque.
  • Hidden Dependencies: Implicit coupling to global state or distant modules.

4. Perform "Manual Archaeology"

Ask the developer: "Why did the AI choose this specific algorithm?" If the answer is "I don't know," you have detected Comprehension Debt.

  • Action: Request the developer to refactor for clarity or add thorough documentation.

5. Validate Tests (Circular Testing)

AI often writes both the code and the tests. This creates a feedback loop where tests only validate the AI's own flawed assumptions.

  • Check: Do the tests cover edge cases and negative paths?
  • Check: Were the tests written after the code (risky) or to a spec (better)?

The Statistics

45-46%
of AI code contains vulnerabilities
Source: Source 4
3-5x
longer to review AI code for quality
Source: Research

The "Explain Before Merge" Rule

The most powerful tool in your review arsenal is the Explain Rule: You cannot merge a Pull Request if the author cannot explain the internal logic of every modified file. This ensures the "vibe" is replaced by engineering understanding.

Related Questions

Learn More

Effective review strategies for individuals and teams are detailed in Chapter 14: Clean Agents and Chapter 16: Clean Teams.

Stop rubber-stamping technical debt