Use these reusable AI code review prompt templates to examine pull requests for defects, security risks, missing tests, breaking changes, and maintainability issues—while keeping a human reviewer responsible for verifying every finding.
Overview
AI can make a pull request review more systematic, but the quality of the result depends on the context you provide and the boundaries you set. A useful review prompt should identify the change under review, describe the relevant repository conventions, request evidence for each finding, and separate confirmed issues from questions or suggestions.
Before using any of the templates below, prepare a review bundle that includes the pull request diff, the affected files, the intended behavior, relevant tests, and any project-specific rules. If the change depends on an API contract, database schema, authentication flow, deployment setting, or configuration file, include the smallest relevant excerpt. Avoid sending an entire repository when a focused context set is enough.
These prompts work best as focused passes rather than one broad request. Run a bug review, security review, and test-coverage review separately. This makes the output easier to verify and turns valid findings into specific review comments, tests, or follow-up tasks.
Context block to reuse
Repository context:
- Language and framework: [for example, TypeScript and a web framework]
- Change objective: [what the pull request is intended to do]
- Compatibility requirements: [supported versions, platforms, or APIs]
- Relevant conventions: [error handling, naming, testing, logging]
- Files in scope: [list files or modules]
Pull request description:
[Paste the description]
Diff:
[Paste the relevant diff]
Related tests, contracts, or schema:
[Paste only the relevant material]
Ask the model to cite file names, symbols, and approximate line locations from the supplied material. If it cannot support a claim from the context, it should label the item as a question rather than a finding.
Checklist by scenario
1. General bug and behavior review
Use this pass when you want to know whether the implementation matches the stated intent and handles realistic edge cases.
Act as a careful pull request reviewer. Review the supplied change for functional bugs, incorrect assumptions, state-management errors, race conditions, error-handling gaps, and edge cases.
For each potential issue, return:
1. Severity: blocker, high, medium, low, or question
2. Location: file, symbol, and line or code excerpt
3. Why it may be a problem
4. A concrete input, state, or execution path that demonstrates the risk
5. A minimal fix or verification step
Do not report style preferences as defects. Do not infer behavior that is not supported by the supplied context. If the evidence is insufficient, say what additional context is needed. End with a short list of areas reviewed and any areas that could not be evaluated.
2. Security review
Use a separate security pass for changes involving user input, authentication, authorization, secrets, file handling, network requests, database queries, serialization, or administrative functions. This prompt is a review aid, not a substitute for targeted testing or a formal security assessment.
Review this pull request for security weaknesses introduced or exposed by the change. Focus only on risks supported by the supplied code and context, including authentication and authorization failures, injection paths, unsafe output handling, sensitive-data exposure, insecure file or URL handling, weak validation, and accidental secret disclosure.
For each finding, provide:
- Category
- Severity with a brief justification
- Exact affected location
- Attacker-controlled input or prerequisite, if applicable
- Observable impact
- Safer remediation direction
- A test or inspection a human reviewer should perform
Distinguish a confirmed code path from a hypothetical concern. Do not claim that a control exists unless it appears in the supplied context. Do not reproduce or transform any apparent secret; flag it for removal and rotation procedures instead.
For a broader workflow, pair this pass with a documented prompt-injection defense checklist when the change handles retrieved content, tool calls, or untrusted instructions. See Prompt Injection Defense for AI Assistants.
3. Missing test and coverage review
Code coverage percentages do not by themselves show whether behavior is well tested. Ask the model to map changed behavior to test cases, including failure paths and boundary conditions.
Review the pull request for missing or weak tests. First summarize the behavior changed. Then create a behavior matrix with:
- Scenario
- Expected result
- Existing test, if present
- Missing test or assertion
- Suggested test level: unit, integration, contract, end-to-end, or manual check
Prioritize tests for changed branches, invalid input, empty or boundary values, permission differences, retries and failures, persistence effects, and backward compatibility. Do not recommend tests for behavior that is outside the supplied change unless you label it as an optional follow-up. For each proposed test, identify the observable assertion that proves the behavior.
4. Breaking-change and compatibility review
This review is useful for public functions, API responses, database schemas, configuration, command-line interfaces, and shared libraries.
Analyze this pull request for breaking changes. Compare the old and new behavior using only the supplied diff, contracts, schemas, examples, and compatibility requirements.
Check for changes to:
- Function or method signatures
- Required versus optional fields
- Response shapes, status codes, or error formats
- Database migrations and rollback assumptions
- Configuration names and defaults
- Serialization, validation, and null handling
- Supported runtime or dependency behavior
Return a table with: affected contract, old behavior, new behavior, likely consumers, evidence, and recommended migration or test. Mark items as confirmed, likely, or unable to determine.
Quick task-to-template reference
| Review goal | Use | Best output |
|---|---|---|
| Find defects | General bug review | Evidence-backed findings with reproduction paths |
| Find security risks | Security review | Risk, affected input, impact, and verification step |
| Improve tests | Test and coverage review | Behavior matrix and prioritized test cases |
| Protect consumers | Compatibility review | Contract changes and migration actions |
What to double-check
- Evidence: Confirm that every reported issue is visible in the diff or supplied repository context. Ask the model to quote the relevant code rather than accepting an unsupported summary.
- Severity: Reassess severity against your application’s real exposure, data sensitivity, availability needs, and deployment path. Model labels are starting points, not decisions.
- Reproduction: Try the proposed input, failing state, or execution path locally. A plausible explanation is not proof that the issue occurs.
- Test value: Turn valid findings into a regression test where practical. A test should assert observable behavior, not merely execute the changed lines.
- Repository conventions: Check whether the suggested fix matches existing error handling, logging, validation, dependency, and test patterns.
- Data handling: Remove API keys, tokens, private credentials, customer data, proprietary prompts, and unnecessary source code before sharing a diff with an external model or service. Use redacted placeholders consistently so the code remains understandable.
- Scope: Ask for a separate pass when the pull request combines unrelated changes. A focused review is easier to audit than a long list of mixed recommendations.
For teams that run reviews repeatedly, store the prompts with a version, owner, intended task, and example output. A prompt change can alter what the review catches, so evaluate it against representative pull requests before making it the default. The AI prompt versioning checklist provides a practical structure for naming and rollback.
Common mistakes
- Sending only the diff: Without the intended behavior, tests, contracts, or surrounding code, the model may mistake an intentional change for a defect. Add focused context and state what is out of scope.
- Requesting “review everything”: Broad prompts often produce style suggestions and speculative concerns. Name the review objective and define the required finding format.
- Treating confidence as verification: Clear language can still describe a nonexistent bug. Require evidence, reproduction steps, and a human check.
- Ignoring negative paths: Happy-path examples conceal failures involving timeouts, retries, malformed input, empty results, permissions, and partial updates. Include these cases explicitly in the test prompt.
- Accepting generated fixes without review: A proposed patch may remove one issue while creating another. Review the patch as a new change and run the relevant tests.
- Using stale context: An old schema, dependency contract, or configuration example can make a correct implementation look wrong. Record the version or commit associated with supplied context.
When to revisit
Revisit these AI code review prompt templates whenever the review workflow or its inputs change. In particular, update them when your team adopts a new model or coding tool, changes repository conventions, introduces a framework or language version, modifies API or database contracts, or adds a new security-sensitive integration.
Before a seasonal planning cycle or a large release, sample recent pull requests and check whether the prompts still produce useful, verifiable findings. Compare results across a small set of known issues and clean changes: the review should identify meaningful risks without turning ordinary implementation choices into defects.
A practical recurring checklist is:
- Remove secrets and unnecessary private context.
- Select one focused template for the review goal.
- Attach the diff, intent, relevant contracts, and tests.
- Require locations, evidence, severity reasoning, and verification steps.
- Validate findings manually and run the appropriate tests or tools.
- Convert confirmed issues into review comments, regression tests, or tracked tasks.
- Record useful prompt changes and reassess them when tools or workflows change.
AI code review is most dependable as a structured second pass. Keep the human reviewer accountable for context, risk acceptance, and final approval, and use the templates as repeatable prompts—not as automatic proof that a pull request is safe.