AI Prompts Documentation
Documents three AI prompts for code review, follow-up questions, and diff analysis using Llama 3.3 70B.
What this file does
Documents three AI prompts for code review, follow-up questions, and diff analysis using Llama 3.3 70B.
When to use it
- Building an AI-powered code review assistant
- Designing structured prompts for LLM-based code analysis
- Implementing diff review with file-by-file feedback
- Creating a system that returns JSON from LLM responses
Assumes this stack
AI Prompts Documentation
This document contains all AI prompts used in the AI Code Review Assistant project. All prompts are designed to work with Llama 3.3 70B via Cloudflare Workers AI.
Try it live: https://cf-ai-code-review-frontend.pages.dev
📋 Table of Contents
Code Review Prompt
Purpose
Analyzes submitted code and provides comprehensive feedback across multiple dimensions: security, performance, code quality, best practices, and potential bugs.
Location
src/worker/llm.ts - reviewCode() function
System Prompt
You are an expert code reviewer with deep knowledge of software engineering best practices, security, and performance optimization. Your role is to provide constructive, actionable feedback on code submissions.
Review Criteria:
1. Security vulnerabilities (SQL injection, XSS, CSRF, authentication issues, etc.)
2. Performance issues (inefficient algorithms, memory leaks, unnecessary computations)
3. Code quality (readability, maintainability, complexity)
4. Best practices (DRY, SOLID principles, design patterns)
5. Potential bugs and edge cases
Response Format: You MUST respond with valid JSON only, no markdown, no code blocks. Use this exact structure:
{
"score": <number 1-10>,
"summary": "<brief summary>",
"categories": {
"security": [{"severity": "critical|warning|info", "title": "...", "description": "...", "line": <optional>, "suggestion": "<optional>", "codeExample": "<optional>"}],
"performance": [...],
"quality": [...],
"bestPractices": [...],
"bugs": [...]
}
}
User Prompt Template
Review the following {language} code:
```{language}
{code}
{previousContext ? Previous review context:\n${previousContext}\n\n : ''}Provide a comprehensive code review. Focus on actionable feedback.
### Parameters
- **code** (string): The code to be reviewed
- **language** (string): Programming language (e.g., "javascript", "python", "typescript")
- **previousContext** (string, optional): Context from previous reviews in the same session
### Model Configuration
- **Model**: `@cf/meta/llama-3.3-70b-instruct-fp8-fast`
- **Max Tokens**: 2000
- **Temperature**: 0.3 (lower for more consistent, focused reviews)
### Expected Response Format
```json
{
"score": 4,
"summary": "Code contains critical security vulnerabilities including SQL injection.",
"categories": {
"security": [
{
"severity": "critical",
"title": "SQL Injection Vulnerability",
"description": "The code directly interpolates user input into SQL query without sanitization.",
"line": 2,
"suggestion": "Use parameterized queries or prepared statements.",
"codeExample": "const query = 'SELECT * FROM users WHERE username = ?';\nreturn db.query(query, [username]);"
}
],
"performance": [],
"quality": [],
"bestPractices": [],
"bugs": []
}
}
Prompt Engineering Decisions
- Structured JSON Output: Ensures consistent parsing and reliable frontend integration
- Explicit Format Instructions: "MUST respond with valid JSON only" prevents markdown formatting issues
- Categorized Feedback: Organizes feedback into actionable categories
- Severity Levels: Helps prioritize issues (critical > warning > info)
- Code Examples: Provides concrete suggestions for fixes
- Context Awareness: Includes previous review context for iterative improvements
Follow-up Question Prompt
Purpose
Answers developer questions about code reviews, providing clarifications and deeper explanations.
Location
src/worker/llm.ts - answerFollowUp() function
System Prompt
You are an expert code reviewer helping a developer understand code review feedback. Provide clear, detailed explanations.
User Prompt Template
The developer asked: "{question}"
Original code ({language}):
```{language}
{code}
Previous review summary: {JSON.stringify(review, null, 2)}
Please provide a helpful answer to their question.
### Parameters
- **question** (string): The developer's question
- **code** (string): The original code that was reviewed
- **language** (string): Programming language
- **review** (ReviewResult): The complete review result object
### Model Configuration
- **Model**: `@cf/meta/llama-3.3-70b-instruct-fp8-fast`
- **Max Tokens**: 1000
- **Temperature**: 0.5 (slightly higher for more natural, conversational responses)
### Expected Response Format
Free-form text response explaining the question in detail, referencing the original code and review.
### Prompt Engineering Decisions
1. **Context-Rich**: Includes full review and original code for comprehensive answers
2. **Conversational Tone**: System prompt emphasizes helpfulness
3. **Structured Input**: Provides all necessary context for accurate responses
---
## Diff Review Prompt
### Purpose
Analyzes code diffs (unified diff format) and provides file-by-file feedback focusing on security, bugs, code quality, best practices, and performance issues in the changed lines.
### Location
`src/worker/llm-diff.ts` - `reviewDiff()` function
### System Prompt
You are a senior code reviewer analyzing a code diff. Review the changes and provide feedback focusing on:
- Security: Look for security vulnerabilities, unsafe patterns, or exposure of sensitive data
- Bugs: Identify potential bugs, logic errors, or edge cases not handled
- Code Quality: Check for code smells, readability issues, or maintainability concerns
- Best Practices: Ensure adherence to coding standards and best practices
- Performance: Identify potential performance issues in the changes
Focus ONLY on the changed lines (additions and modifications), not the entire codebase context.
Respond with a JSON object in this exact format: { "score": <number 1-10>, "summary": "<brief overall assessment>", "fileReviews": [ { "path": "<file path>", "issues": [ { "severity": "<critical|warning|info>", "title": "<short title>", "description": "<detailed description>", "line": <line number if applicable, null otherwise>, "suggestion": "<how to fix>", "codeExample": "<optional fixed code>" } ], "suggestions": ["<improvement suggestion>"] } ], "overallSuggestions": ["<general improvement>"] }
Important:
- Score 8-10: Excellent changes, minimal or no issues
- Score 6-7: Good changes with minor issues
- Score 4-5: Changes need improvement
- Score 1-3: Critical issues that should be addressed before merging
- Focus on actionable feedback
- Be constructive and specific
### User Prompt Template
Here is the diff to review:
{diffSummary}
{diffContent}
{additionalContext ? \nAdditional context: ${additionalContext} : ''}
Please review these changes and provide your feedback in the specified JSON format.
### Parameters
- **parsedDiff** (ParsedDiff): Parsed diff object containing files, hunks, and line changes
- **additionalContext** (string, optional): Additional context about the changes (e.g., "This is a security fix for user authentication")
- **config** (AppConfig): Configuration including model settings
### Model Configuration
- **Model**: `@cf/meta/llama-3.3-70b-instruct-fp8-fast`
- **Max Tokens**: 2000 (inherited from config)
- **Temperature**: 0.3 (inherited from config, lower for more consistent reviews)
### Expected Response Format
```json
{
"score": 7,
"summary": "Good changes overall with minor security concerns.",
"fileReviews": [
{
"path": "src/auth.js",
"issues": [
{
"severity": "warning",
"title": "Potential SQL Injection",
"description": "User input is directly concatenated into SQL query.",
"line": 15,
"suggestion": "Use parameterized queries or prepared statements.",
"codeExample": "const query = 'SELECT * FROM users WHERE id = ?';\nreturn db.query(query, [userId]);"
}
],
"suggestions": ["Add input validation", "Consider using an ORM"]
}
],
"overallSuggestions": ["Add unit tests for new authentication logic"]
}
Prompt Engineering Decisions
- Diff-Focused: Explicitly instructs to focus only on changed lines, not the entire codebase
- File-by-File Structure: Organizes feedback by file path for better navigation
- Line-Specific Feedback: Includes line numbers when applicable for precise issue location
- Context Support: Allows additional context to be provided for better understanding
- Score Guidelines: Clear scoring criteria helps maintain consistency
- Actionable Suggestions: Emphasizes constructive, specific feedback with code examples
Implementation Notes
- All prompts are designed for Llama 3.3 70B via Cloudflare Workers AI
- Response parsing includes fallbacks for non-JSON responses
- Temperature and token settings are tuned for this specific use case
- The nested response structure
{"response": {...}}is handled in the parsing logic - Diff review uses the same model configuration as code review for consistency
What's inside
3 prompt sections with system prompts, user templates, parameters, and engineering decisions.
Change this for your project
- Replace
@cf/meta/llama-3.3-70b-instruct-fp8-fastwith your model ID - Replace
https://cf-ai-code-review-frontend.pages.devwith your live URL - Replace
src/worker/llm.tsandsrc/worker/llm-diff.tswith your file paths
Where it goes
A prompt collection. Copy the individual prompts you need rather than the whole file.
Worth borrowing
- Use a system prompt that enforces JSON-only output for reliable parsing
- Include severity levels and code examples in feedback categories
- Provide optional context fields to support iterative review sessions
Related Documents
starProject
Lists 120+ starred open-source projects across AI, DevOps, Flutter, and web development for discovery and inspiration.
midjourney-expert
Serves as a reference for Midjourney V7/Niji 7 prompting, covering parameters, reference systems, editing tools, and moderation workarounds.
🎣 Hooks & Headlines Generator
Generates 20, 30 headline variations across 10 proven formulas, with psychological reasoning and platform-specific best practices.
Daily Agent Tasks Framework
Gives you a daily structure for assigning strategic work to Claude and development work to Codex, organized by project priority and current sprint.