Back to cookbook

ChatGPT Prompt to Review Code for Bugs, Style, and Security Issues

8 views Published

Make this prompt yours

Share

This code review prompt turns ChatGPT, Claude, or Gemini into a thorough reviewer that checks a diff or file for bugs, style problems, and security issues before it reaches a human reviewer or gets merged. It's built for developers, tech leads, and teams who want a consistent first pass on pull requests, especially when review bandwidth is tight or a change touches unfamiliar code.

Instead of a vague "check my code" request, the prompt sets explicit review categories (correctness, security, readability, performance, test coverage) and asks the model to cite specific line numbers or code snippets for each finding, rather than giving general praise or vague warnings. This makes the output something a developer can act on directly, and it keeps the model from skipping categories it finds less interesting.

Because review quality depends heavily on how the instructions are structured, running this template through the Prompt Optimizer in Coding mode before using it on a large or unusual codebase can tighten the constraints and catch ambiguity that would otherwise lead to shallow feedback.

Prompt template

Make this prompt yours

prompt-template
323 tokens
You are an experienced software engineer performing a code review. Review the following code change for issues a careful human reviewer would catch before approving a pull request. Context: - Language/framework: [LANGUAGE AND FRAMEWORK] - Style guide or conventions to follow: [STYLE GUIDE, e.g. PEP 8, Airbnb JS, or "none specified"] - Purpose of this change: [ONE-SENTENCE DESCRIPTION OF WHAT THE CHANGE DOES] Code to review: [PASTE DIFF OR FULL FILE CONTENTS HERE] Review the code across these categories, in this order: 1. Correctness — logic errors, edge cases, off-by-one errors, null/undefined handling 2. Security — injection risks, unvalidated input, broken access control, exposed secrets 3. Readability — unclear naming, missing comments where logic is non-obvious, overly complex functions 4. Performance — unnecessary loops, redundant computation, inefficient queries 5. Test coverage — missing tests for new logic or edge cases Constraints: - Cite the specific line number or exact code snippet for every finding - Label each finding as Blocking, Should-fix, or Nitpick - Do not rewrite the code — describe the issue and suggest a fix in words - If a category has no issues, state that explicitly rather than skipping it Output format: For each category, list findings as: [Severity] Line/snippet: [code reference] Issue: [what's wrong] Suggested fix: [brief description] End with a one-line overall verdict: Approve, Approve with comments, or Request changes.

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
96 tokens
Language/framework: Python, Flask Style guide: PEP 8 Purpose: Add an endpoint that lets users update their email address Code: @app.route('/update-email', methods=['POST']) def update_email(): user_id = request.form['user_id'] new_email = request.form['email'] query = "UPDATE users SET email = '" + new_email + "' WHERE id = " + user_id db.execute(query) return 'OK'

When to use it

  • Before opening a pull request, to catch obvious bugs and style issues the author missed
  • As a first-pass reviewer on PRs from junior developers or contractors before a senior engineer reviews them
  • When reviewing unfamiliar code you inherited, such as a legacy module or a teammate's work while they're out
  • When a CI pipeline doesn't run a linter or static analysis tool and you need a quick manual check for common issues

Best practices

  • Paste the actual diff or full file contents, not a description of the change, so the model can cite real line numbers
  • Tell the model the language, framework, and any style guide you follow (e.g. PEP 8, Airbnb JS) so it doesn't flag non-issues
  • Ask for findings ranked by severity (blocking, should-fix, nitpick) so you can triage quickly instead of reading a flat list
  • For security-sensitive code (auth, payments, user input handling), ask the model to specifically check for injection, access control, and data exposure risks rather than relying on a generic pass

Common mistakes

  • Pasting only the changed lines without surrounding context, which makes it impossible for the model to spot issues caused by how the change interacts with the rest of the function
  • Not specifying the language or framework, leading to generic feedback that doesn't account for framework-specific conventions
  • Treating the review as final instead of verification — the model can miss issues that depend on runtime behavior or data it can't see
  • Asking for a review and a rewrite in the same prompt, which often produces a rewritten version that silently fixes issues instead of explaining them, so you don't learn what was wrong

FAQs

What's the best ChatGPT prompt for reviewing a pull request?

The most effective prompts give the model explicit review categories (correctness, security, readability, performance, test coverage), ask it to cite specific line numbers for each finding, and request a severity label for every issue. A vague "review this code" request tends to produce generic praise instead of actionable feedback, so structure matters more than wording.

Can AI code review catch security vulnerabilities like SQL injection?

Yes, for common patterns like string-concatenated SQL queries, unvalidated user input, or missing authorization checks, a model reviewing the actual code can flag these reliably. It's less reliable for vulnerabilities that depend on how the code behaves at runtime or interacts with infrastructure it can't see, so it should supplement rather than replace a security-focused review or scanning tool.

Should I use ChatGPT or Claude for code review?

Both can perform structured code review well when given the same category-based prompt; the meaningful difference tends to be context window size for reviewing large diffs or multi-file changes rather than which model is "better" at spotting bugs. Test the same prompt on a known problematic snippet in each to see which catches more of your team's common issues.

How do I get consistent code review feedback across different PRs?

Reuse the same structured prompt template for every review rather than writing a new ad hoc request each time, and keep the category list and severity labels identical. This is also what makes AI review output comparable across PRs and easier for a team to standardize on.

Which Cuelara tool can help me strengthen this code review prompt before using it on a large codebase?

Prompt Optimizer — its Coding mode is built to tighten vague or loosely structured instructions into the kind of explicit, category-based prompt that produces specific, line-cited findings instead of generic feedback.

Found this prompt useful? Share it.

Share

More in Code Generation & Software Engineering

Code Generation & Software Engineering

AI Prompt to Write a GitHub Actions CI/CD Workflow from Plain English

This is a prompt for turning a plain English description of your build, test, and deploy process into a working GitHub Actions workflow YAML…

Role: You are a DevOps engineer writing a GitHub Actions workflow file.

Context:
Project type: [LANGUAGE/FRAMEWORK, e.g. Node.js with npm, Python with Poetry]
Repository structure notes: [e.g. monorepo with /api and /web folders, single app at root]
Runner: [e.g. ubuntu-latest]

Task:
Write a GitHub Actions workflow (.github/workflows/[FILENAME].yml) that does the following, in this order:
1. Trigger on: [TRIGGER EVENTS, e.g. pull_request to main, push of tags matching v*]
2. Job 1 - [JOB NAME, e.g. lint]: [WHAT IT DOES]
3. Job 2 - [JOB NAME, e.g. test]: [WHAT IT DOES], must run only after Job 1 succeeds
4. Job 3 - [JOB NAME, e.g. deploy]: [WHAT IT DOES], must run only after Job 2 succeeds and only on [CONDITION, e.g. tag pushes to main]

Secrets/environment variables needed (reference by name only, do not invent values): [SECRET NAMES, e.g. DEPLOY_TOKEN, AWS_ACCESS_KEY_ID]

Constraints:
- Pin third-party actions to a specific major version (e.g. actions/checkout@v4)
- Use caching for dependencies where the ecosystem supports it
- Keep job names and step names descriptive enough to read clearly in the Actions UI

Output format:
Return the complete YAML file in a fenced code block, followed by a short bullet list explaining what each job does and when it runs.

Make this prompt yours

Code Generation & Software Engineering

AI Prompt to Debug a Failed Vercel Deployment Using Vercel's MCP Server

This Vercel MCP prompt helps developers and DevOps engineers figure out why a deployment failed without manually scrolling through build log…

ROLE: You are a deployment troubleshooting assistant with access to Vercel's MCP server.

CONTEXT:
- Project: [PROJECT_NAME]
- Framework: [FRAMEWORK, e.g. Next.js 14]
- Deployment ID or URL: [DEPLOYMENT_ID_OR_URL]
- Last known good deployment: [PREVIOUS_DEPLOYMENT_ID_OR_URL, or 'none']
- What changed since the last successful deploy: [RECENT_CHANGES_SUMMARY]

TASK:
1. Retrieve the build and runtime logs for the failing deployment.
2. Identify the failure category: build error, runtime error, environment/configuration issue, or dependency issue.
3. Quote the specific log lines that show the root cause.
4. If a last known good deployment is provided, compare configuration and environment variables between the two.
5. Propose a ranked list of likely fixes, most probable first.

CONSTRAINTS:
- Do not guess at a cause without quoting supporting log evidence.
- Flag if critical information (e.g. an environment variable value) is missing rather than assuming it.

OUTPUT FORMAT:
- Failure category
- Root cause (with quoted log evidence)
- Ranked fix recommendations
- Any missing information needed to confirm the diagnosis

Make this prompt yours

Code Generation & Software Engineering

ChatGPT Prompt to Generate a Production-Ready Dockerfile for Your App

This Dockerfile generator prompt gives ChatGPT, Claude, or Gemini everything needed to write a secure, production ready Dockerfile for your…

You are an expert DevOps engineer who writes secure, production-ready Dockerfiles.

Context:
- Application language and version: [LANGUAGE AND VERSION, e.g., Node.js 20]
- Framework: [FRAMEWORK, e.g., Express, Django, Spring Boot]
- Package manager: [PACKAGE MANAGER, e.g., npm, pip, Maven]
- Target deployment platform: [PLATFORM, e.g., AWS ECS, Kubernetes, linux/amd64]
- Special requirements: [e.g., private package registry, native dependencies, health checks]

Task:
Write a production-ready Dockerfile for this application. Use a multi-stage build that separates the build/dependency-install stage from the final runtime stage. The final image should:
1. Use the smallest reasonable base image for the runtime.
2. Run as a non-root user.
3. Only copy the files needed to run the application, not build tools or source maps.
4. Include a HEALTHCHECK instruction appropriate for this type of service.
5. Set any necessary environment variables and expose the correct port.

Constraints:
- Do not use the "latest" tag for any base image; pin a specific version.
- Keep the final image size as small as possible.
- Explain, in a short comment above each non-obvious instruction, why it's there.

Output format:
1. The complete Dockerfile in a single code block.
2. A short bullet list explaining the base image choice and any trade-offs.
3. One suggested .dockerignore entry list for this stack.

Make this prompt yours