Prompt Engineering AI-Generated Code Code Review

Review AI-Generated Code

AI wrote it; review it with extra suspicion: strict correctness review of the diff, because generated code fails confidently.

Overview

AI-generated code has a signature failure mode: it looks right. It compiles, reads cleanly, handles the happy path — and invents an API, drops an edge case, or quietly changes behavior it wasn't asked to touch. This setup reviews AI-generated changes as diffs under strict correctness: the twelve correctness checks plus diff criteria (does the change do ONE thing? is changed behavior covered by changed tests? what's the regression risk in touched paths?), with every finding flagged and the verdict withheld until the checklist is done.

How to use this resource

  1. Review the diff, not the file

    Diff scope flags unrelated changes — the assistant's favorite way to expand its own scope.

  2. Verify every external call

    Invented APIs are the signature AI failure: each external symbol the diff introduces deserves a checklist pass.

  3. Demand changed tests for changed behavior

    The diff criterion that catches the silent behavior change generated code loves to slip in.

Why This Works

  • Strict style removes the benefit of the doubt that fluent code unearns
  • Diff criteria catch scope expansion — the AI failure mode reviews built for humans miss
  • One review contract scales to whatever volume the assistant produces

Best for

  • Teams adopting AI coding agents with a review gate
  • Diffs accepted under time pressure from a confident assistant
  • Codebases where generated code volume outpaces human review

Not for

  • Validating AI output FORMAT (JSON, structure) — that's the AI Output Validator
  • Re-generating the code — review the diff that exists; regeneration re-rolls the risk

Use cases

  • Gating Copilot/agent-written changes before they enter the codebase
  • Catching the invented API call that compiles against nothing
  • Flagging the unrequested "improvements" hiding in the diff

FAQ

Does this review prompt fix the AI-generated bugs it finds or only report them?

It reports only — the instruction "Review only — report findings; do not rewrite the code" is explicit, and each finding is one bullet as [SEVERITY] location — what is wrong and why. It ends with an APPROVED or CHANGES REQUIRED verdict, but a human still decides whether to merge and does the fixing. It generates review text; catching every issue is not guaranteed.

How does this catch the extra changes an assistant slips into a diff?

Through the criterion "Whether the diff does one thing — unrelated changes flagged." Because the scope is the CHANGE, not the whole codebase, and "Removed lines matter as much as added ones," unrequested edits get surfaced as findings. It flags them for your judgment; you and your reviewers still confirm each one before the code lands.

How is reviewing AI code different from validating its JSON output?

This targets correctness of the change — logic errors, null dereferences, race conditions, invented APIs across the twelve-item checklist — not output shape. The notFor line points format checks ("JSON, structure") to the AI Output Validator instead. Here you paste a diff under CODE TO REVIEW; the generated prompt judges behavior, then you run it in your assistant and own the merge call.

More resources from Code Review Prompt Generator

Resources that pair well

Related tools

Guides for this resource

Tip: Save time by exploring related resources and tools that integrate with this resource.