Getting Useful Code Reviews from ChatGPT Without Generic Feedback
You paste your function into ChatGPT, ask it to review the code, and get back three paragraphs about error handling, naming conventions, and "consider adding comments." It sounds helpful until you realise the same response would fit any Python function written in the last decade. The problem isn't ChatGPT β it's the prompt.
Getting a sharp review requires you to give ChatGPT the same context you'd give a colleague: what this code is supposed to do, what constraints you're working under, and what specifically you're worried about.
What you'll learn
- Why vague prompts produce vague reviews β and how to fix them
- How to set up context so ChatGPT understands your environment
- Role-playing techniques that shift the model into a critical mindset
- How to ask targeted questions that surface real bugs
- A reusable prompt template you can drop into any review session
Prerequisites
This guide assumes you have access to ChatGPT (GPT-4 or later gives noticeably better reviews than GPT-3.5). You don't need any special plugins or API access β everything here works in the standard chat interface or via the API if you're scripting reviews into a workflow.
Why ChatGPT gives generic feedback by default
Language models predict the most likely helpful response given your input. When you ask "review my code" with no other context, the most likely helpful response is a general checklist because that's what fits the widest range of possible code. ChatGPT doesn't know if you're writing a one-off migration script or a function that runs a thousand times a second in production.
It also doesn't know your team's conventions, the framework version you're targeting, or whether you've already thought about the obvious edge cases. Without that information, it defaults to surface-level observations that are technically correct but don't move the needle for you.
The fix is straightforward: give it the context it needs upfront, and ask a specific question instead of an open-ended one.
Set the context before you paste any code
Before ChatGPT sees a single line of your code, tell it what it's looking at. A short context block at the top of your message does more work than any clever phrasing in the request itself.
Here's a template you can adapt:
Context:
- Language: Python 3.11
- Framework: FastAPI, async handlers
- This function processes incoming webhook payloads from Stripe.
It runs on every payment event, so it can be called thousands
of times per hour during peak load.
- We use Pydantic v2 for validation.
- The team style guide requires explicit return types on all public functions.
Code to review:
[paste your code here]
Question: Are there any race conditions or error-handling gaps that
could cause us to silently miss a payment event?
Notice what this does. It tells ChatGPT the language version, the runtime constraints, the libraries in use, and the team conventions β and it ends with a single, concrete question. That last part is critical. An open question like "what do you think?" invites a broad answer. A focused question about race conditions in a high-throughput async handler invites a precise one.
Tell ChatGPT what role to play
Role-prompting isn't a magic trick, but it does shift the model's response distribution in useful ways. Asking ChatGPT to act as a senior engineer focused on a specific quality attribute tends to surface feedback that's more pointed than a neutral review.
Compare these two openers:
β "Review this function for me."
β
"Act as a senior backend engineer doing a security-focused code
review before this ships to production. Be direct. Flag anything
that could cause a data leak or allow unauthorized access.
Don't pad the response with general best practices I already know."
The second prompt sets a mindset, a priority, and a constraint (skip the padding). That last instruction matters more than it looks. Telling ChatGPT not to include generic advice actively suppresses the boilerplate you don't need.
Other role framings that work well:
- Performance reviewer: "Focus only on algorithmic complexity and memory usage. Assume the code is functionally correct."
- New team member: "Read this code as someone unfamiliar with the codebase. Point out anything that is confusing or underdocumented."
- Skeptical QA engineer: "Your job is to find cases where this function returns the wrong result or throws unexpectedly. Assume the happy path works."
Ask for one thing at a time
A common mistake is asking ChatGPT to review everything at once: correctness, style, performance, security, and readability in one shot. You'll get something back for each category, but it'll be shallow across the board because the model has to spread its attention.
Run separate passes instead. It takes an extra minute but the results are measurably sharper:
- First pass: correctness and edge cases
- Second pass: performance bottlenecks
- Third pass: readability and naming
- Fourth pass: security implications (if relevant)
For most functions, you only need the first one or two passes. Only run all four for code that's going into a critical path or a public-facing surface.
This is the same discipline that makes human code reviews effective. A reviewer asked to look at "everything" will miss things that a reviewer asked to look specifically at error handling will catch.
Use a checklist prompt for structured reviews
If you want a comprehensive review in one pass β useful for a pull request rather than a single function β give ChatGPT an explicit checklist to work through. This forces it to address each dimension separately rather than blending them into a paragraph of generalities.
Review the code below. Go through each item in this checklist
in order, and for each one either confirm it looks fine or
explain the specific problem and suggest a fix:
1. Input validation: are all inputs sanitized and validated?
2. Error handling: are all exceptions caught appropriately?
Does any error path silently swallow the error?
3. Edge cases: null/empty inputs, zero values, very large inputs.
4. Performance: any obvious O(nΒ²) traps or unnecessary I/O in a loop?
5. Naming: are functions and variables named so their intent is clear
without reading the body?
Code:
[paste your code here]
The checklist format has an additional benefit: it makes the response easy to scan. You can jump straight to the section that matters most for your current concern.
Give ChatGPT a failing scenario to probe
One of the most underused techniques is giving ChatGPT a concrete scenario and asking whether the code handles it correctly. This is closer to asking a colleague "what happens if the database is down when this runs?" than it is to asking for a generic review.
Here is the code: [paste code]
Walk me through what happens, step by step, if:
- The external API call on line 14 times out after 30 seconds.
- The retry logic runs three times and all three fail.
- A second request for the same user arrives while the first
retry is still in progress.
Does the code handle this correctly? If not, what breaks?
This forces ChatGPT to trace the execution path rather than pattern-match against common review comments. You'll surface race conditions, missing timeout handling, and incorrect retry logic far more reliably this way than with an open-ended review.
This approach pairs well with the techniques in debugging ChatGPT code suggestions that silently break edge cases, where the focus is on catching problems the model introduces rather than the ones it surfaces.
Common pitfalls when prompting for code reviews
Pasting too much code at once
Context windows are large now, but review quality degrades as the amount of code grows. A 500-line file will get a worse review than a 50-line function. Break large reviews into logical units: review the data access layer separately from the business logic, for example.
Not providing the surrounding interface
If your function calls three helpers, ChatGPT can't tell whether those helpers are correct. Either paste their signatures with a one-line description of what each does, or note explicitly that you want to assume they behave as documented. Otherwise you'll get feedback that misunderstands what the code is doing.
Accepting the first response without pushing back
ChatGPT's first response is rarely its best. If something seems off, or the feedback feels too surface-level, push back: "That suggestion about using a try/except block β I already have one on line 8. Look again and tell me if there's a gap specifically in the retry path." Follow-up messages consistently produce sharper analysis than a single shot.
Asking it to praise as well as criticize
"What's good and what's bad?" invites a balanced response where the model feels obligated to find positives even when you want pure criticism. If you want a tough review, tell it: "Don't tell me what's working well. Focus only on problems."
Forgetting to anchor suggestions in your constraints
ChatGPT may suggest refactoring to a pattern your team has deliberately chosen not to use, or recommend a library you can't add as a dependency. Include your constraints upfront. "We can't introduce new dependencies" or "this needs to be compatible with Python 3.9" will filter out suggestions that would waste your time.
If you use GitHub Copilot in your editor as well as ChatGPT for reviews, it's worth reading about fixing GitHub Copilot suggestions that miss your codebase context β many of the same context-setting principles apply there too.
For a broader look at building AI into your daily engineering work beyond just code review, the practical workflow guide for Claude Code covers how to integrate AI review into a repeatable development loop.
Wrapping up
Getting useful code reviews from ChatGPT comes down to treating it like a colleague who is extremely capable but has zero context about your project unless you provide it. Generic prompts produce generic feedback. Specific, constrained prompts produce specific, actionable feedback.
Here are four concrete things you can do right now:
- Build a context block template for your main project β language, framework version, key libraries, team conventions β and paste it at the top of every review session.
- Pick one quality dimension per review pass rather than asking for everything at once. Start with correctness and edge cases.
- Write one failing scenario for the next function you review and ask ChatGPT to trace the execution path through it.
- Add "don't pad the response with general best practices" to your standard review prompt and notice the difference in response quality immediately.
- Push back on the first response at least once per session. Follow-up questions consistently surface issues that the initial response misses.
Frequently Asked Questions
How do I stop ChatGPT from giving the same generic code review every time?
The most effective fix is to include explicit context before your code: the language version, framework, key constraints, and team conventions. Then end your prompt with a single focused question rather than an open-ended "review this" request, which forces ChatGPT to engage with your specific situation instead of defaulting to a general checklist.
Can ChatGPT catch real bugs in my code or just style issues?
ChatGPT can catch real logic bugs, edge case gaps, and error-handling problems if you prompt it correctly. Asking it to trace a specific failing scenario step by step β such as what happens when an API call times out and all retries fail β is far more effective at surfacing real bugs than asking for a general review.
Is it better to paste a whole file or individual functions for a ChatGPT code review?
Individual functions or logical units consistently get better reviews than large files. Review quality degrades as the amount of code grows, so break large submissions into the data access layer, business logic, and utility helpers and review each separately.
What's the best way to give ChatGPT role instructions for a code review?
Frame the role around a specific quality attribute you care about, such as "act as a senior backend engineer doing a security-focused review before this ships to production." Adding an instruction like "don't pad the response with general best practices" actively suppresses boilerplate and keeps the feedback focused on what matters to you.
How many review passes should I run with ChatGPT for a critical function?
For critical production code, two to four passes is a reasonable approach: one for correctness and edge cases, one for performance, one for security if the function handles user data, and optionally one for readability. For most everyday functions, one or two targeted passes is enough and takes only a few minutes.
π€ Share this article
Sign in to saveRelated Articles
Comments (0)
No comments yet. Be the first!