AI code review prompts can help developers find defects, security risks, missing tests, and maintainability problems, but only when the review is structured and every recommendation is verified. This guide provides a reusable workflow and prompt templates for using an LLM as a review assistant without treating its output as an approval.
Overview
LLM code review works best as a focused analysis step inside an existing pull-request process. The model can inspect code, explain control flow, identify suspicious edge cases, suggest tests, and summarize changes. It cannot reliably replace compilation, automated tests, dependency scanning, runtime observation, or human judgment about product requirements.
The quality of an AI review depends heavily on the information provided. A short instruction such as “find bugs in this code” gives the model too little context and often produces a mixture of useful observations, speculative concerns, and missed issues. Better prompt engineering defines the reviewer’s role, supplies the relevant code and constraints, asks for evidence, and requires uncertainty to be stated explicitly.
Before sending code to an AI developer tool or LLM API, remove secrets, credentials, private keys, customer data, and unrelated proprietary material. Provide the smallest useful context: the changed files, relevant interfaces, error-handling conventions, tests, and a short description of intended behavior. If the repository is large, review it in stages rather than placing an entire codebase into one prompt.
A dependable workflow has five stages: prepare the review context, run scenario-specific prompts, verify each finding, convert confirmed issues into changes or follow-up tasks, and record useful feedback for future prompt refinement. This makes AI code review an auditable part of development rather than an informal suggestion generator.
Checklist by scenario
1. General bug-finding review
Use this prompt when you want a first pass over a pull request or function:
You are reviewing code as a careful senior engineer. Analyze the supplied diff and relevant surrounding code for functional bugs, incorrect assumptions, edge cases, error-handling failures, and regressions.
Context:
- Language and runtime: [language/runtime]
- Intended behavior: [short description]
- Changed files: [files]
- Relevant constraints: [performance, compatibility, business rules]
For each finding, provide:
1. Severity: critical, high, medium, low, or informational
2. Exact file and line or code reference
3. Why the behavior is likely incorrect
4. A concrete input or execution path that demonstrates the risk
5. A minimal fix or test that would confirm the issue
Do not report style preferences as bugs. If evidence is insufficient, label the concern as uncertain and explain what additional context is needed.
The request for a reproducible path is important. It helps separate a real defect from a plausible-sounding concern and gives the human reviewer a direct way to test the claim.
2. Security-focused review
Security analysis should be narrow and explicit. Ask the model to inspect relevant trust boundaries rather than simply requesting “a security audit.”
Review this code for security weaknesses. Focus on input validation, authentication and authorization, injection risks, sensitive-data exposure, unsafe deserialization, path or command handling, insecure defaults, logging, and error responses.
Identify:
- The untrusted input or attacker-controlled condition
- The affected operation or trust boundary
- The required precondition for exploitation
- The likely impact if the issue is real
- A remediation that fits the existing architecture
- A test or review step that can validate the finding
Do not claim exploitability without showing the relevant data flow. Distinguish confirmed evidence, plausible risk, and missing information. Do not reproduce or retain secrets found in the input.
An LLM can point toward a security concern, but security findings require verification against the actual framework configuration, deployment environment, permissions, and data flow. Use established security tooling and qualified review for high-impact systems.
3. Test-generation review
Ask for tests based on behavior and risk, not merely line coverage:
Analyze the changed code and propose tests for expected behavior, boundary conditions, invalid input, failure handling, concurrency or ordering issues, and regression risks.
For every proposed test, include:
- Scenario and expected result
- Why the scenario matters
- Required fixtures or mocks
- The smallest useful test implementation in [framework]
- Any assumption that must be confirmed first
Prioritize tests that could distinguish a correct implementation from the current implementation. Do not invent APIs, fixtures, or business rules that are not supported by the supplied context.
Review generated tests for assertions that could pass without testing the intended behavior. A test with extensive setup but weak assertions can create false confidence.
4. Maintainability and refactoring review
Use a separate prompt for design quality. Mixing every possible concern into one request makes prioritization harder.
Review this code for maintainability. Look for unclear responsibilities, duplicated logic, excessive coupling, difficult-to-test components, misleading names, hidden side effects, and error-handling patterns that will make future changes risky.
Return no more than five findings, ordered by likely maintenance impact. For each finding, explain the cost of leaving it unchanged and suggest a small, incremental refactoring. Preserve public behavior unless a behavior change is explicitly requested. Call out changes that would require broader tests or architectural review.
5. Pull-request summary and dependency-risk review
For a pull-request summary, instruct the model to stay factual:
Summarize this pull request for a technical reviewer. Include the purpose, files or components affected, externally visible behavior changes, risk areas, test coverage, and questions that remain unanswered. Separate facts directly supported by the diff from reasonable inferences. Do not describe an issue as fixed unless the code and tests support that conclusion.
For dependency changes, provide the manifest diff, lockfile changes, runtime compatibility requirements, and reason for the upgrade. Ask the model to identify transitive changes and migration questions, but verify versions, advisories, licenses, and compatibility with authoritative project and repository tooling.
What to double-check
- Context: Did the model receive the relevant interface, configuration, tests, and intended behavior? Missing context can turn a correct implementation into a false positive.
- Evidence: Can each finding be tied to a line, data flow, input, or execution path? Reject vague warnings that provide no way to reproduce or investigate the issue.
- Severity: Does the priority reflect realistic impact and likelihood, or is the model using alarming language without operational evidence?
- Tests: Does the suggested test assert the business or security property that matters? Run it against both the original and modified code where practical.
- Scope: Did the review examine the complete change, including migrations, configuration, error paths, and callers? A function-level review may miss integration failures.
- Privacy: Were secrets and sensitive records removed before the prompt was submitted? Establish an approved handling process for source code and model providers.
- Tool behavior: Check the current model context limits, repository access, IDE integration, structured-output support, and retention settings before standardizing a workflow. These capabilities can change.
For production AI workflows, treat the review prompt like a small specification. Version it, test it against representative examples, and track which findings reviewers accepted, rejected, or marked as uncertain. The automated prompt testing checklist provides a useful pattern for evaluating prompt changes. If the workflow calls an LLM through an API, also plan for timeouts, retries, rate limits, and fallbacks as described in the reliable LLM API calls checklist.
Common mistakes
Using one giant prompt for every review. Bug discovery, security analysis, test generation, and summarization have different success criteria. Separate prompts make results easier to evaluate and reduce unfocused output.
Accepting a finding because it sounds technical. Require a code reference and a reproduction path. If neither is available, classify the result as a hypothesis rather than an issue.
Asking the model to approve the pull request. An LLM should report observations and uncertainty, not make an unreviewed release decision. Keep merge approval tied to your normal human and automated controls.
Supplying only the changed lines. A diff is useful, but many bugs depend on callers, interfaces, configuration, schemas, or tests. Add targeted surrounding context when it affects behavior.
Letting generated patches bypass review. Apply suggestions in a controlled branch, run formatting, static analysis, tests, and security checks, then inspect the final diff. A proposed fix can introduce a new defect or alter behavior outside the original issue.
Failing to record rejected findings. False positives are valuable feedback. Capture why a finding was rejected and use those examples when refining the prompt, context selection, or output schema. For large repositories, retrieval quality also matters; the RAG retrieval troubleshooting guide covers missing, irrelevant, and conflicting context.
When to revisit
Review this workflow whenever the underlying inputs change. Revisit prompts before a new planning or release cycle, after adopting a different coding model or IDE integration, and when repository languages, frameworks, security requirements, or test conventions change. A prompt that worked with one model may need adjustment when context handling, tool access, structured output, or response behavior changes.
Schedule a lightweight review of the workflow after several pull requests. Compare accepted findings with missed defects, duplicate warnings, and reviewer corrections. Update the examples, severity definitions, and required output fields based on that evidence. Also check token usage, latency, and failure handling if the review is automated; the LLM cost and latency checklist can help organize that review.
Before your next pull request, use this action list:
- Remove secrets and unrelated sensitive material.
- Write down the intended behavior and review scope.
- Run a general bug prompt, then focused security and test prompts where relevant.
- Require evidence, severity, uncertainty, and a verification step for every finding.
- Reproduce or disprove each high-priority concern using code, tests, tools, or documentation.
- Apply only verified changes, run the normal checks, and record useful prompt feedback.
Used this way, AI code review prompts support better engineering judgment without replacing it. The most reliable workflow is not the one that produces the longest list of warnings; it is the one that helps reviewers find meaningful issues, verify them efficiently, and improve with each change.