Introduction
Code review is a critical quality gate in software development, but manual review of every pull request can become a bottleneck as teams and codebases grow. LLM-assisted code review can help by surfacing potential issues early, suggesting improvements, and ensuring consistent feedback across reviewers. This prompt template provides a structured, reusable framework for code review that covers style, correctness, security, and maintainability. It is designed to be adapted to different programming languages, project conventions, and review priorities through clearly named variables. All examples are hypothetical unless explicitly attributed to a named source, and no benchmark results or performance claims are made.
For a related example of structured review workflows, see the published article "AI Agent Orchestration Patterns for Production Systems".
LLM-assisted review works best when it complements human judgment rather than replaces it. A model can scan hundreds of lines for common anti-patterns, inconsistent formatting, or missing input validation in seconds, freeing human reviewers to focus on architectural decisions, business logic correctness, and domain-specific concerns. However, models can also hallucinate API usage, miss subtle race conditions, or overlook project-specific context that a human reviewer would catch immediately. This template is designed to guide the model toward structured, verifiable output while making clear where human oversight remains essential.
Prompt Template Overview
This template guides an LLM to act as a senior code reviewer. It accepts named variables that customize the review for the target language, project conventions, and focus areas. The prompt instructs the model to analyze submitted code, categorize findings by severity, suggest concrete improvements, and identify security concerns. It does not execute code or access external systems; it only processes the code and instructions provided in the variables.
The template is organized around seven review sections: summary, correctness, style and conventions, security, maintainability, recommended changes, and questions for the author. Each section has a defined purpose so that the model's output is predictable and easy to integrate into a review workflow. If no issues are found in a category, the model is instructed to state that explicitly rather than inventing problems.
Variables
The following variables are referenced in promptText and should be supplied before use:
language: The programming language of the code under review (e.g., Python, TypeScript, Go).projectConventions: Project-specific coding conventions, such as indentation style, naming rules, or forbidden patterns.focusAreas: The review dimensions to emphasize, such as performance, security, error handling, or test coverage.codeSnippet: The source code to review, provided as a fenced code block.prContext: Optional context about the pull request, such as the feature being added or the bug being fixed.
Each variable maps directly to a placeholder in promptText. All five variables are used in every review invocation; if a variable has no meaningful value, supply an empty string or "None specified" rather than omitting it, so the model's behavior remains consistent.
Prompt Text
You are a senior code reviewer with expertise in {{language}}. Review the following code snippet according to the project conventions and focus areas provided.
Project Conventions:
{{projectConventions}}
Focus Areas:
{{focusAreas}}
Pull Request Context:
{{prContext}}
Code to Review:
```{{language}}
{{codeSnippet}}
Provide your review in the following sections:
- Summary: A brief one-paragraph assessment of the overall code quality and any major concerns.
- Correctness: Issues related to logic errors, edge cases, type safety, or runtime exceptions.
- Style and Conventions: Violations of the stated project conventions and suggestions for idiomatic {{language}}.
- Security: Potential security issues such as injection vulnerabilities, unsafe deserialization, hardcoded secrets, or insufficient input validation.
- Maintainability: Code that is difficult to read, test, or modify, with refactoring suggestions.
- Recommended Changes: A prioritized list of concrete changes, each with a before/after code example where helpful.
- Questions for the Author: Open questions that require the author's domain knowledge to resolve.
If no issues are found in a category, state that explicitly rather than inventing problems.
### Usage and Worked Example
To use this template, substitute each variable with values appropriate for your review. For example:
- `language`: Python
- `projectConventions`: "Follow PEP 8. Use type hints on all public functions. Prefer list comprehensions over map/filter."
- `focusAreas`: "Error handling, input validation, testability"
- `prContext`: "Adds a new endpoint for user registration in the authentication service."
- `codeSnippet`: The Python function to review, provided inside a fenced code block.
An example review request might look like:
You are a senior code reviewer with expertise in Python. Review the following code snippet according to the project conventions and focus areas provided.
Project Conventions: Follow PEP 8. Use type hints on all public functions. Prefer list comprehensions over map/filter.
Focus Areas: Error handling, input validation, testability
Pull Request Context: Adds a new endpoint for user registration in the authentication service.
Code to Review:
def register_user(email, password):
user = User.create(email, password)
db.session.add(user)
db.session.commit()
return user
Provide your review in the following sections: ...
The model would then produce a structured review identifying, for instance, that passwords should be hashed before storage, that email input should be validated, and that database errors should be handled with try/except blocks. Each finding would appear under the appropriate section header, making it easy for a human reviewer to triage and act on the output.
## Limitations
This prompt template is a guide, not a replacement for human review. LLMs can miss subtle logic errors, hallucinate API usage, or overlook project-specific context that a human reviewer would catch. Always treat model output as a suggestion to verify, not as authoritative. Do not submit code containing secrets, API keys, or personally identifiable information to any model unless your organization has reviewed and approved that data flow. The template does not enforce a permission manifest; operational access controls must be implemented separately by your team. Model output should never be merged directly into a codebase without human review and testing.
## Selection Checklist
Before using this template in a team workflow, confirm the following:
- The model being used supports the context length needed for your typical code snippets.
- Your organization has approved submitting code snippets to the chosen model provider.
- Reviewers are trained to treat model output as advisory, not authoritative.
- A human reviewer signs off on all model-suggested changes before they are merged.
- The variables are kept up to date as project conventions evolve.
## Conclusion
LLM-assisted code review can improve review consistency and catch common issues early, but it works best when integrated into a human-led review process. Use this template as a starting point, adapt the variables to your team's conventions, and always review the model's output critically before acting on it. The goal is not to replace human judgment but to make it more efficient by surfacing likely issues earlier in the development cycle.
Prompt template
You are a senior code reviewer with expertise in {{language}}. Review the following code snippet according to the project conventions and focus areas provided.
Project Conventions:
{{projectConventions}}
Focus Areas:
{{focusAreas}}
Pull Request Context:
{{prContext}}
Code to Review:
```{{language}}
{{codeSnippet}}
```
Provide your review in the following sections:
1. **Summary**: A brief one-paragraph assessment of the overall code quality and any major concerns.
2. **Correctness**: Issues related to logic errors, edge cases, type safety, or runtime exceptions.
3. **Style and Conventions**: Violations of the stated project conventions and suggestions for idiomatic {{language}}.
4. **Security**: Potential security issues such as injection vulnerabilities, unsafe deserialization, hardcoded secrets, or insufficient input validation.
5. **Maintainability**: Code that is difficult to read, test, or modify, with refactoring suggestions.
6. **Recommended Changes**: A prioritized list of concrete changes, each with a before/after code example where helpful.
7. **Questions for the Author**: Open questions that require the author's domain knowledge to resolve.
If no issues are found in a category, state that explicitly rather than inventing problems.