Review the AI's code

An AI-written function with five planted bugs. Flag the lines you doubt, run the tests, and see which bugs tests catch and which only reading finds.

Tests the AI wrote
Edge-case tests you can add

Read the function first and tap the number of any line you would question. Then run the tests, and only then show the bugs.

Example data. The tests run in your browser on a copy of this Python function that behaves the same way, checked against real Python 3 and sqlite3.

customer_report.py, written by an AI tool

Python
  1. def customer_report(db, email, min_amount=0):
  2.     """Total, average and biggest order for one customer.
  3.     Counts orders of at least min_amount."""
  4.     rows = db.execute(
  5.         f"SELECT id, amount FROM orders WHERE email = '{email}'"
  6.     ).fetchall()
  7.     print("debug:", email, [r["amount"] for r in rows])
  8.     kept = [r for r in rows if r["amount"] > min_amount]
  9.     total = sum(r["amount"] for r in kept)
  10.     average = total / len(kept)
  11.     biggest = sorted(kept, key=lambda r: r["amount"])[0]
  12.     return {
  13.         "total": total,
  14.         "average": round(average, 2),
  15.         "biggest": biggest["id"],
  16.     }

Tests passing

Not run

Bugs the tests catch

Not run

Lines you flagged

0

Test results

Pick tests and run them. All green is not the same as no bugs.

The example table the tests use

idemailamount
A-101[email protected]120.00
A-102[email protected]80.00
A-103[email protected]40.00
B-201[email protected]60.00
C-301o'[email protected]95.00

Tests only check what someone thought to test. Reading the diff for secrets, string-built SQL and data that should not leave the function (step 5 of the review routine) finds what they miss.