Code Review in AI
From the AI Prompting cheat sheet ยท Code Generation & Technical ยท verified Jul 2026
Code Review
Analyze code for issues and improvements
javascript
NAME: Code Review Analysis
PURPOSE: Get comprehensive code review with actionable feedback
TEMPLATE:
Please review this code:
```[LANGUAGE]
[CODE TO REVIEW]
```
Analyze for:
1. **Bugs & Logic Errors**: Identify any potential bugs
2. **Performance**: Suggest optimization opportunities
3. **Security**: Highlight security vulnerabilities
4. **Best Practices**: Check against [LANGUAGE] conventions
5. **Maintainability**: Assess readability and structure
Provide:
- Severity level for each issue (Critical/High/Medium/Low)
- Specific line numbers where applicable
- Fixed code examples for critical issues
- Overall code quality score (1-10)
EXAMPLE:
Please review this code:
```javascript
function getUserData(userId) {
let user = database.query("SELECT * FROM users WHERE id = " + userId);
if (user != null) {
return {
name: user.name,
email: user.email,
password: user.password
}
}
}
```
Analyze for:
1. **Bugs & Logic Errors**: Identify any potential bugs
2. **Performance**: Suggest optimization opportunities
3. **Security**: Highlight security vulnerabilities
4. **Best Practices**: Check against JavaScript conventions
5. **Maintainability**: Assess readability and structure
OUTPUT:
## Code Review Results
**Overall Score: 3/10** - Critical security issues and poor practices
### ๐ด Critical Issues
1. **SQL Injection Vulnerability** (Line 2)
- Severity: CRITICAL
- Issue: Direct string concatenation in SQL query
- Fix: Use parameterized queries
```javascript
const user = database.query("SELECT * FROM users WHERE id = ?", [userId]);
```
2. **Password Exposure** (Line 6)
- Severity: CRITICAL
- Issue: Returning password in response
- Fix: Never return passwords
```javascript
return {
name: user.name,
email: user.email
// Never include password
}
```
### โ ๏ธ High Priority Issues
3. **No Async Handling** (Line 2)
- Severity: HIGH
- Issue: Database queries should be asynchronous
- Fix: Use async/await
4. **Weak Null Check** (Line 3)
- Severity: MEDIUM
- Issue: != allows undefined to pass
- Fix: Use strict equality
### ๐ Recommendations
```javascript
async function getUserData(userId) {
// Validate input
if (!userId || typeof userId !== 'number') {
throw new Error('Invalid user ID');
}
try {
// Use parameterized query
const user = await database.query(
"SELECT id, name, email FROM users WHERE id = ?",
[userId]
);
if (!user) {
return null;
}
return {
id: user.id,
name: user.name,
email: user.email
};
} catch (error) {
console.error('Database error:', error);
throw new Error('Failed to fetch user data');
}
}
```๐ Request specific analysis categories
โ ๏ธ Ask for severity levels to prioritize fixes
๐ก Request fixed code examples for learning