(Note · · 6 min read)
Reviewing code an AI wrote, when nobody can explain it
The risk in AI-written code is not that it looks bad. It is that it looks good: consistent naming, sensible structure, no obvious smells. Ordinary review is tuned to catch sloppiness, and this is not sloppy. It is confident, and nobody in the room can explain why it does what it does.
By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka
What you actually lost
Normally a diff comes with an author who can say why. That reasoning is most of what review checks: it was done this way because of that constraint, this case cannot happen because of a guarantee upstream. Generated code arrives without it, and reviewers tend to supply the missing rationale themselves, assuming a reason exists because the code looks deliberate.
So the first question is not is this correct but can anyone here explain why it is correct. If nobody can, the only honest options are to work it out or not to merge it.
Check the edges, which is where plausibility runs out
Generated code reproduces the shape of the common case well. It is far weaker on what happens around the edges, because those are specific to your system rather than to the pattern.
- Empty, missing, duplicate and concurrent inputs — not just the happy path the example assumed.
- Error handling: whether failures are swallowed, and whether a caught error leaves state half-written.
- Whether a failed external call is treated as a legitimate empty result, which is how outages become silent data loss.
- Boundaries between money, permissions and personal data, where being nearly right is still wrong.
Verify the things that look like facts
Generated code is fluent about APIs, which means it will produce a call that reads perfectly against a library version that does not exist, or a configuration key that was renamed. Check anything asserted about an external system against that system's own documentation rather than against how right it looks.
The same scepticism applies to dependencies it introduced. A package name that sounds correct is not evidence the package is the one you meant, or that it is maintained.
Ask whether it belongs here
The common failure is duplication: a helper reimplemented because the generator could not see the one that exists three files away. Each instance is individually defensible and collectively a codebase where fixes have to be applied several times, and will not be.
Search for what already exists before accepting a new utility. This is the single highest-value check on generated code, and it is nearly invisible in a diff.
Make tests the place the understanding lives
If nobody can explain the implementation, the tests have to carry the specification. Write them yourself rather than generating them alongside, because tests generated from the same mistaken assumption agree with the code and prove nothing.
Name each test after the behaviour it protects. Then the next person, who also did not write the implementation, has something that states what it was supposed to do.
The rule worth keeping
Volume of code is not progress, and merged code is owned by the team regardless of what produced it. The bar is not whether it works today but whether somebody can change it safely in six months — which means whether anybody understands it now.
Common questions
What is different about reviewing AI-generated code?
It arrives without an author who can explain why it is the way it is, and that reasoning is most of what review normally checks. Because the code reads as deliberate, reviewers tend to supply the missing rationale themselves and assume a reason exists.
Where is AI-generated code most likely to be wrong?
At the edges: empty, duplicate or concurrent inputs, error handling that swallows failures or leaves state half-written, external call failures treated as empty results, and anything touching money, permissions or personal data.
Should I generate tests for generated code?
Write them yourself. Tests generated alongside the implementation tend to encode the same mistaken assumption, so they agree with the code and prove nothing. If nobody can explain the implementation, the tests have to carry the specification.
What is the highest-value check on AI-written code?
Whether it duplicates something that already exists in the codebase. Generators cannot see the helper three files away, and each duplicate is individually defensible but collectively means fixes must be applied in several places, and will not be.