AI Code Review Prompts for Pull Requests
Pull request review is one of the highest-leverage habits on any engineering team, and one of the easiest to do badly. Reviewers get tired, diffs get large, and the same classes of bugs slip through week after week. Well-written AI code review prompts can act as a tireless first pass: they catch the boring, mechanical problems before a human ever opens the diff, so your teammates can spend their attention on design and intent.
The catch is that most people prompt badly. Pasting a diff and typing "review this code" gets you a wall of polite, generic advice. This guide shows how to structure AI code review prompts so the feedback is specific, ranked, and actually worth acting on.
Why "review this code" fails
A vague prompt produces vague output. The model has no idea what your team cares about, so it hedges: rename this variable, add a comment, consider using a constant. You end up with fifteen nitpicks and none of the one bug that matters.
There are three root causes:
- No context. The model doesn't know the framework, the conventions, or what the change is supposed to accomplish.
- No priorities. Without a severity scale, a missing semicolon and a SQL injection look equally important.
- No output contract. Free-form prose is hard to skim, hard to paste into a PR comment, and impossible to automate around.
The anatomy of a good AI code review prompt
Every reliable review prompt contains the same five parts:
- Role and stack. "You are a senior Laravel engineer reviewing a pull request" anchors vocabulary and best practices.
- Intent. One or two sentences from the PR description. A reviewer who knows what the change is for can spot when it doesn't do that.
- Scope. Tell the model to comment only on lines changed in the diff, and to ignore style issues a linter already covers.
- A checklist. The specific categories you want checked: correctness, security, performance, error handling, tests.
- A strict output format. For example: severity, file and line, problem, suggested fix, one item per finding, and an explicit "no issues found" when the diff is clean.
That last part matters more than it seems. Asking the model to say nothing when there is nothing to say removes the pressure to invent problems.
Five AI code review prompts you can copy
1. Correctness and edge cases
You are a senior backend engineer reviewing a pull request.
Intent of the change: {{pr_description}}
Review ONLY the changed lines in the diff below. Find bugs,
unhandled edge cases (null, empty, huge input, concurrent calls),
and places where the code does not match the stated intent.
For each finding output: severity (high/medium/low), file:line,
the problem, and a concrete fix. If you find nothing, reply
"No issues found." Do not comment on formatting.
{{diff}}
2. Security review
Act as an application security reviewer. Examine this diff for:
injection (SQL, command, template), broken authorization checks,
missing input validation, secrets in code, unsafe deserialization,
and insecure defaults. Assume all request input is hostile.
Report only exploitable or plausibly exploitable issues, with a
one-line attack scenario for each.
{{diff}}
3. Performance and database access
Review this diff for performance problems: N+1 queries, queries
inside loops, missing indexes implied by new WHERE or ORDER BY
clauses, unbounded result sets, and blocking calls in request
paths. For each, estimate when it will hurt (row count or traffic)
and suggest a fix.
{{diff}}
4. Test coverage gaps
List the behaviors introduced or changed by this diff. For each,
say whether the included tests cover it. Then propose the three
most valuable missing test cases, written as test names plus a
one-sentence description of the assertion.
{{diff}}
5. PR description sanity check
Compare this pull request description with the diff. Flag anything
the diff does that the description does not mention, and anything
the description claims that the diff does not do.
Description: {{pr_description}}
{{diff}}
Keep these as separate prompts instead of one giant checklist. Focused prompts produce sharper findings, and you can run only the ones that fit the change: a config tweak does not need a performance pass.
Wiring AI code review prompts into your workflow
You don't need a heavy platform to start. A small script that builds the prompt from your branch diff is enough, and it works locally or in CI. The callModel function below is a placeholder for whichever LLM API your team uses.
// review.js — run with: node review.js "PR description here"
import { execSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
const description = process.argv[2] ?? 'No description provided';
const diff = execSync('git diff origin/main...HEAD --unified=3', {
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024,
});
if (diff.length > 60_000) {
console.error('Diff too large, split the PR or review per file.');
process.exit(1);
}
const template = readFileSync('./prompts/correctness.txt', 'utf8');
const prompt = template
.replace('{{pr_description}}', description)
.replace('{{diff}}', diff);
// Replace with your provider's SDK call
const review = await callModel(prompt);
console.log(review);
Store the prompt templates in your repository so they are versioned and reviewed like any other code. When a review misses something important, improve the template and the whole team benefits.
Common mistakes
- Sending the whole repository. Send the diff plus only the surrounding context the model needs. Huge inputs dilute attention and raise cost.
- Treating output as a verdict. Models can be confidently wrong. Every finding is a lead to verify, not a merge blocker.
- Skipping the human review. AI review replaces the mechanical first pass, not the conversation about design and trade-offs.
- Leaking sensitive code. Check your company's policy before sending proprietary code to any external API, and strip secrets from diffs.
- Ignoring noise. If the tool produces ten low-value comments per PR, people will stop reading it. Tighten the prompt until signal dominates.
Frequently Asked Questions
Can AI code review prompts replace human reviewers?
No. They are best at consistent, mechanical checks such as missed null cases, obvious injection risks, and absent tests. Humans are still needed to judge architecture, product fit, and maintainability.
How long should a pull request be for AI review?
Smaller is better. Diffs under a few hundred changed lines get the most precise feedback. For larger changes, review file by file or split the PR.
How do I reduce false positives?
Add a severity scale, tell the model to report only issues it can justify from the diff, and allow it to answer "No issues found." Then refine the prompt each time a false positive appears.
Should I run these prompts in CI?
Yes, once the prompts are stable. Run them as a non-blocking step that posts findings as a comment, so developers get fast feedback without a flaky check gating merges.
Conclusion
Good AI code review prompts are specific about role, intent, scope, checklist, and output format, and they are split into focused passes rather than one vague request. Start this week by saving the correctness prompt above into a prompts/ folder in your repository, run it on your next three pull requests, and adjust the wording every time it misses a real bug or invents a fake one.
0 Comments
No comments yet — be the first to share your thoughts.