How to Use ChatGPT for Code Reviews ?
You know that feeling when you submit a pull request and it sits there for three days? Or when you’re reviewing someone else’s code and feel like you’re missing something obvious?
I’ve been there. We all have.
The good news? ChatGPT can actually help with code reviews. Not replace human reviewers, but catch the stuff that makes you go “how did I miss that?”
The Problem With Traditional Code Reviews
Let’s be honest. Code reviews are broken in most teams.
Senior developers are swamped. Junior developers are afraid to review senior code. Everyone’s rushing to ship features.
The result? Bugs slip through. Code quality suffers. Reviews become a bottleneck instead of a quality gate.
What ChatGPT Actually Does Well
ChatGPT is really good at spotting the same mistakes you make every day. It catches:
- Missing error handling
- Security holes you didn’t think about
- Performance issues hiding in plain sight
- Code that works but looks terrible
It’s like having a really pedantic colleague who never gets tired of pointing out problems.
The Magic Prompt Formula
Here’s the prompt I use for 90% of my code reviews:
Review this [LANGUAGE] code for bugs, security issues, and readability problems.
Be specific about what's wrong and how to fix it.
[YOUR CODE HERE]
This code [brief explanation of what it does].
That’s it. Simple, direct, gets results.
Real Example: Python Function Gone Wrong
Let’s say you wrote this Python function:
def get_user_data(user_id):
user = db.query(f"SELECT * FROM users WHERE id = {user_id}")
if user:
return user[0]
return None
Looks fine, right? Wrong.
Here’s what ChatGPT will tell you:
Problems:
- SQL injection vulnerability (ouch)
- No error handling for database failures
- Assumes user[0] exists without checking
Better version:
def get_user_data(user_id):
try:
user = db.query("SELECT * FROM users WHERE id = %s", (user_id,))
return user[0] if user else None
except DatabaseError as e:
logger.error(f"Database error: {e}")
return None
This took ChatGPT 10 seconds to catch. It might take a human reviewer 10 minutes.
JavaScript: Async/Await Nightmares
Here’s another common mess:
async function fetchUserData(userId) {
const response = await fetch(`/api/users/${userId}`);
const data = await response.json();
return data;
}
ChatGPT’s feedback:
- No error handling for failed requests
- No status code checking
- Network errors will crash your app
Fixed version:
async function fetchUserData(userId) {
try {
const response = await fetch(`/api/users/${userId}`);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return await response.json();
} catch (error) {
console.error('Failed to fetch user data:', error);
throw error;
}
}
When ChatGPT Gets It Wrong
ChatGPT isn’t perfect. It makes mistakes, especially with:
Business Logic It doesn’t understand your specific requirements. If your code needs to work a certain way for business reasons, ChatGPT might suggest “improvements” that break things.
Performance Context ChatGPT might suggest optimizations that don’t matter for your use case. If you’re processing 10 records, you don’t need to optimize for 10 million.
Team Standards Your team might have specific coding conventions. ChatGPT follows general best practices, not your team’s style guide.
Prompts That Actually Work
For Security Reviews:
Check this code for security vulnerabilities. Focus on:
- SQL injection
- XSS attacks
- Authentication bypasses
- Data validation issues
[CODE]
For Performance Reviews:
Review this code for performance issues. Look for:
- Inefficient loops
- Database query problems
- Memory leaks
- Unnecessary computations
[CODE]
For Readability:
Make this code more readable and maintainable. Suggest:
- Better variable names
- Clearer logic flow
- Missing documentation
- Code organization improvements
[CODE]
Java Spring Boot Example
Here’s a controller that looks okay but has problems:
@RestController
public class UserController {
@GetMapping("/users/{id}")
public User getUser(@PathVariable String id) {
return userService.findById(id);
}
}
ChatGPT catches:
- Missing error handling for non-existent users
- No input validation
- Should return ResponseEntity for proper HTTP responses
Improved version:
@RestController
public class UserController {
@GetMapping("/users/{id}")
public ResponseEntity<User> getUser(@PathVariable String id) {
if (id == null || id.trim().isEmpty()) {
return ResponseEntity.badRequest().build();
}
User user = userService.findById(id);
if (user == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(user);
}
}
My Workflow: ChatGPT + Human Review
Here’s what actually works in practice:
- Write your code
- Run it through ChatGPT first – catch obvious issues
- Fix the problems that make sense
- Submit for human review – focus on architecture and business logic
- Iterate based on human feedback
This cuts review time in half and catches more bugs.
Common Mistakes Developers Make
Mistake 1: Trusting ChatGPT Blindly Always test the suggestions. ChatGPT can be wrong.
Mistake 2: Not Giving Context “Review this code” gets generic advice. “Review this authentication middleware for security issues” gets specific help.
Mistake 3: Ignoring Team Standards If your team uses specific patterns, tell ChatGPT about them.
Mistake 4: Over-Engineering Just because ChatGPT suggests 20 improvements doesn’t mean you need all of them.
Quick Wins You Can Try Today
Before your next commit:
- Copy your changed files
- Paste them into ChatGPT with the magic prompt
- Fix the obvious issues
- Submit for human review
For code reviews:
- Use ChatGPT to do a first pass
- Focus human reviewers on architecture and business logic
- Speed up the whole process
For learning: Ask ChatGPT to explain why something is wrong. You’ll learn patterns to avoid.
The Bottom Line
ChatGPT won’t replace human code reviewers. But it’s really good at catching the stupid mistakes we all make.
Use it as your first line of defense. Let it catch the obvious stuff so humans can focus on the important things like architecture, business logic, and mentoring.
Your code will be better. Your reviews will be faster. Your team will be happier.
Just remember: ChatGPT is a tool, not a replacement for thinking. Use it wisely, and it’ll make you a better developer.
Happy Learning 🙂