Skip to content
Code review

A practical review process for AI-generated code

Review behavior, integration, and failure paths with a worked example that turns a plausible patch into a decision you can defend.

By Hunicode Team · · 6 min read · Updated

On this page
  1. Restate the change in observable terms
  2. Read the whole diff before the details
  3. Trace a plausible implementation
  4. Make the smallest understandable correction
  5. Verify independently of the generated tests
  6. Review failure paths and integration
  7. Close the review with evidence

Generated code can look consistent and still solve the wrong problem. A useful review starts with the behavior you need, then checks whether the patch implements that behavior and fits the surrounding system. Treat the assistant's explanation as a set of claims to investigate alongside the code.

The debate over whether coding interviews are dead makes this review skill more relevant: when AI writes the code, your judgment is what the interviewer sees.

You do not need a separate standard of correctness for AI suggestions. You do need to account for the fact that a large, confident answer can arrive before you have formed your own understanding of the change. Slow the review down enough to make that understanding explicit.

Restate the change in observable terms

Before reading line by line, write one sentence describing what a caller should observe. For example: “Return up to limit unique user IDs in first-seen order without modifying the input.” Add the relevant constraints: IDs are strings, limit must be a nonnegative safe integer, and an invalid limit should throw a RangeError.

This is a small function, but its contract contains several independent requirements. An implementation could deduplicate correctly while sorting the IDs, mutate the input while preserving the result, or return an element when the limit is zero. Naming those requirements helps you avoid reviewing only the most obvious behavior.

If you are reviewing a bug fix, begin with the reproduction: the input or user action, actual behavior, and expected behavior. Check that the proposed change addresses the cause of that difference.

Read the whole diff before the details

Look at the changed files and the size of the patch. Does a utility function now introduce a dependency? Did a generated test alter a shared fixture? Did a small correction expand into a new abstraction? These changes may be justified, but each increases what you need to understand.

Read callers and types when they affect the contract. A function that looks safe in isolation can still return a shape its consumer does not handle. For changes with side effects, identify when those effects happen and what the caller sees if they fail.

Keep a brief list of questions as you read. Resolve questions that could affect correctness before spending time on naming or formatting. This keeps style preferences from crowding out behavior review.

Trace a plausible implementation

Suppose the assistant proposes:

function uniqueIds(ids: string[], limit: number): string[] {
  ids.sort();
  return [...new Set(ids)].slice(0, limit);
}

This code is short and returns unique values. It also sorts the input in place, violating both first-seen order and non-mutation. For a negative limit, slice uses an end position relative to the array length, which does not match the required error behavior.

Trace a small input by hand before running anything:

ids = ["b", "a", "b", "c"], limit = 2
Expected result: ["b", "a"]
Expected original ids after the call: ["b", "a", "b", "c"]

The proposed implementation returns ["a", "b"] and changes the original array. One example exposes two contract violations. This is why an independent example can be more useful than a generic request to “review carefully.”

Make the smallest understandable correction

One implementation that meets the stated contract is:

function uniqueIds(ids: readonly string[], limit: number): string[] {
  if (!Number.isSafeInteger(limit) || limit < 0) {
    throw new RangeError("limit must be a nonnegative safe integer");
  }
  const result: string[] = [];
  const seen = new Set<string>();
  for (const id of ids) {
    if (result.length === limit) break;
    if (!seen.has(id)) {
      seen.add(id);
      result.push(id);
    }
  }
  return result;
}

The loop follows the input order. The limit check happens before accepting an ID, so a zero limit produces an empty result. The readonly parameter prevents accidental mutation through this parameter in TypeScript; the implementation also avoids mutation at runtime. A type annotation alone would not prove that a different implementation leaves the input untouched.

The function examines at most all input elements and stores at most the number of accepted unique IDs. It makes no attempt to normalize case or remove blank IDs because those behaviors are absent from the contract. If they are needed, specify them and add examples before extending the function.

Verify independently of the generated tests

Check the ordinary case, an empty list, a zero limit, a limit greater than the number of unique IDs, repeated IDs, and invalid limits. Include an assertion that the original list still has its original order. Test the failure contract explicitly rather than accepting any thrown exception as success.

For an actual application, run a check at the boundary where this function is used. A URL parameter arrives as text, for example, while this function expects a number. The caller must parse and validate that input according to its own contract. A passing unit test for this helper cannot prove the caller does so.

Read the tests for accidental agreement with the implementation. If a generated test expects sorted results, it would reinforce the original bug. Expected outputs should come from the requirement, even when they contradict the assistant's code or explanation.

Review failure paths and integration

For larger patches, ask what happens when an operation fails halfway through. Does a request return an error the UI can display? Does a retry duplicate a write? Does cleanup run after an exception? Does an authorization check apply to the resource being changed?

These questions should follow the actual patch. A pure array helper needs different review attention from a payment or file-upload handler. Use the scope of the change to choose concrete failure scenarios rather than applying a long checklist mechanically.

Also inspect new dependencies and configuration changes. Confirm that the package exists, that the version and API match the code, and that the dependency is necessary. An import statement is not evidence that the library offers the promised behavior.

Close the review with evidence

Summarize what you accepted and how you checked it. A useful review note might say: “The helper now preserves first-seen order and validates the limit. Tests cover duplicates, zero, invalid limits, and input preservation. The existing caller passes a parsed number.” If the last sentence is unverified, say what remains to check instead.

Keep unresolved concerns visible. Do not replace an unanswered question with a confident summary because the tests pass. When you can explain the contract, trace the important cases, and connect the evidence to the change, you are in a better position to accept it.

For more practice choosing those cases, continue with Test beyond the happy path. To make the next generated patch easier to review, use the request structure in Ask AI for code you can actually evaluate.

Try it in a real coding round.

A little practice makes these ideas your own.

Find a practice challenge →
← Back to guides