An LLM can make pull-request review faster, but only when its task is narrow, its context is controlled, and every finding can be checked. This AI code review workflow shows how to configure repeatable feedback without filling a pull request with speculative comments: define review scopes, provide repository context, require file and line citations, separate blocking issues from advice, handle large diffs safely, and measure which suggestions developers accept.
Overview
Automated code review with an LLM should supplement human ownership, not replace it. The most useful setup treats the model as a reviewer that produces evidence-backed observations for a defined purpose. It should not be asked to make a vague judgment such as “find anything wrong.” That instruction encourages broad, inconsistent feedback and makes it difficult for developers to distinguish a real defect from a stylistic preference.
Start by deciding what the review is allowed to evaluate. A practical scope can include security-sensitive changes, incorrect business logic, broken error handling, unsafe data exposure, missing authorization checks, backward-incompatible API changes, and tests that do not cover the changed behavior. Formatting, naming, and broad refactoring advice can be handled separately or excluded unless the team specifically wants that feedback.
The review should also have a clear output contract. Each finding should identify the affected file and line or line range, explain the risk, describe why the current code may fail, and suggest a focused correction when one is reasonably clear. If the model cannot cite the changed code, it should label the observation as uncertain or omit it. A concise list of high-confidence findings is generally more useful than a long list of possibilities.
For repository context, provide the pull-request diff together with the relevant project instructions, surrounding code, interfaces, tests, and configuration. Do not assume that a model can infer architectural rules from a diff alone. When context is retrieved from documentation or a code index, apply the same access controls used by the repository and avoid sending secrets, credentials, or unrelated private material. For broader application security considerations, use the LLM application security checklist.
Checklist by scenario
For a small, focused pull request
- State the change objective and the expected behavior.
- Supply the complete diff, relevant surrounding functions, and the tests that exercise the change.
- Ask for correctness, security, data-handling, and regression risks before style suggestions.
- Require each finding to include a file path, line reference, severity, reasoning, and confidence.
- Return an explicit “no high-confidence findings” result when nothing actionable is found.
This scenario is a good starting point for a pilot because the context is easier to inspect and the output can be compared with a human review. Keep the model’s result as a draft until the team understands its false-positive patterns.
For a security-sensitive change
- Identify the trust boundaries, user-controlled inputs, sensitive data, authentication paths, and authorization decisions affected by the change.
- Ask targeted questions about injection, access control, secret exposure, unsafe deserialization, logging, and error disclosure where relevant to the technology.
- Require the model to distinguish a demonstrated issue from a possible attack path that needs manual confirmation.
- Route high-severity or uncertain findings to a qualified human reviewer rather than automatically blocking the merge.
- Do not give the review process unnecessary credentials or permission to modify code, approve changes, or execute production actions.
Security review benefits from narrow prompts and strong escalation rules. An LLM can help identify questions for investigation, but it does not establish that a vulnerability exists or that an application is secure.
For a large or cross-cutting diff
- Split the review by component, risk area, or logical change rather than sending an unstructured repository-sized prompt.
- Review interfaces and data flows first, then inspect implementation details within each component.
- Use a short repository map that lists key modules, ownership boundaries, public interfaces, and test commands.
- Record findings with stable identifiers so duplicate observations from separate review passes can be merged.
- Run a final synthesis pass that removes duplicates and preserves only findings supported by cited evidence.
Large diffs create two risks: important details may be omitted, and the model may connect unrelated snippets incorrectly. Chunking should follow the code’s logical structure, not an arbitrary character limit. If context windows, latency, or request limits become operational concerns, review the guidance on LLM rate limits and retries and LLM cost optimization.
For a mature team workflow
- Run the review as a non-blocking check initially.
- Define which finding categories may block a merge and which are advisory.
- Send comments only when they meet a confidence and evidence threshold.
- Allow developers to mark a finding as accepted, rejected, duplicate, or needing investigation.
- Review sampled outputs with senior engineers and update the prompt or rules based on observed failures.
Model selection should reflect the repository’s requirements for reasoning quality, latency, context capacity, and cost rather than a generic “best model” label. The LLM model selection guide provides a useful framework for comparing those dimensions.
Pull-request prompt template
Use a prompt with explicit boundaries and a structured response. Adapt the terms to the repository’s language and review policy:
You are reviewing a pull request as a careful software engineer.
Review scope:
- Focus on correctness, security, data handling, authorization, error handling,
compatibility, and regressions caused by the changed code.
- Do not report formatting, naming, or personal style preferences unless they
create a functional or maintenance risk.
- Review only the supplied repository context. Do not invent files, behavior,
requirements, or test results.
For every actionable finding, return:
- severity: blocking, important, or advisory
- confidence: high, medium, or low
- file and line or line range
- problem: what may be wrong
- evidence: the relevant code path or assumption
- recommendation: the smallest reasonable next step
Only report findings that are specific and supported by the diff or supplied
context. If a concern cannot be located in the code, mark it as a question for
human investigation rather than a defect. If there are no high-confidence
findings, say so explicitly. Return JSON with a findings array and a summary.
Validate the returned structure before publishing comments. If the model produces malformed JSON, unsupported line references, duplicate findings, or a severity outside the allowed set, send the result for repair or discard it. Tool calling and schema validation patterns can help when the review is part of an application; see tool calling in LLM applications.
What to double-check
- Repository instructions: Confirm that the model receives current contribution rules, supported versions, test commands, and architecture notes. Remove obsolete instructions that could bias the review.
- Line citations: Check that every comment points to a changed or directly relevant line. A citation that cannot be reproduced is not useful evidence.
- Severity definitions: Write concrete criteria for blocking, important, and advisory findings. For example, a blocking issue might be a credible defect that can cause data loss or unauthorized access, while an advisory item may improve maintainability without requiring an immediate fix.
- Diff completeness: Include deleted code, renamed files, generated configuration changes, migrations, and test changes when they affect behavior.
- Permissions and privacy: Confirm which repository content is sent to the model, who can access logs, how long outputs are retained, and whether the integration can write comments or take other actions.
- Evaluation data: Keep a small set of representative pull requests containing known defects, benign patterns, and deliberately ambiguous cases. Use it to compare prompt or model changes.
- Outcome metrics: Track accepted, rejected, duplicate, and escalated findings. Also monitor review latency, comments per pull request, and the proportion of comments with valid citations. These measures are more informative than raw comment volume.
For prompt changes, treat the review instructions like code. Version them, test them against a regression set, and record the model configuration used for each evaluation. A dedicated prompt testing framework can help teams make changes without losing visibility into quality.
Common mistakes
Asking for everything at once. A broad request produces noisy advice. Start with the risks the team actually wants to catch and add categories only after measuring their value.
Allowing uncited comments. A comment without a file, line, or code path forces the developer to repeat the investigation. Make evidence a hard output requirement.
Blocking merges on unverified guesses. Automatic blocking should be reserved for narrowly defined, high-confidence conditions. Advisory findings can still be useful without interrupting delivery.
Sending only the diff. The diff may not show interface contracts, validation helpers, callers, tests, or configuration defaults. Retrieve the minimum additional context needed for the review question.
Confusing model confidence with correctness. A confident explanation can still be wrong. Require reproducible reasoning and have developers verify important findings against code, tests, and requirements.
Measuring activity instead of value. More comments do not necessarily mean better review. Use acceptance and rejection patterns to identify useful categories, recurring false positives, and prompts that need refinement.
When to revisit
Revisit the workflow before a seasonal planning cycle, when a repository adopts a new language or framework, after a major architecture change, or whenever the team changes its coding model or integration. Also review it when developers report comment fatigue, when security requirements change, or when accepted findings decline.
A practical six-month review can include a fresh sample of pull requests, a comparison of accepted versus rejected findings by category, a permission audit, a check for stale repository instructions, and a test of large-diff behavior. Re-run the evaluation set after changing the prompt, model, retrieval method, output schema, or blocking thresholds. If the workflow becomes expensive or slow, consider routing simple checks to a lighter model while reserving deeper analysis for higher-risk changes; document that policy so results remain understandable.
To roll out the process, choose one repository, run the review in advisory mode, collect developer feedback, and remove low-value categories before expanding. Publish the severity definitions and the way findings should be disputed. Once the results are consistent, decide whether a small subset of high-confidence checks can become merge gates. This staged approach keeps the AI code review workflow accountable to engineering judgment instead of making the model’s output the process.