Introduction
Code review is one of the most valuable yet time-consuming practices in software engineering. A thorough review catches bugs early, enforces coding standards, shares knowledge across teams, and improves maintainability. However, conducting effective reviews consistently requires discipline, structured criteria, and clear communication — especially when reviewers have varying experience levels or when reviews span multiple codebases and programming languages.
This prompt template provides a reusable framework for conducting structured code reviews. It guides the model through evaluating code quality, security, performance, maintainability, and test coverage, producing consistent, actionable feedback with severity levels and specific recommendations. The template works across programming languages and can be adapted to different team conventions and review contexts.
When to Use This Template
Appropriate Use Cases
- Pull request reviews: Review code changes before merging to main branches
- Pre-commit self-review: Developers review their own code before submitting for peer review
- Codebase audits: Periodic review of existing code for quality and security
- Onboarding new team members: Train junior developers on what to look for during reviews
- Cross-language reviews: Review code in languages the reviewer may not know deeply
When NOT to Use This Template
- Security-critical code requiring expert review: This template augments, not replaces, expert security review
- Regulated environments with mandatory review processes: Complement, don't replace, mandated review workflows
- Emergency production fixes: Time-critical fixes may need expedited review paths
Prompt Variables
The template uses the following named variables. Replace each placeholder with actual values before submitting the prompt:
| Variable | Description | Example |
|---|---|---|
code_diff | The code diff or changes to review (unified diff format) | Git diff output showing added/modified lines |
language | Programming language of the code | Python, TypeScript, Go, Java, Rust |
project_conventions | Team or project coding standards | PEP 8, Google Java Style, Airbnb JavaScript Style |
reviewer_role | Perspective of the reviewer | Senior engineer, security reviewer, tech lead, peer reviewer |
focus_areas | Specific areas to emphasize | Security, performance, error handling, testing, documentation |
All five variables are required for complete context. If a variable is not applicable, provide a brief note (e.g., "No specific project conventions defined").
Prompt Text
You are an experienced software engineer conducting a code review. Your role is to provide thorough, constructive, and actionable feedback on code changes.
CONTEXT:
- Code diff: {code_diff}
- Programming language: {language}
- Project conventions: {project_conventions}
- Reviewer role: {reviewer_role}
- Focus areas: {focus_areas}
INSTRUCTIONS:
1. Read through the entire code diff before providing feedback.
2. Evaluate each change against the following criteria:
- Correctness: Does the code do what it claims to do?
- Security: Are there vulnerabilities or unsafe patterns?
- Performance: Are there obvious performance issues?
- Maintainability: Is the code readable and well-structured?
- Testing: Is there adequate test coverage?
- Documentation: Are public APIs and complex logic documented?
3. For each issue found, provide:
- File and line reference
- Issue description
- Severity (Critical, High, Medium, Low, Suggestion)
- Recommended fix or improvement
- Code example where helpful
4. Group feedback by severity level, starting with Critical issues.
5. Provide a summary with overall assessment and recommended next steps.
6. Be constructive: acknowledge good practices, not just problems.
OUTPUT FORMAT:
## Code Review Summary
**Overall Assessment**: [Pass/Major Issues/Minor Issues/Needs Work]
### Critical Issues
- [File:line] Description → Recommendation
### High Issues
- [File:line] Description → Recommendation
### Medium Issues
- [File:line] Description → Recommendation
### Low Issues & Suggestions
- [File:line] Description → Recommendation
### Positive Observations
- [File:line] What was done well
### Recommended Next Steps
1. [Action item]
2. [Action item]
Usage Instructions
Step 1: Prepare the Code Diff
Extract the unified diff of the changes you want reviewed. Include enough context (typically 3-5 lines of unchanged code around each change) so the reviewer understands what each change affects.
Step 2: Fill in Variables
Replace each {variable} placeholder with actual values:
- code_diff: Paste the complete unified diff
- language: Specify the programming language (e.g., "TypeScript", "Python 3.11")
- project_conventions: Reference your team's style guide or conventions
- reviewer_role: Choose the perspective (e.g., "Senior engineer focused on maintainability")
- focus_areas: List priority areas (e.g., "Security, error handling, API design")
Step 3: Submit and Review Output
Submit the completed prompt to your model. Review the output carefully:
- Critical and High issues should be addressed before merging
- Medium issues should be addressed or discussed with the team
- Low issues and suggestions are optional improvements
- Positive observations help reinforce good practices
Step 4: Iterate Based on Feedback
Use the review output to:
- Fix identified issues
- Update your project conventions if patterns recur
- Add the review checklist to your team's contribution guidelines
Worked Example
Input Variables
| Variable | Value |
|---|---|
code_diff | A Python diff adding a user authentication endpoint with password hashing |
language | Python 3.11 |
project_conventions | PEP 8, type hints required, docstrings for public functions |
reviewer_role | Senior backend engineer |
focus_areas | Security, error handling, input validation |
Expected Output Structure
## Code Review Summary
**Overall Assessment**: Major Issues
### Critical Issues
- [auth.py:42] Password stored in plaintext → Use bcrypt or argon2 for password hashing
### High Issues
- [auth.py:55] No rate limiting on login endpoint → Add rate limiting to prevent brute force
### Medium Issues
- [auth.py:31] Missing type hints on function parameters → Add type annotations per PEP 484
### Low Issues & Suggestions
- [auth.py:18] Import ordering not alphabetical → Reorder imports per PEP 8
### Positive Observations
- [auth.py:12] Good use of environment variables for configuration
### Recommended Next Steps
1. Fix plaintext password storage before merge
2. Add rate limiting middleware
3. Add type hints to all public functions
Limitations
This prompt template is a tool to assist code review, not a replacement for human judgment. Consider:
- False positives: The model may flag valid patterns as issues
- False negatives: Security vulnerabilities may be missed
- Context limitations: The model only sees the provided diff, not the full codebase
- Language-specific nuances: Some issues may be language or framework-specific
Always have a qualified engineer review the model's output before acting on it, especially for security-critical code.
Related Resources
For complementary practices, see:
- Implementing Effective Model Caching in LLM Applications — Caching strategies that can reduce review workload for repetitive code patterns
- Model Cascading in Production: Cost-Effective AI Workflow Orchestration — Routing strategies that can route simple reviews to cheaper models
Prompt template
You are an experienced software engineer conducting a code review. Your role is to provide thorough, constructive, and actionable feedback on code changes.
CONTEXT:
- Code diff: {code_diff}
- Programming language: {language}
- Project conventions: {project_conventions}
- Reviewer role: {reviewer_role}
- Focus areas: {focus_areas}
INSTRUCTIONS:
1. Read through the entire code diff before providing feedback.
2. Evaluate each change against the following criteria:
- Correctness: Does the code do what it claims to do?
- Security: Are there vulnerabilities or unsafe patterns?
- Performance: Are there obvious performance issues?
- Maintainability: Is the code readable and well-structured?
- Testing: Is there adequate test coverage?
- Documentation: Are public APIs and complex logic documented?
3. For each issue found, provide:
- File and line reference
- Issue description
- Severity (Critical, High, Medium, Low, Suggestion)
- Recommended fix or improvement
- Code example where helpful
4. Group feedback by severity level, starting with Critical issues.
5. Provide a summary with overall assessment and recommended next steps.
6. Be constructive: acknowledge good practices, not just problems.
OUTPUT FORMAT:
## Code Review Summary
**Overall Assessment**: [Pass/Major Issues/Minor Issues/Needs Work]
### Critical Issues
- [File:line] Description → Recommendation
### High Issues
- [File:line] Description → Recommendation
### Medium Issues
- [File:line] Description → Recommendation
### Low Issues & Suggestions
- [File:line] Description → Recommendation
### Positive Observations
- [File:line] What was done well
### Recommended Next Steps
1. [Action item]
2. [Action item]