How to review AI-generated code: 10-point checklist

Equipe HcodeOctober 19, 20267 min read

In this article

To review AI-generated code, treat it as if it were written by a new colleague: check if it solves the requested problem, if it actually exists (APIs and packages), if it is safe, if it handles edge cases, and if it has tests that prove what it promises. The checklist of 10 points below covers these items and ends with a prompt ready for you to use.

AI is already part of the routine for programmers. In the 2026 Stack Overflow Developer Survey, 73% of those who use code assistants or agents use them every day, and 67% mainly use them to generate code in areas they already know. The same survey shows the other side: 93% say they need source citation to trust AI's response. In other words, those who use it trust cautiously, and the review is the step that transforms a suggestion into code that you can sign off on.

Why review AI-generated code?

AI writes code that looks correct, and that's the problem. It can invent a method that doesn't exist in the version of the library you're using, ignore an edge case, or mix your project's style with patterns from others. You are the one making the commit, so the responsibility for the outcome is yours, not the tool's.

A good review is also an opportunity to learn: by understanding each snippet, you build repertoire instead of just copying and pasting.

10-point checklist for reviewing AI-generated code

Use the list in order. The first points prevent wasting time on code that shouldn't progress.

1. Understand what the code does before executing it

Read the code line by line and explain in your own words what each block does. If you can't explain a snippet, don't accept it yet: ask the AI to explain and verify the explanation in the official documentation. Code you don't understand is technical debt you've just created.

2. Confirm that it solves the requested problem

The AI responds to what was written in the prompt, not to what you needed. Compare the result with the actual requirements: inputs, expected outputs, and business rules. Run the code with a simple example and a difficult example.

3. Check if packages and APIs actually exist

Check each import, package, and method in the documentation and the official registry (npm, PyPI, Maven, etc.). Verify the exact name of the package, the version, and whether it is maintained. Models may suggest packages that do not exist, and invented names may be registered later by malicious third parties, so never install a dependency without checking.

4. Look for security flaws

Pay close attention to user input, database queries, authentication, and secrets. The most common issues are SQL injection, passwords or tokens written in the code, and lack of data validation. A classic example:

// Vulnerable: the email goes directly into the query
const query = `SELECT * FROM usuarios WHERE email = '${email}'`;

// Fixed: parameterized query
const resultado = await db.query(
  "SELECT * FROM usuarios WHERE email = $1",
  [email]
);

5. Test edge cases and errors

AI tends to write the "happy path." Test empty lists, null values, overly long text, network failure, and timeout. See how a small detail can break the function:

function media(notas) {
  return notas.reduce((a, b) => a + b, 0) / notas.length;
}

media([]); // NaN, because the calculation becomes 0 / 0

// Fixed
function media(notas) {
  if (notas.length === 0) return 0;
  return notas.reduce((a, b) => a + b, 0) / notas.length;
}

Want to receive more guides like this? Follow the Hcode blog and get the next AI content for programmers.

6. Read tests with the same rigor

If the AI generated the tests, review them as well. A weak test passes even when the code is wrong and gives a false sense of security:

// Weak test: passes with any value
test("calculates the average", () => {
  expect(media([10, 20])).toBeDefined();
});

// Better test: checks the result and the edge case
test("calculates the average", () => {
  expect(media([10, 20])).toBe(15);
  expect(media([])).toBe(0);
});

A good test truly fails when the code is wrong. If you want to verify, alter the code on purpose and see if the test fails.

7. Observe performance

The code may work with 10 records and freeze with 10,000. Be cautious about queries within loops (the known N+1 problem), nested loops, and loading entire lists into memory:

// N+1: one database query for each order
for (const pedido of pedidos) {
  pedido.cliente = await db.clientes.buscarPorId(pedido.clienteId);
}

// Better: one query for all clients
const ids = pedidos.map((p) => p.clienteId);
const clientes = await db.clientes.buscarPorIds(ids);

The names db.clientes.buscarPorId and buscarPorIds are fictitious, to illustrate the idea: adapt to your ORM or driver.

8. Ensure consistency with your project

Check if the code follows your naming conventions, folder structure, error handling, and team's style. The AI may recreate a utility function that already exists in the project. Run the linter, formatter, and type checking: they catch a lot without effort.

9. Protect sensitive data and licenses

Before pasting code into the prompt, remove passwords, tokens, API keys, and clients' personal data, and follow your company's AI policy. When receiving code, be wary of long and very specific snippets that seem copied from another project and check the license of any new library.

10. Deliver in small, reviewable changes

Request small changes, one at a time, and make separate commits. A 40-line diff you review carefully; an 800-line one you'll just skim. If the code will go to someone else for review later, inform in the pull request what was generated with AI and what you verified.

A prompt ready to ask for a second opinion

The AI itself can help with the review, as long as you treat the response as a second opinion, not as approval. Copy and adapt:

Review the code below as a senior engineer. List:
1) unhandled bugs and edge cases;
2) security problems;
3) packages, functions, or APIs that may not exist in the version I use;
4) performance points;
5) missing tests.
For each item, indicate the line, explain the risk, and suggest the fix.
Cite the official documentation when possible. If you're not sure,
say you're not sure instead of stating it.

Language and version: [fill in]
Code:
[paste here]

Asking for source citation helps precisely with the point that weighs most heavily on developers' trust, according to the Stack Overflow survey. Even so, open the link and verify: AI can also err in citations.

Conclusion

Using AI for programming is great for gaining speed, and the review is what maintains quality. Understand the code, confirm that it exists, solves the problem, and is safe, test the difficult cases, take care of performance, maintain the project's standards, and deliver in small parts. Save this list and apply it to each suggestion that enters your repository.

If you want to evolve as a developer in the AI era, check out the Hcode course platform and follow the blog.

Frequently asked questions

Is it safe to use AI-generated code in production?

It can be, as long as the code is reviewed, tested, and verified like any other. AI does not guarantee correctness or security, so the responsibility for the outcome still lies with the person making the commit.

How to tell if the AI invented a package or function?

Check the name and version in the official registry (npm, PyPI, etc.) and the function in the documentation for the version you are using. If the package is unknown, do not install it before verifying who maintains it.

Can AI review the code it generated?

It can point out issues and works well as a second opinion but does not replace human review or automated tests.

Do I need to inform that I used AI in the pull request?

It depends on your team's policy. Even so, it is good practice to state what was generated with AI and what you verified, for the reviewer to know where to pay more attention.

Source

2026 Stack Overflow Developer Survey Results, October 6, 2026.

Keep learning with Hcode

Sign up for the course platform and follow the next blog guides.