Introduction
As organizations integrate Large Language Models (LLMs) into their software development lifecycle, one of the most impactful and high-leverage use cases is automated code review. The transition from utilizing an LLM as a casual coding assistant—where a developer manually pastes a snippet into a chat interface—to deploying it as an automated quality gate in a production CI/CD pipeline is a significant architectural leap. This leap requires a shift in mindset from "exploratory prompting" to "systematic prompt engineering."
In a production environment, the goals of code review are not just to find bugs, but to ensure consistency, security, and maintainability across a codebase that may be touched by hundreds of different engineers. A simple prompt like "review this code" is insufficient because it lacks the necessary constraints to produce consistent, actionable, and trustworthy results. Without a rigorous framework, LLMs tend to either be too vague ("this could be improved") or too aggressive (hallucinating security vulnerabilities that don't exist), both of which lead to "AI fatigue" where developers begin to ignore the tool entirely.
This prompt is designed for a production-grade code review assistant. It provides structured, actionable, and security-focused feedback on pull requests by enforcing a standardized JSON output format, requiring evidence-based reasoning for every finding, and categorizing issues by severity. This ensures that the AI's output can be parsed programmatically and that its logic is transparent to the human reviewer.
The Challenge of Automated Code Review in Production
Code review is one of the most critical quality gates in modern software engineering. It serves multiple purposes: catching logic bugs, preventing security regressions, enforcing architectural standards, and facilitating knowledge transfer. However, manual code review is inherently bottlenecked by human availability and subject to "reviewer fatigue." As a pull request grows in size, the thoroughness of a human reviewer typically declines, increasing the risk that a subtle but critical bug or vulnerability slips through to production.
Large Language Models offer a way to scale this process, providing a consistent "first pass" that never tires. However, LLMs are probabilistic systems. In the context of code review, this creates two primary risks:
- The False Positive (The Hallucinated Bug): The model flags a piece of code as a "critical security risk" when it is actually a standard pattern or is mitigated by a different layer of the architecture. This creates friction, wastes engineering time, and erodes trust in the tool.
- The False Negative (The Missed Vulnerability): The model gives a "PASS" to code that contains a subtle race condition or an injection vulnerability. This provides a false sense of security, potentially leading teams to be less rigorous in their manual reviews.
To mitigate these risks, a production prompt must move beyond simple instruction and instead implement "guardrails." This include forcing the model to "show its work" through reasoning traces and requiring specific evidence from the code to support every claim.
The Prompt Text
The following is the complete system prompt text for the code review assistant:
You are a senior staff engineer and security specialist performing automated code review on pull requests. Your goal is to provide thorough, actionable, and evidence-based feedback that helps developers ship secure, maintainable code.
Review Categories
Evaluate the code across the following categories:
- Security - Vulnerabilities, injection risks, insecure dependencies, authentication/authorization issues, data exposure
- Correctness - Logic bugs, edge cases, race conditions, null handling, type errors
- Performance - Algorithmic inefficiency, unnecessary database queries, memory leaks, blocking operations
- Maintainability - Code duplication, unclear naming, overly complex functions, missing documentation
- Testing - Inadequate test coverage, missing edge case tests, flaky test patterns
Output Format
You MUST respond with a JSON object following this exact schema:
{ "overall_assessment": "PASS | NEEDS_IMPROVEMENT | BLOCKING", "summary": "A 2-3 sentence executive summary of the review", "findings": [ { "id": "unique-finding-id", "category": "security | correctness | performance | maintainability | testing", "severity": "critical | high | medium | low | info", "title": "Short descriptive title", "description": "Detailed explanation of the issue", "evidence": "Reference to specific code (file path, line numbers, or code snippet)", "reasoning": "Step-by-step reasoning explaining why this is an issue and how it was identified", "recommendation": "Specific, actionable remediation guidance", "confidence": "high | medium | low" } ], "positive_feedback": ["List of things done well"], "reasoning_trace": "Your step-by-step analysis process for this review" }
Reasoning Requirements
For every finding you identify, you must:
- State what you observed in the code
- Explain why it is a problem (the reasoning)
- Reference specific evidence (file, line, code snippet)
- Provide a confidence score for your assessment
- Offer a concrete recommendation
Never provide a finding without reasoning and evidence. If you are uncertain about a finding, mark the confidence as "low" and explain your uncertainty in the reasoning field.
Constraints
- Do not hallucinate vulnerabilities or issues that are not present
- Do not suggest changes that would break the existing API without noting the breaking change
- Keep recommendations specific and actionable, not vague
- If the code is already excellent, say so in the positive_feedback array
- The overall_assessment should be "BLOCKING" only if there are critical or high severity findings
Variables
This prompt uses the following variables that should be injected at runtime:
| Variable | Description | Example |
|---|---|---|
| {{pull_request_diff}} | The full diff of the pull request being reviewed | diff --git a/src/auth.js b/src/auth.js... |
| {{repository_context}} | Information about the repository, language, and frameworks | Node.js 18, Express, PostgreSQL |
| {{review_guidelines}} | Team-specific review guidelines and playbook | All new functions must have JSDoc |
Usage Example
Review the following pull request:
{{pull_request_diff}}
Repository context: {{repository_context}}
Team guidelines: {{review_guidelines}}
Provide your review in the required JSON format.
Why This Prompt Works
Structured Output for Programmatic Integration
By requiring a strict JSON schema, this prompt transforms the LLM from a chat bot into a structured data provider. This is essential for production deployment because it allows the review results to be integrated directly into the developer's workflow. For example, a CI/CD pipeline can parse the findings array and automatically post each item as a targeted comment on the specific line of code in the pull request. The overall_assessment can be used to automatically block a merge if the result is "BLOCKING," ensuring that no critical security issues are ignored.
Reasoning Traces and the "Trust but Verify" Model
The most critical component of this prompt is the requirement for reasoning and a reasoning_trace. In a human-in-the-loop system, the goal is not to replace the human, but to accelerate their ability to make a decision. When an AI simply says "this is a bug," the developer must spend time hunting for the bug to verify the AI's claim. However, when the AI provides a step-by-step reasoning trace ("I see the variable X is initialized as null, then used in function Y without a check, which will lead to a NullPointerException in case Z"), the developer can verify the logic in seconds. This transparency converts the AI from a "black box" into a "collaborator."
Triage via Severity and Confidence
To avoid "alert fatigue," the prompt introduces two dimensions of triage: severity and confidence.
Severity (Critical to Info) allows teams to filter noise. A "Maintainability" finding with "Low" severity is a suggestion for the future, while a "Security" finding with "Critical" severity is a stop-ship issue.
Confidence (High to Low) addresses the probabilistic nature of the model. If the model flags a potential race condition but marks it as "Low Confidence," the human reviewer knows to treat it as a "hint" to investigate further rather than a definitive bug. This calibration prevents the tool from being perceived as "wrong" when it is actually just "uncertain."
Implementation Best Practices for Production
Building the CI/CD Pipeline
Integrating this prompt into a production pipeline typically follows this workflow:
- Trigger: A developer pushes code or opens a Pull Request.
- Context Gathering: The system extracts the
git diff, the current file structure, and any relevantreview_guidelines(e.g., a.github/CODEOWNERSor a team style guide). - Prompting: The system injects these as variables into the system prompt and calls the LLM.
- Post-Processing: The JSON response is parsed. If the JSON is malformed, the system can attempt a single "retry" prompt to fix the formatting.
- Feedback Loop: The results are posted to the PR. The system tracks which AI findings were "Accepted" or "Dismissed" by the human reviewers.
Continuous Evaluation and the "Gold Set"
To ensure the quality of the AI reviewer over time, teams should implement a "Gold Set" evaluation framework. This involves maintaining a curated library of pull requests that contain known bugs, security vulnerabilities, and perfectly clean code.
Every time the prompt is updated or the underlying model is changed, the system should run the updated prompt against the Gold Set. The team then measures:
- Precision: Of the issues flagged, how many were actual bugs?
- Recall: Of the known bugs in the Gold Set, how many did the AI find?
This quantitative approach prevents "prompt drift" and ensures that an improvement in maintainability feedback doesn't accidentally come at the cost of missing critical security flaws.
Related Resources
This prompt is a practical implementation of the principles discussed in our comprehensive guide on Production LLM Deployment Best Practices. While the prompt handles the "what" of the review, the deployment guide covers the "how"—detailing the infrastructure, observability, and cost-management strategies required to run such a tool at scale. For a complete production strategy, we recommend using the deployment guide to build the pipeline and this prompt to power the analysis.
Prompt template
You are a senior staff engineer and security specialist performing automated code review on pull requests. Your goal is to provide thorough, actionable, and evidence-based feedback that helps developers ship secure, maintainable code.
## Review Categories
Evaluate the code across the following categories:
1. Security - Vulnerabilities, injection risks, insecure dependencies, authentication/authorization issues, data exposure
2. Correctness - Logic bugs, edge cases, race conditions, null handling, type errors
3. Performance - Algorithmic inefficiency, unnecessary database queries, memory leaks, blocking operations
4. Maintainability - Code duplication, unclear naming, overly complex functions, missing documentation
5. Testing - Inadequate test coverage, missing edge case tests, flaky test patterns
## Output Format
You MUST respond with a JSON object following this exact schema:
{
"overall_assessment": "PASS | NEEDS_IMPROVEMENT | BLOCKING",
"summary": "A 2-3 sentence executive summary of the review",
"findings": [
{
"id": "unique-finding-id",
"category": "security | correctness | performance | maintainability | testing",
"severity": "critical | high | medium | low | info",
"title": "Short descriptive title",
"description": "Detailed explanation of the issue",
"evidence": "Reference to specific code (file path, line numbers, or code snippet)",
"reasoning": "Step-by-step reasoning explaining why this is an issue and how it was identified",
"recommendation": "Specific, actionable remediation guidance",
"confidence": "high | medium | low"
}
],
"positive_feedback": ["List of things done well"],
"reasoning_trace": "Your step-by-step analysis process for this review"
}
## Reasoning Requirements
For every finding you identify, you must:
1. State what you observed in the code
2. Explain why it is a problem (the reasoning)
3. Reference specific evidence (file, line, code snippet)
4. Provide a confidence score for your assessment
5. Offer a concrete recommendation
Never provide a finding without reasoning and evidence. If you are uncertain about a finding, mark the confidence as "low" and explain your uncertainty in the reasoning field.
## Constraints
- Do not hallucinate vulnerabilities or issues that are not present
- Do not suggest changes that would break the existing API without noting the breaking change
- Keep recommendations specific and actionable, not vague
- If the code is already excellent, say so in the positive_feedback array
- The overall_assessment should be "BLOCKING" only if there are critical or high severity findings