News / Learn / AI coding tools
How should you review AI-written code?
You'll be able to review AI-written code with a repeatable checklist that catches the errors these tools make most often.
In plain English
AI tools write code fast, and the code often looks right while hiding mistakes. Reviewing it means checking what the code does, not how confident it sounds. You read it as if a new teammate wrote it, and you verify its claims by running it.
Why it matters
Your product inherits every bug you ship, and AI output can add bugs quickly. Speed is only useful if the review step stays strong. A clear review habit lets you use coding agents without trusting them blindly.
How it works
Start by checking the intent. Ask whether the change does what you asked, and nothing extra. Agents often add unrequested features, rename things, or touch files outside the task. A diff that is larger than the job is a warning sign.
Next, check the logic at the edges. AI code tends to handle the happy path well and miss empty inputs, null values, off-by-one errors, timeouts, and concurrent access. Read each branch and ask what happens when the input is unexpected.
Check every external call. Confirm that library functions, method names, and config keys exist in the version you use. Models sometimes invent plausible APIs. Look at the real documentation or the source when a call looks unfamiliar.
Check security and data handling. Look for secrets in code, unsafe string building in queries or shell commands, missing authorization checks, and logging of private data. Treat any text that came from users or from web pages as untrusted input.
Finally, verify by running. Run the tests, add tests for the new behavior, and try the feature yourself. A passing test suite only proves what the tests check, so write tests that would fail if the code were wrong.
A concrete example
A quick test that targets an edge case AI code often misses. The function is simple on purpose, so the test is what matters.
def average(values):
if not values:
raise ValueError("values must not be empty")
return sum(values) / len(values)
def test_average_basic():
assert average([2, 4]) == 3
def test_average_rejects_empty():
try:
average([])
except ValueError:
pass
else:
raise AssertionError("expected ValueError for empty input")A short sketch to show the idea. Check the official docs of the tool you use.
What goes wrong
- Trusting confident explanations Judge the code, not the prose. Run it and check the behavior yourself.
- Approving large diffs quickly Ask the agent for smaller changes. Review one logical change at a time.
- Assuming invented APIs are real Confirm every unfamiliar function or option in the official docs or source.
- Relying only on AI-written tests Write or check tests that would fail on wrong behavior, not tests that copy the code's assumptions.
Going deeper
Learn your language's linter, type checker, and static security scanner, and wire them into your workflow. Read about code review practices from your team's existing process, and about threat modeling for the parts of your app that handle user data.
FAQ
Do I need to read every line?
Read everything that touches data, money, auth, or external calls closely. Skim low-risk generated boilerplate, but still run it and check its behavior.
Can AI review AI code?
A second model can catch some issues and is useful as an extra pass. It does not replace human review or tests, because it can share the same blind spots.
Why does AI code look so clean?
Models are good at producing familiar patterns. Clean style is not evidence of correct logic, so review logic separately from formatting.
What should I check first?
Start with the scope of the change and any external calls. Then check error handling, inputs at the edges, and security-sensitive code.
Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.