Mesrai
Back to blog
// essayBest Practices

Code Review Checklist for AI-Generated Code: 25 Checks Before You Merge

A 25-point code review checklist for AI-generated code: correctness, security, architecture, performance and tests, with a worked example and what to automate.

Surya Pratap SinghNovember 17, 202611 min read

AI-generated code looks finished long before it is correct. It compiles, it is neatly formatted, and it often comes with tests that pass. That polish is exactly why it needs a deliberate code review checklist: the mistakes in AI-generated code are rarely syntax errors, they are missing checks, wrong assumptions and quiet security gaps that a quick skim will not catch.

This guide gives you a 25-point code review checklist for AI-generated code, grouped into five areas you can work through in order: correctness, security, architecture, performance, and tests and release. Then it walks through a real-world style example where a small AI-written endpoint fails seven of the checks, and shows which checks to automate so your reviewers spend their attention where it matters.

Statistics from Veracode's 2025 study: AI chose the insecure option in 45% of coding tasks, failed to prevent cross-site scripting in 86% and log injection in 88%, and Java code failed over 70% of the time
Functional is not the same as safe. Source: Veracode 2025 GenAI Code Security Report.

Why AI-generated code needs its own review checklist

Code review best practices were built around a human author who understood the change and could explain every line. With AI-generated code, the author is often a model that optimised for "looks plausible and runs", and the person who opened the pull request may have read it once.

The evidence that this matters is now solid. Veracode's 2025 GenAI Code Security Report tested more than 100 large language models on 80 coding tasks. When a task could be solved securely or insecurely, the models picked the insecure option 45% of the time. They failed to defend against cross-site scripting in 86% of relevant cases and against log injection in 88%, and security results did not improve as the models got better at writing working code.

The failure modes are different from human ones:

  • Plausible but wrong logic. The code handles the example in the prompt and nothing else.
  • Missing edge cases. Empty lists, nulls, time zones, retries and concurrent requests are the first things to go.
  • Invented or unnecessary dependencies. A new package for something the standard library already does, or one that does not exist at all.
  • Tests that confirm the bug. When the same model writes the code and the tests, the tests encode the same wrong assumption.
  • Security left to chance. Authorization, input validation and output encoding are added only when the prompt asked for them.

This is also what people mean by "vibe coding security": code accepted because it felt right in the editor, not because anyone checked it. A checklist turns that feeling into a short, repeatable process.

The 25-point code review checklist at a glance

Five columns of five checks each: correctness, security, architecture, performance, and tests and release
The full checklist. Work through it left to right.

Correctness checks (1 to 5)

Start here. If the change does the wrong thing, nothing else matters.

  1. Does it match the actual requirement? Re-read the ticket, not the prompt. AI code often solves the question it was asked rather than the problem the user has.
  2. Is every input validated? Check type, range, length and format at the boundary, before anything else touches the data.
  3. Are error paths handled, not swallowed? Look for empty catch blocks, errors logged and then ignored, and functions that return null on failure without the caller checking.
  4. Are boundary cases correct? Off-by-one comparisons (< versus <=), empty collections, zero, negative numbers, the first and last day of a month, and time zones.
  5. Are concurrency assumptions safe? Two requests at once, a retried webhook, a double-clicked button. Check for read-then-write races and missing idempotency keys.

Security checks (6 to 10)

These are the checks AI-generated code fails most often, and the ones with the highest cost when missed.

  1. Authentication: every new route or handler requires a logged-in user, unless it is deliberately public.
  2. Authorization: the code checks that this user may act on this specific record, not just that they are logged in. Insecure direct object references are among the most common AI mistakes.
  3. Secrets: no keys, tokens or passwords in code, config, tests or fixtures. See How AI Detects Hardcoded Secrets in Pull Requests.
  4. Injection: queries use parameters, shell commands avoid string building, HTML output is encoded, and logs never include raw user input. For a real example, see the SQL injection Mesrai caught in a search endpoint.
  5. Dependencies: every new package exists, is the one you meant, is maintained, and is actually needed.

Architecture checks (11 to 15)

AI tools see the file in front of them. Your reviewers see the system.

  1. Module boundaries: the change lives where similar code lives, and it does not reach into another module's internals.
  2. Dependency direction: lower layers do not import from higher ones, and shared libraries do not start depending on applications.
  3. Backward compatibility: public functions, API responses, events and database columns keep working for existing callers. A renamed field is a breaking change. See the breaking API change Mesrai caught pre-merge.
  4. Data contracts: schemas, migrations and serializers agree with each other, and new required fields have defaults or a backfill.
  5. Blast radius: you know which other services, jobs or packages call the changed code, and they still work.

Performance checks (16 to 20)

  1. Query count: no database calls inside loops. N+1 queries are a classic AI pattern because each line looks reasonable on its own.
  2. Resource use: large files and result sets are streamed or paginated, not loaded into memory whole.
  3. Algorithmic cost: no nested loops over data that will grow, and no repeated sorting or searching inside a loop.
  4. Caching: anything cached has a clear key, an expiry and an invalidation path. A cache with no invalidation is a bug waiting for a deploy.
  5. Hot paths: code that runs on every request, or on every row in a batch job, gets an extra look.

Tests and release checks (21 to 25)

  1. Meaningful assertions: tests check results and side effects, not just "did not throw".
  2. Failure-path tests: at least one test for invalid input, a missing record and a permission error. AI test suites are often all happy paths.
  3. Migration safety: schema changes are backward compatible during deploy, and large tables are altered without long locks.
  4. Rollback plan: you know how to undo this change, and the undo does not lose data.
  5. Observability: new failure modes produce a log line, a metric or an alert that someone will actually see.

Worked example: an AI-written endpoint that fails 7 checks

Here is a realistic pull request. A developer asked an AI assistant for "an endpoint to fetch a user's invoices with optional status filter". The result looks clean and has a passing test:

jsinvoices.routes.js
router.get('/api/invoices/:userId', async (req, res) => {
  const { userId } = req.params;
  const status = req.query.status;
  logger.info(`Fetching invoices for ${req.query.email}`);

  let sql = `SELECT * FROM invoices WHERE user_id = ${userId}`;
  if (status) sql += ` AND status = '${status}'`;
  const invoices = await db.query(sql);

  for (const inv of invoices) {
    inv.items = await db.query(`SELECT * FROM invoice_items WHERE invoice_id = ${inv.id}`);
  }
  res.json(invoices);
});
The AI-written invoices endpoint annotated with seven findings: missing authentication, missing ownership check, SQL injection twice, email in logs, an N+1 query loop and an unbounded result
Seven of the 25 checks fail in under fifteen lines of code that "work".

Run it through the checklist and seven checks fail:

  • Check 6, authentication: nothing requires a logged-in user.
  • Check 7, authorization: any caller can read any user's invoices by changing :userId. This is an insecure direct object reference.
  • Check 9, injection: both userId and status are pasted into SQL. A crafted status value can read other tables.
  • Check 9 again, logs: the user's email goes straight into the log, which is both a privacy problem and a log-injection risk.
  • Check 2, input validation: status is not checked against the allowed values.
  • Check 16, query count: one query per invoice inside the loop, the classic N+1.
  • Check 17, resource use: no pagination, so a customer with ten thousand invoices gets all of them in one response.

The fixed version is barely longer:

jsinvoices.routes.js
const ALLOWED = new Set(['paid', 'open', 'void']);

router.get('/api/invoices', requireAuth, async (req, res) => {
  const status = req.query.status;
  if (status && !ALLOWED.has(status)) return res.status(400).json({ error: 'invalid status' });

  const invoices = await db.query(
    `SELECT * FROM invoices WHERE user_id = $1 ${status ? 'AND status = $2' : ''}
     ORDER BY created_at DESC LIMIT 50`,
    status ? [req.user.id, status] : [req.user.id],
  );
  const items = await db.query(
    'SELECT * FROM invoice_items WHERE invoice_id = ANY($1)',
    [invoices.map((i) => i.id)],
  );
  res.json(attachItems(invoices, items));
});

The user now comes from the session rather than the URL, both queries are parameterised, the status is checked against a fixed list, items load in one query, results are paginated, and nothing personal is logged. The original test still passes, which is the point: a passing test told you nothing about any of these problems.

Automate the checklist, keep humans for judgment

Twenty-five checks is a lot to do by hand on every pull request. The good news is that about half of them are mechanical and can run automatically before a person ever looks.

Two columns: checks to automate, such as injection, secrets, query loops and missing tests, and checks that need a human, such as requirement fit, architecture fit and rollback plans
Let machines do the mechanical half of the checklist so reviewers have time for the judgment half.

Automate: secrets (8), injection patterns (9), dependency checks (10), query-in-loop detection (16), missing failure-path tests (22), unsafe migrations (23), and well-defined team conventions.

Keep human: requirement fit (1), authorization design (7), architecture and blast radius (11 to 15), and release decisions (24, 25).

Automating checks with Mesrai

Mesrai reviews every pull request automatically, so the mechanical checks are done before your reviewer opens the diff, and it does not matter whether a person or an AI wrote the change.

  • Security and correctness findings on every PR. Mesrai flags injection risks, missing authorization checks, leaked secrets, N+1 queries and unhandled errors as inline review comments.
  • Your checklist as Mesrai Rules. Write team rules in plain English, such as "every route under /api must use requireAuth" or "never log email addresses", and every pull request is checked against them. The built-in rules library covers security hardening, error handling, performance and test coverage, so you can start without writing anything. See Mesrai Rules for test coverage enforcement.
  • Repository context, not just the diff. Architecture checks need to know who calls the changed code, so Mesrai reviews with repository context instead of the changed lines alone.
  • Before the push. The Mesrai CLI runs the same review on your machine, which is the best moment to catch AI mistakes: before anyone else has to read them.

Mesrai does not replace your reviewer's judgment on checks 1, 7 and 11 to 15. It makes sure that judgment is spent on the decisions only a person can make.

A pull request template for AI-assisted changes

Paste this into .github/pull_request_template.md so every author answers the questions reviewers would otherwise have to ask:

A pull request template with sections for what changed and why, how much was AI-generated, how it was verified, risky areas and rollback
Make authors do the first pass of the checklist themselves.
htmlpull_request_template.md
## What and why
<!-- Link the ticket. One paragraph on the problem this solves. -->

## AI assistance
- [ ] Significant parts of this change were AI-generated
- Tool used:

## How I verified it
- [ ] I read every changed line and can explain it
- [ ] Tests cover at least one failure path (invalid input, not found, forbidden)
- [ ] No secrets, personal data or new dependencies I did not intend

## Risk
- Areas touched (auth, payments, migrations, public API):
- Rollback plan:

For more habits that keep AI-assisted teams honest, see PR hygiene for AI-assisted teams.

Frequently asked questions

How do you review AI-generated code?

Read it as if a new teammate wrote it with no context. Check it against the original requirement, not the prompt, then work through security, architecture, performance and tests. Pay extra attention to authorization, input validation and failure-path tests, which AI code most often gets wrong.

What should a code review checklist include?

At minimum: correctness against the requirement, input validation, error handling, authentication and authorization, injection and secrets, backward compatibility, query and performance patterns, meaningful tests including failure paths, and a rollback plan. The 25 checks above cover each of these.

Is AI-generated code less secure than human code?

It is not automatically worse, but it is consistently weak in specific areas. Veracode found models chose insecure options in 45% of security-relevant tasks, and that rate did not improve as models got better at writing working code. Treat security checks as mandatory for AI-written changes.

What is vibe coding security?

It is the risk that comes from accepting code because it looks and feels right rather than because it was verified. The fix is not to stop using AI, but to add a consistent review step: a checklist, automated checks and a human decision on the risky parts.

Can an AI code reviewer review AI-generated code?

Yes, and it is a good fit for the mechanical checks, because it reads every line every time. Keep humans for the judgment calls: whether the change solves the right problem, fits the architecture and can be safely released.

Sources

Want every AI-generated pull request checked against your team's checklist automatically? Try Mesrai on your repositories.

// try

See it on your next PR.

Free for individual developers as a launch offer. Set up in about 2 minutes. Mesrai reviews every commit.