Code Review

Get a prioritized code review that covers correctness, security, readability and tests.

code reviewqualitysecurity All models

Prompt

Prompt
Review the {language} code below.

<purpose>
{purpose}
</purpose>

<code>
{code}
</code>

<review_focus>
{review_focus}
Conventions to respect: {team_conventions}
</review_focus>

Review in this order and be specific. Refer to line numbers or function names.
1. Correctness: bugs, edge cases, wrong assumptions, off-by-one errors, unhandled null or empty values.
2. Security: input validation, injection risks, unsafe use of data, secrets in code.
3. Error handling and reliability: what happens when something fails.
4. Readability and maintainability: naming, structure, duplication.
5. Tests: what is missing, and the three most valuable test cases to add.

For each issue, give: severity (high, medium, low), what is wrong, why it matters, and a concrete fix with a short code example. Sort the issues from most to least severe.

Do not invent problems to look thorough. If something looks fine, say so in one line. If you need to see other files to be sure about an issue, tell me which ones instead of guessing. End with a one-paragraph summary: would you approve this change, and what must change first?

Variables

VariableWhat to put inExample
{language}The programming language and framework.TypeScript with Node.js
{code}The code to review.Paste the function, file or diff here.
{purpose}What the code is supposed to do.Validate an uploaded CSV and import valid rows into the database.
{review_focus}What you care about most.Correctness, error handling and security.
{team_conventions}Style rules or conventions to respect. Write "none" if there are none.Functions under 40 lines; no default exports.

How to use

  1. Paste the code together with a one-sentence purpose. Without the purpose, the review can only judge style.
  2. Fix high-severity issues first, then run your tests. Do not apply suggested fixes without understanding them.
  3. If the code is large, review it in parts, such as one file or one function at a time.

Example result

Illustrative example

High: in importRows, an empty CSV leads to rows[0] being undefined, which throws before any validation runs. Fix: return early when rows.length === 0. Medium: file contents are written to the database without trimming or length checks. Add per-field validation before insert. Summary: do not approve yet. Fix the empty-file crash and add validation first.

Model notes

Claude

Claude tends to explain trade-offs in reviews. For large changes, paste the diff and the files it touches rather than everything.

ChatGPT

Works as-is. If your plan supports file upload, you can upload the file instead of pasting it.

Gemini

If you can attach files or a repository export, name the files in the review focus so comments refer to the right place.

Grok

State the language and framework clearly. Ask it to flag any suggestion that depends on a library version, and check it yourself.

Refine the result

  • Prompt
    Rewrite only the high-severity fixes as a patch I can apply.
  • Prompt
    Which of your suggestions are matters of taste rather than correctness?
  • Prompt
    Write the three test cases as runnable code.

Related templates

  • Debug an Error

    Diagnose an error by giving the AI the message, the code, what you tried and what you expected.

    debuggingerrorstroubleshooting All models
  • Write Unit Tests

    Generate unit tests that cover normal cases, edge cases and failures, with the reasoning for each.

    testingunit testsquality All models
  • Refactor for Readability

    Improve the structure and naming of code without changing what it does, with a list of changes.

    refactoringreadabilityclean code All models

Related guide