AI Code Review Workflow: Prompts, Triage Rubric and a Worked Diff Example
A repeatable AI code review workflow: what context to give the model, a review prompt that demands evidence, a triage rubric for false positives, human checks, and how to package it as a reusable review skill.
AI can make code review faster, but only if you treat its output as a list of claims to check rather than a verdict. A model will find real bugs, miss others, and confidently flag things that are fine. The useful part is the workflow around it: what you give the model, how you ask for findings, how you sort them, and what a human always checks.
This guide walks through one illustrative reviewed diff end to end, then turns it into a repeatable process you can save as a prompt or a reusable skill. For broader prompting technique, see the coding prompts workflow guide.
What AI Review Is Good and Bad At
Usually helpful:
- Spotting common bug patterns: missing authorization checks, unbounded inputs, unhandled error paths, off-by-one logic
- Applying a checklist consistently to every pull request
- Explaining why something is risky, which helps the author learn
- Suggesting test cases for the change
Usually weak without help:
- Business rules it has not been told about
- Code outside the diff (callers, middleware, schemas, config)
- Your team's conventions and known exceptions
- Telling a real problem from a pattern that only looks risky
The second list is why context and triage matter more than the wording of the review prompt.
A Worked Example: One Diff, Reviewed
Illustrative example, not a measured result. The diff, review comments and triage below were written for this article to show the workflow. They are not output from a benchmark or a study, and a real model's comments will differ between runs and models.
The diff
A pull request adds an invoice PDF download endpoint and a limit option to the invoice list in an Express + TypeScript API that uses an ORM:
// routes/invoices.ts
router.get("/invoices", requireAuth, async (req, res) => {
const orgId = req.user.orgId;
- const invoices = await db.invoice.findMany({ where: { orgId } });
+ const limit = Number(req.query.limit) || 50;
+ const invoices = await db.invoice.findMany({ where: { orgId }, take: limit });
res.json(invoices);
});
+router.get("/invoices/:id/pdf", requireAuth, async (req, res) => {
+ const invoice = await db.invoice.findUnique({ where: { id: req.params.id } });
+ if (!invoice) return res.status(404).end();
+ const pdf = await renderInvoicePdf(invoice);
+ res.setHeader("Content-Type", "application/pdf");
+ res.send(pdf);
+});
PR description: "Customers can download an invoice as PDF. Also adds ?limit= to the list endpoint."
What the AI reviewer said (illustrative)
| # | Comment | Severity given |
|---|---|---|
| 1 | The PDF route loads the invoice by id only. Any authenticated user can download another organization's invoice by guessing or enumerating IDs. Check invoice.orgId === req.user.orgId. | High |
| 2 | limit comes from the query string and is not bounded. ?limit=1000000 loads every invoice for the org in one query. Clamp it, for example to 1-100. | Medium |
| 3 | req.params.id is passed into a database query: SQL injection risk. | Medium |
| 4 | renderInvoicePdf is awaited without a try/catch; a rejected promise may not reach your error handler. | Low |
| 5 | Use findFirst instead of findUnique for better performance. | Low |
How the human reviewer triaged it
| # | Verdict | Why |
|---|---|---|
| 1 | Confirmed, must fix | Reproduced by reading the code: nothing ties the invoice to the caller's org. The fix is to query with both id and orgId, and return 404 (not 403) so IDs are not confirmed to exist. A regression test was added for cross-org access. |
| 2 | Confirmed, fix | Real but lower impact: the query is still scoped to the caller's org. Clamp and validate the value. |
| 3 | False positive | The ORM sends id as a bound parameter, not string-concatenated SQL. The reviewer checked that no raw query is involved. |
| 4 | Context-dependent | Whether this matters depends on the framework version and on whether the project already wraps async handlers. The reviewer checked the project's error middleware before deciding. |
| 5 | False positive / noise | Looking up a record by its unique primary key is exactly what findUnique is for. No evidence of a performance problem was given. |
What the human caught that the AI did not
- Caching of sensitive files. Invoices contain billing details. The response sets no
Cache-Controlheader, so the reviewer asked forCache-Control: private, no-storebecause the API sits behind a CDN. - Product rule. Draft invoices should not be downloadable. That rule lives in a product spec the model never saw.
- Test coverage. The PR had no test for the new route at all. The reviewer asked for tests covering own-org success, cross-org 404, missing invoice 404, and
limitclamping.
The lesson from this example: the two most important findings (#1 and the caching issue) were one AI catch and one human catch. Two of the five AI comments would have wasted the author's time if applied without checking.
The Repeatable Workflow
Step 1: Build a context packet
Most false positives come from missing context. Before you run a review, gather:
- The diff, not entire files. Add a few lines of surrounding code where the change depends on it.
- Intent: the PR description or ticket. What should this change do?
- Code the diff relies on: auth middleware, the schema or model definitions involved, and direct callers.
- Conventions: error handling pattern, validation library, logging rules, test framework.
- Known non-issues: patterns your team has decided are fine, for example "the ORM parameterizes all queries; do not flag injection for ORM calls."
- Out of scope: what you do not want comments on (formatting handled by the linter, naming bikesheds).
Do not paste secrets, credentials or customer data into a review prompt, and check your organization's policy and your AI provider's data terms before sending proprietary code.
Step 2: Ask for findings with evidence
The single biggest improvement to an AI review prompt is requiring evidence for every finding. It makes false positives easier to spot and discourages vague comments.
You are reviewing a pull request. Report only problems you can support
with evidence from the code provided.
## Context
PR intent: [WHAT THIS CHANGE SHOULD DO]
Stack: [LANGUAGE, FRAMEWORK, ORM/DB, TEST FRAMEWORK]
Relevant code outside the diff:
[AUTH MIDDLEWARE / SCHEMA / CALLERS]
Team conventions:
[ERROR HANDLING, VALIDATION, LOGGING RULES]
Known non-issues (do not report):
[e.g. ORM calls are parameterized; formatting is enforced by the linter]
## Diff
[DIFF]
## Instructions
Check, in this order:
1. Authorization and data exposure (can a caller reach data they should not?)
2. Input validation and resource limits
3. Correctness and edge cases against the stated intent
4. Error handling
5. Missing tests for the changed behavior
For each finding, output:
- Location: file and line(s)
- Problem: one sentence
- Evidence: the specific code path or input that triggers it
- Severity: high / medium / low
- Confidence: high / medium / low, and what context would change your mind
- Suggested fix
If you are unsure whether something is a problem because it depends on
code you cannot see, list it under "Questions for the author" instead of
reporting it as a finding. If you find nothing significant, say so.
You can browse more review templates in the code review prompt collection, or start from the pull request code review template.
Step 3: Triage every finding
Use a fixed rubric so triage is fast and consistent across reviewers:
| Verdict | Test | Action |
|---|---|---|
| Confirmed | You can point to the code path or write a failing test | Fix before merge; add a regression test where practical |
| Plausible | It depends on context outside the diff | Check that context or ask the author; don't block on the AI's word alone |
| False positive | The evidence is wrong (e.g., the framework already handles it) | Dismiss, and add a "known non-issue" line to the prompt if it recurs |
| Noise | Style preference, speculative performance advice, or something the linter owns | Dismiss; tighten the "out of scope" section |
Two habits keep this honest:
- Severity and confidence are separate. A high-severity, low-confidence finding (like a possible authorization gap) is worth checking even if it turns out to be wrong. A low-severity, low-confidence one usually isn't.
- Record the verdicts. A short log of accepted and dismissed findings per PR is what tells you whether the prompt is improving.
Step 4: Human checks that always happen
Regardless of what the AI said, the human reviewer checks:
- Intent: does the change do what the ticket asked, including product rules the model never saw?
- Authorization: for every new data access, who can reach it, and is it scoped to the caller?
- Sensitive data: logging, caching headers, error messages and responses don't leak more than intended
- Tests: the changed behavior is covered, including at least one failure or abuse case
- Each "Confirmed" fix: verified by a test or by reading the fixed code, not by trusting the AI's suggested patch
- Architecture and ownership: the change fits where it lives, and the right people have seen it
Step 5: Iterate on the prompt, not on individual reviews
After a handful of PRs, look at your triage log:
- Recurring false positives become "known non-issues" in the context packet.
- Recurring noise becomes an "out of scope" line.
- Bugs that reached production but were visible in the diff become a new item in the check order.
Re-run the updated prompt on a few past PRs where you already know the right answer (for example, PRs that later needed a bug fix). This is a small evaluation set of your own; it will tell you more about whether the prompt works on your codebase than any general claim about a model.
Focused Passes for Higher-Risk Changes
For most PRs, one evidence-based review is enough. For risky changes, run a focused pass with the same context packet.
Security pass:
Using the context and diff above, act as a security reviewer. Focus only on:
authentication and authorization, injection (SQL, command, template, XSS),
secrets and sensitive data exposure, unsafe deserialization, SSRF, and
missing rate or size limits. For each finding give location, the attack
input or request that triggers it, severity, confidence, and a fix.
Do not report issues the context marks as known non-issues.
Performance pass:
Using the context and diff above, look only for performance problems that
matter at this scale: [EXPECTED DATA SIZES / REQUEST RATES].
Consider N+1 queries, unbounded queries or loops, blocking calls on hot
paths, and missing pagination. For each finding, explain the input size at
which it becomes a problem. Skip micro-optimizations.
Refactor pass (behavior should not change):
This PR is intended to be a pure refactor of [COMPONENT].
Old implementation:
[OLD CODE]
New implementation:
[NEW CODE]
List every behavioral difference you can find, including error handling,
ordering, null/empty handling and side effects. If there are none, say so.
Then list tests that would prove equivalence.
Bug-fix pass:
This PR fixes: [BUG DESCRIPTION AND REPRODUCTION STEPS]
Fix:
[DIFF]
1. Does the fix address the root cause or only the symptom?
2. What other inputs reach the same faulty code path?
3. What regression test would have caught the original bug?
Turn It Into a Reusable Review Skill
Once the prompt and context packet are stable, store them somewhere your tools load automatically instead of pasting them each time.
Option 1: a saved prompt. Keep the review prompt as a template with placeholders, and version it as you add known non-issues.
Option 2: an Agent Skill. The Agent Skills format is a directory with a SKILL.md file containing YAML frontmatter (a required name and description) followed by Markdown instructions; optional folders such as references/ can hold longer material (Agent Skills specification, checked 2026-11-05). A minimal review skill might look like this:
---
name: pr-review
description: Reviews a pull request diff for authorization, input validation, correctness, error handling and missing tests. Use when asked to review a PR, a diff, or staged changes.
---
# PR review
## Inputs to gather
- The diff and PR description
- Auth middleware, schemas and direct callers touched by the diff
- references/conventions.md and references/known-non-issues.md
## Check order
1. Authorization and data exposure
2. Input validation and resource limits
3. Correctness against the stated intent
4. Error handling
5. Missing tests
## Output
For each finding: location, problem, evidence, severity, confidence, fix.
Put anything that depends on unseen code under "Questions for the author".
HyperPrompt's code review skill is a starting point you can adapt: it checks code quality, security and performance and returns findings with severity, location, description and a suggested fix. Add your own evidence requirement, check order and known non-issues to it.
Option 3: project instructions for your coding assistant. Most AI coding tools read project-level instruction files, and review guidance can live there. For example, Cursor reads project rules from .cursor/rules as .mdc files and also supports AGENTS.md (Cursor docs, checked 2026-11-05); Claude Code reads CLAUDE.md (Claude Code docs, checked 2026-11-05); and GitHub Copilot reads .github/copilot-instructions.md, which applies to Copilot code review by default (GitHub docs, checked 2026-11-05). See how to write Cursor rules and the rules library for examples.
Where AI Review Fits in a Team Process
Three common setups, each with a different tradeoff:
- Author self-review before opening the PR. The author runs the review prompt, fixes confirmed issues, and notes dismissed ones in the PR description. Cheapest; relies on the author's triage.
- AI first pass, human second. The AI comments on the PR; the human reviewer triages those comments and then focuses on intent, architecture and anything the checklist above requires. Works well when the triage rubric is shared.
- Human-led with focused AI passes. The reviewer runs a security or performance pass only when the change warrants it. Lowest noise; depends on the reviewer noticing risk.
In every setup, the AI does not approve merges. A human owns the decision.
What to Track
If you want to know whether AI review is helping, track your own numbers rather than relying on general claims:
| What | How |
|---|---|
| Accepted findings | Count findings triaged as Confirmed per PR |
| False positive rate | False positives + noise divided by all findings |
| Escaped bugs | Bugs found after merge that were visible in the reviewed diff |
| Review time | Time from PR open to approval, before and after adoption |
| Reviewer sentiment | A short periodic survey: is the AI pass worth reading? |
Frequently Asked Questions
Does AI code review replace human reviewers?
No. In the example above, one of the two most important findings came from a human who knew a product rule and the deployment setup. Use AI to widen coverage and speed up the mechanical checks; keep humans responsible for intent, risk and approval.
How do I reduce false positives?
Give the model the code it needs to judge the change (middleware, schemas, callers), require evidence for every finding, and keep a "known non-issues" list that grows as you triage.
Which model should I use for code review?
Models and their capabilities change frequently, so we don't recommend a specific one here. Run your prompt on a few past PRs where you already know what the right review comments were, and compare candidates on accepted findings and false positives.
What about code confidentiality?
Check your organization's policy and your provider's data handling terms before sending proprietary code. Never include secrets or production customer data in a review prompt.
Should every PR get an AI review?
Not necessarily. Docs-only and generated-file changes rarely benefit. Many teams start with author self-review on all PRs and a focused security pass on changes that touch authentication, payments or data access.
Next steps: browse code review prompts, adapt the code review skill, or pair this with debugging prompts for the fixes that review uncovers.
Related Articles
Coding Prompts That Work: A Workflow from Context to Verified Code
A practical workflow for AI-assisted coding: give the right context, set constraints, generate in small steps, verify with tests, review and security checks, and iterate. Links to individual coding templates for each step.
How to Create Claude Code Skills: A SKILL.md Guide with a Worked Example
Create an Agent Skill for Claude Code: directory layout, SKILL.md frontmatter rules, supporting files and scripts, where Claude Code discovers skills, how they are invoked, failure handling, and how skills differ from MCP servers.
50 ChatGPT Prompts for Developers, With Example Output Shapes
50 copy-paste prompts for debugging, code review, documentation, refactoring and everyday dev tasks, with illustrative input and output examples for the five most useful ones and notes on verifying results.