How to Review Code with an LLM

Using an LLM to review code is one of the most immediately practical applications of AI in software development. It is faster than waiting for a human reviewer, available at any time, and capable of catching a useful class of issues — logic errors, missing edge cases, security anti-patterns, and style inconsistencies — before code reaches a human reviewer or production. It does not replace human code review, but it meaningfully improves the quality of code that reaches human review. This guide covers how to make AI code review effective, what it catches well, and where it falls short.

What AI Code Review Is Good At

LLMs are strong reviewers for several specific categories of issues. Logic errors in well-bounded functions: given a function with clear inputs and a clear purpose, the model can reason about whether the implementation handles all cases correctly. Security anti-patterns: SQL injection via string concatenation, hardcoded credentials, missing input validation, insecure deserialization — the model has seen thousands of examples of these and flags them reliably. Null and edge case handling: “what happens if this list is empty,” “what if this API call returns None,” “what if this integer overflows” — the model systematically considers inputs that code authors often overlook because they are focused on the happy path. Code style and readability: variable naming, function length, whether a comment accurately describes what the code does. Consistency with common patterns: “this is usually implemented with X — is there a reason you used Y instead?” For all of these, the model’s broad exposure to code makes it a useful first pass before human review.

What AI Code Review Misses

LLM code review has clear limitations that are important to understand. Business logic correctness: the model cannot know whether the code correctly implements the business requirement unless you explain the requirement in detail — it can only verify that the code does what it appears to intend, not whether what it intends is right. System-level interactions: issues that arise from how this code interacts with other systems — race conditions with external services, database contention, downstream side effects — are hard for the model to detect without full context of the system. Domain-specific correctness: financial calculations, medical data handling, cryptographic implementations — domains where correctness requires specialised expertise are areas where the model may give confident but incorrect analysis. Performance at scale: the model can flag obvious O(n²) algorithms but often misses performance issues that only appear under specific load patterns or data distributions.

Figure 1 — AI code review: what it catches vs what it misses

✓ Catches reliably ✗ Often misses SQL injection / XSS patternsBusiness logic correctness Missing null / edge case handlingSystem-level race conditions Hardcoded credentials / secretsPerformance under specific load Style / naming inconsistenciesDomain-specific correctness Obvious O(n²) algorithmsSubtle downstream side effects

Integrating AI Review into CI

For teams who want AI code review to happen automatically on every pull request, there are tools that run LLM review as a CI step. CodeRabbit, Greptile, and PR-Agent are examples: they integrate with GitHub or GitLab, trigger on pull request creation, and post review comments automatically. This gives every pull request an AI first pass without any developer needing to manually invoke the review. The comments appear as review suggestions that developers can accept, dismiss, or discuss, just like human reviewer comments. For teams with slow human review cycles, automated AI review on PR creation ensures at least a first pass happens immediately, catching basic issues before the human reviewer even opens the diff. The quality of automated review tools varies; testing a few on your own recent PRs before committing to one is worth doing.

The most effective teams treat AI review and human review as genuinely different things rather than interchangeable. AI review is fast, systematic, and good at the pattern-matching categories described above. Human review is slower, more contextual, and essential for business logic, architecture, and the judgment calls that require understanding the full system. Running both — AI review automatically on PR creation, human review after — captures the benefits of each without treating either as a substitute for the other.

How to Prompt for Effective Code Review

The quality of AI code review depends heavily on how you frame the request. A generic “review this code” produces a generic response — comments on style and obvious issues, but little deep analysis. More targeted prompts produce more useful output. For security review: “Review this code specifically for security vulnerabilities. Consider SQL injection, authentication bypass, input validation gaps, and insecure direct object references.” For logic review: “Here is the function and its specification. Verify whether the implementation correctly handles all cases in the specification, including edge cases.” For the full picture: “Review this code as a senior engineer would. Flag any bugs, security issues, performance concerns, or maintainability problems. Be specific about where issues are and why they matter.” Giving the model a role and a specific focus produces substantially better results than an open-ended review request.

Providing Sufficient Context

Effective AI code review requires providing enough context for the model to do useful analysis. At minimum: the code being reviewed, the language and framework version, and what the code is supposed to do. For better results, also provide: the calling context (how is this function used?), relevant data models (what does the input object look like?), and any known constraints (this runs in a security-sensitive context, this needs to handle 10,000 requests per second). Without context about what the code is supposed to do, the model can only review for form, not substance. A 50-word explanation of the function’s purpose often produces more useful review than 500 words of code alone.

Using AI Review in Your Workflow

The most effective workflow is to use AI review before human review, not instead of it. Write your code, run the tests, then ask the AI to review it before opening a pull request. The AI catches the mechanical issues — the missing null check, the SQL injection risk, the inconsistent naming — so your human reviewer can focus on higher-level concerns: architecture, design decisions, business logic correctness. This makes human code review more valuable by focusing human attention where human judgment is irreplaceable, rather than spending review time on issues a model could have caught in seconds. Teams that adopt this workflow often report shorter review cycles because the code that reaches human review has fewer basic issues.

Iterating on AI Review Feedback

When the AI identifies an issue, the review does not end at the flag — ask follow-up questions. “You flagged a potential SQL injection issue at line 12 — can you show me what a safe version of this query would look like?” or “You mentioned this could cause a race condition — under what specific conditions would that occur?” The AI’s initial review comment is often a starting point for a more detailed conversation that produces a concrete fix rather than just a warning. This back-and-forth is faster than a human review cycle where you submit the fix and wait for re-review, and it ensures you understand why the change is needed, not just what to change.

Reviewing AI-Generated Code

When the code being reviewed was itself generated by an AI, the review dynamic shifts. The model reviewing its own recently generated output may be less critical than reviewing code from a different source. For AI-generated code, consider using a different model for review than for generation — if Cursor with Claude generated the code, paste it into ChatGPT or Gemini for review. This avoids the pattern where the same model produces and approves the same class of errors. The review prompt for AI-generated code should be especially explicit about security: “This code was AI-generated. Review it as if you are looking for the typical mistakes AI coding assistants make, including overly complex solutions, missing error handling, and subtle logic errors in edge cases.”

Diff Review for Pull Requests

For pull request review workflows, paste the diff rather than the full file — the model can focus on what changed rather than reviewing unchanged code that is already in production. A good diff review prompt: “This is a git diff for a pull request. Review only the changed lines for bugs, security issues, and unintended side effects. Describe each issue with the line number and a specific explanation of the problem.” Diff-focused review is faster (less code to process), more focused (the model’s attention is on what changed), and more relevant (it catches issues introduced by the change, not pre-existing issues in unchanged code). For large PRs, split the diff by file and review each file separately to keep the context focused.

AI code review is most valuable as a pre-flight check before human review — catching the mechanical issues quickly so human reviewers can focus on substance. Its value comes from being immediate, tireless, and systematic about the classes of issues it handles well. Its limitations are real and worth understanding: it cannot know whether your code is right for your business requirements, it misses system-level interactions, and it can give confident analysis that is wrong in specialised domains. Use it accordingly — as a capable first reviewer, not as a replacement for the human judgment that remains essential for high-quality software.

Leave a Comment