How to review AI generated code: a worked example

For experts4 min read

A senior developer reading code on a large monitor in a Nairobi office, pen in hand over a printed page, late afternoon light

How to review AI generated code comes down to a short routine: understand the goal, run the code, try to break it, then write down the exact defect and the fix. Below is a buggy snippet and the review a careful reviewer would write.

Why AI generated code needs a careful reviewer

Developers already use these tools widely, and they are wary of them. In the 2025 Stack Overflow Developer Survey, 45.7% of respondents said they distrust the accuracy of AI output, and 45.2% said debugging AI-generated code takes more time. The same survey reports that 84% use or plan to use AI tools. The code is used, and it needs checking.

Source: Stack Overflow Developer Survey 2025, AI section(opens in a new tab)

The snippet

The prompt was: write a function that returns how many pages are needed to show a list of items, given the number of items and a page size.

Python
def pages_needed(total_items, per_page):    return total_items // per_page print(pages_needed(100, 10))  # 10print(pages_needed(101, 10))  # 10   <- one item has no pageprint(pages_needed(0, 10))    # 0print(pages_needed(5, 0))     # ZeroDivisionError

It runs, and the first example is right. A reviewer who stops there approves broken code.

How to review AI generated code: the five steps

  1. State the goal in your own words. Pages needed means rounding up, so 101 items at 10 per page need 11.
  2. Run the code on the happy path, then on boundaries: one more than a full page, zero items, a page size of one.
  3. Look for inputs the prompt allowed but the code did not think about, such as a page size of zero or a negative number.
  4. Name the defect precisely, with the input that shows it.
  5. Write the fix and check it with the same inputs.

The review a good reviewer writes

The function uses floor division, which drops the remainder. With 101 items and 10 per page it returns 10, so the last item never appears on any page. The first sample passes only because 100 is an exact multiple of 10. A second problem: a page size of 0 raises ZeroDivisionError with no useful message. The code should reject a non-positive page size explicitly.

Python
def pages_needed(total_items, per_page):    if per_page < 1:        raise ValueError("per_page must be at least 1")    return (total_items + per_page - 1) // per_page assert pages_needed(100, 10) == 10assert pages_needed(101, 10) == 11assert pages_needed(0, 10) == 0assert pages_needed(1, 10) == 1

The reviewer's verdict: reject the original, with the fix above. Notice the structure of that review. It states the effect, gives the input that proves it, names the secondary problem, and shows the corrected version with checks. It does not say 'this seems off'.

A checklist for ai code review in 2026

  • Does it do what the prompt asked, including the constraints?
  • Does it handle empty, one, many, and boundary inputs?
  • Does it change its input when it should not?
  • Are errors raised or swallowed? Is there a bare except?
  • Are there security problems: built SQL strings, unchecked file paths, secrets in code?
  • Do the imports and function calls exist in the version the prompt names?
  • Are the tests real, or do they only check that the code runs?

The last two matter more than they used to. Models sometimes call a function that does not exist, or use an option from a different library version. Verify any unfamiliar call in the official documentation before you approve it.

Tests written by the model deserve the same review

A model that writes the code and the tests in one go often writes tests that agree with its own mistakes. Check that the expected values come from the spec, not from running the function. A test suite where every assertion matches the buggy output proves nothing.

Run the code, if you can

Reading is fast, and running is certain. The METR study in 2025 found that experienced developers who were allowed to use AI tools took about 19% longer on real issues, yet afterwards believed they had been faster. That does not mean AI tools are bad. It means feelings about code quality are unreliable, so measure with a run or a test where you can.

Source: METR: early-2025 AI and experienced open-source developers(opens in a new tab)

If you cannot run it, say so in the review. 'Reviewed by reading; not executed' is an honest line, and it tells the next person how much trust to place in your verdict.

Turning the skill into paid work

This routine is the core of AI code review tasks in training projects. You read short snippets, find the defect and write the reason. Strong reviewers are specific, fast and calm. They never pad the review to look thorough.

Curatrain vets engineers with graded skill tests and matches those who pass to paid, remote jobs. Sign up free at curatrain.com/login.