Why AI-generated code needs a deliberate review
Code from an AI assistant tends to look finished. It is neatly formatted, confidently commented and usually compiles. That polish makes it easy to skim, and skimming is where problems slip through: a method that does not exist in the library version you use, an edge case the prompt never mentioned, or a security shortcut copied from a common but unsafe pattern.
Hold AI-generated code to the same standard as any other contribution, and add checks for the mistakes models make most often. You are responsible for everything you merge, whoever or whatever typed it. Work through the sections below in order; each item is a yes-or-no question about the change in front of you.
Before you read the code
- You can restate the task in one or two sentences and list its acceptance criteria. If you cannot, the review has nothing to check against.
- The size of the change fits the task. If it touches far more files than the task needs, ask for a smaller change instead of reviewing a large one.
- You know which parts were generated and which were edited by hand, so you know where to look hardest.
- The code builds and the existing tests pass, locally or in CI, before you spend time on detailed review.
Intent and correctness
- The change does what the task asked, and nothing else. Look for unrequested refactors, renamed variables and 'improvements' outside the scope.
- Edge cases are handled: empty or missing input, records that do not exist, very large values, time zones, concurrent requests and partial failures.
- Error handling is real. Exceptions are not caught and silently ignored, and failures produce messages someone can act on.
- The logic follows the patterns already used in the codebase instead of introducing a second way of doing the same thing.
- Comments and docstrings describe what the code actually does. Remove comments that restate the prompt or promise behaviour the code does not have.
Invented or outdated APIs
- Every imported package exists, is the one you intended and is already an approved dependency. Read names carefully: a plausible name can belong to a different package entirely.
- Every function, method and parameter used exists in the version pinned in your project. Check the official documentation or the installed source, not memory.
- No deprecated calls have crept in because the model learned an older version of the library.
- Configuration keys, environment variable names and command-line flags match the current documentation.
Security and data handling
- No secrets, API keys, tokens or real personal data appear in code, tests, fixtures or comments.
- Input from users, files, networks and model output is validated before it is used.
- Database queries pass values as parameters, never by building SQL text from untrusted values.
- Shell commands, file paths and URLs built from input are restricted to an allowlist or safely escaped.
- Authentication and authorisation checks have not been removed, loosened or bypassed to make something work.
- New logging does not record secrets, tokens or personal data.
# Unsafe: the value becomes part of the SQL text, so crafted input can change the query
cursor.execute(f"SELECT id, status FROM orders WHERE customer_ref = '{customer_ref}'")
# Safe: the driver sends the value separately, so it is always treated as data
cursor.execute("SELECT id, status FROM orders WHERE customer_ref = ?", (customer_ref,))The placeholder style depends on your database driver; this example uses the question-mark style of Python's built-in sqlite3 module.
Tests and verification
- New behaviour has tests, and you have read them. Generated tests sometimes assert whatever the code currently does, which proves nothing.
- At least one test fails if you deliberately break the new code. If nothing fails, the tests are not checking the behaviour.
- Tests cover the edge cases in your acceptance criteria, not only the expected path.
- No existing test was deleted, skipped or weakened to make the build pass.
- For anything a user will see, you ran the code yourself and the result matches what the task asked for.
Maintainability and fit
- Names, structure and style follow the project's conventions, and the linters pass.
- There is no dead code, unused import or speculative abstraction added 'for later'.
- No logic is duplicated where an existing helper already does the job.
- If a block looks copied from a specific project, you have checked where it came from and whether its licence allows you to use it.
- You could explain every line to a colleague. If you cannot, learn it or remove it before merging.
When to send it back
Ask for a revision, or write the change yourself, when you see any of these signals. Rejecting a change at review is far cheaper than debugging it in production.
| Signal | What to do |
|---|---|
| The change is much larger than the task | Split the task and generate one part at a time. |
| It uses an API you cannot find in the documentation | Treat the whole change as unverified until that call is confirmed or replaced. |
| Tests were edited to match the new code | Restore the original tests and fix the code instead. |
| Security checks were weakened | Reject it and restate the security requirement in the next request. |
| You cannot explain how it works | Do not merge. Ask for a simpler version or write it yourself. |
Better input produces changes that are easier to review. The guide to giving AI assistants useful context shows how to write a task brief with a definition of done you can check against.
Related lessons
- Acceptance CriteriaNew Project Creation
- Reading an Unfamiliar CodebaseExisting Project Engineering
- Sharing Code with an AI Assistant SafelyExisting Project Engineering
- Written by
- PromptFable Editorial
- Last updated 13 Nov 2026
- Review
- Not yet reviewed
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.