my-git

How to Review AI-Generated Code

English 中文

The risk with AI-generated code is that it often changes boundaries, semantics, dependencies, and long-term maintenance costs while in a state that “looks reasonable.”

When reviewing AI code, review the intent first, then the diff, and then the validation.

1. Review Order

Understand Intent First

Ask first:

For an AI diff without clear intent, do not enter code details first.

Then Look at Diff Size

git diff --stat

If the number of files is too large, split them first:

Then Look at Behavioral Changes

Focus checks on:

Finally Look at Tests

AI-written tests easily verify only “the implementation it just wrote” and do not verify real business boundaries.

Good tests should answer:

2. High-Risk Signals

3. Review Checklist

4. Prompt Examples

Let AI Perform Risk Review

Please review the current git diff.
Output only specific risks, do not provide vague summaries.
Focus checks on: behavioral boundaries, compatibility, error handling, test validity, security risks, and irrelevant changes.
Give file paths, risk descriptions, and suggested modification methods for each problem.

Let AI Split Commits

Based on the current git diff, please suggest how to split it into multiple logical commits.
Provide a title, included files, and reason for splitting for each commit.
Do not modify files.

Let AI Generate PR Description

Please generate a PR description based on the current git diff.
Include What changed, Why, How tested, Risk, and Rollback plan.
Mark content that cannot be confirmed from code as "requires manual input."

5. Humans Assume Final Responsibility

AI can help you find problems faster, but it cannot assume merge responsibility for you.

The final reviewer should at least confirm:

6. How to Use AI Review Tools

AI Review tools are suitable for the first round of scanning, especially for finding obvious bugs, test gaps, security risks, irrelevant changes, and maintainability issues.

Teams should maintain three boundaries when using them:

  1. AI review results do not constitute owner approval.
  2. High-risk directories still require human owner review.
  3. False positives and false negatives of AI review should be periodically reviewed.

Put AI review results into the PR process, but do not let them replace human merge judgment.

Extended Reading