AI Prompt to Review Your Code Before You Commit
Copy an AI prompt that reviews a code change for bugs, edge cases, readability and security, and sorts every finding by how serious it is.
Published · 2 min read
A second pair of eyes catches mistakes that the author has stopped seeing. When no teammate is free, an assistant can play that role, as long as you tell it what the change is supposed to do. This prompt asks for findings sorted by seriousness, so a possible data leak is never buried under a comment about variable names.
The prompt
Act as a careful reviewer for a [language or framework] project. Purpose of this change: [one or two sentences on what it should do]. Constraints I care about: [for example no new dependencies, must stay fast, must work on older browsers]. Review the diff or code below. Report your findings in three groups: "Must fix" for bugs, security problems and data loss, "Should fix" for missing edge cases and unclear logic, and "Optional" for style and naming. For each finding give the line or function, why it matters and a short suggested change. If you find no problems in a group, say so instead of inventing some. Finish by listing the tests you would add. Code or diff: [paste it here]
Replace the highlighted brackets with your own details before you send it.
When this prompt helps
Use it just before you commit or open a pull request, when you are working alone on a small project, or when you want a quick check before a human reviewer spends time on your work. It is also a good way to learn: reading why something is risky teaches more than being told to change it.
How to use it
- State the purpose of the change. Without it the assistant can only judge style, not whether the code does its job.
- Paste a reasonably small diff. A review of fifty lines is far more careful than a review of five hundred.
- Start with the "Must fix" group and verify each claim yourself. A review can be wrong, so reproduce a problem before you change code for it.
- Turn the suggested tests into real tests and run them.
A filled-in example
Act as a careful reviewer for a Node.js project. Purpose of this change: let users upload a profile picture and store it on disk. Constraints I care about: no new dependencies.
A thorough reviewer would ask what happens with very large files, files with the wrong type, and file names that contain path characters such as double dots. If the review ignores uploads of unexpected types, ask about that directly.
Tips for better results
- Say who will run the code. Code for a personal script has different risks from code on a public server.
- Ask the assistant to explain any finding you do not understand rather than applying it blindly.
- Never paste real passwords, tokens or customer records into a review request.
- Run your normal linter and tests as well. A review by an assistant adds to them but does not replace them.
Variations to try
- Ask for a review that looks only at security and treats everything else as out of scope.
- Add "assume the next developer is a beginner" to get comments focused on readability.
- Ask for a one-paragraph summary of the change that you can reuse as a pull request description.