AI prompts that make code reviews better
Share
TL;DR: Use structured prompts for refactors, naming, tests, and risk discovery. Verify diffs quickly and keep humans in the loop.
Principles
- Provide the context and goal in a few clear sentences.
- Ask for small, verifiable diffs.
- Request tests and a summary of risks.
Prompt library
Refactor for clarity
Refactor this function to be more readable without changing behavior.
Return only the new function body and explain risky changes.
Naming pass
Suggest better names for functions and variables that improve intent.
Return a table of old name - new name with reasons.
Test suggestions
Given this function, write three focused unit tests: a happy path, an edge case, and an error case.
Return only the test code.
Verification
- Run tests and linters. Compare output before and after.
- Skim the diff for behavior changes that were not requested.
- Rollback if the diff is too large. Ask for a smaller change.
FAQ
Can AI approve PRs on its own
No. Keep a human reviewer. Use AI to speed up drafting and feedback.
How do I prevent hallucinations
Provide the exact function or file, set constraints on what to change, and verify through tests.
Cast this in your project
- Vibe Coding Bible - Ebook for practical AI workflows.
- Ask Better, Get More - Guide to level up your prompts.
Image credit: Photo by cottonbro studio: https://www.pexels.com/photo/close-up-shot-of-fist-bump-6153344/