Example result: Review code written by an AI before you trust it
AI-generated example · Review AI Code
Updated

Review code written by an AI before you trust it

AI-written code often looks right and fails on the first unusual input. This prompt reviews it for the typical AI mistakes, such as functions that do not exist and tests that test nothing, and tells you what to check by hand.

text-code-review-ai-written-code — claude — 89 words

Act as a sceptical senior reviewer. The code below was written by an AI assistant.

What it is supposed to do: [GOAL]
Code:
[PASTE]

Check especially for the mistakes AI code often has: invented functions or library options that do not exist, outdated APIs, missing error handling, security gaps (injection, secrets, weak validation), code that handles the happy path only, and tests that do not really test anything. For each problem, give the line, why it is wrong, and the fix. End with what I should test by hand.

Run the code and read it. AI code often looks right and fails on the first unusual input.

Get a better result

What you will get

A sceptical review that checks for invented functions, outdated APIs, missing error handling, security gaps, happy-path-only logic and weak tests, with the line, reason and fix for each, and what to test by hand.

Common mistake

The reviewer approves code that calls a function that does not exist.

Fix: Ask it to “list every library call and check each against the version’s documentation”, then confirm in the real docs.

Also watch for
  • Review stays at the surface and ignores security. Ask directly about user input, secrets, authentication and file or database access, one by one.
  • The tests pass but test nothing. Ask “would these tests fail if the code was wrong?” and try breaking the code on purpose.
Try a variation: ask for the unusual inputs

Add “give me ten unusual inputs, such as empty, huge, negative and unicode, and what the code should do with each”. Run them and compare the results.

Still not right? Reply with this

Go through the code again as if the user input were hostile. List each input, where it is used and what could go wrong.

Guides that use this prompt

More chat & writing prompts

See all 465 →