Reviewing AI Code

By Syncfusion®, Inc. · Last updated

Review AI changes with a short checklist. Catch made-up APIs, off-by-one mistakes, missing edge cases, regular expressions that look right, and scope creep, without raising false alarms.

What Reviewing AI Code Means

Code review = reading a change carefully before it is accepted, to find problems.

AI code often looks clean and confident. Its mistakes are usually small and easy to miss.

The most common ones:

  • a method or package that does not exist
  • a loop or count that is off by one
  • an input nobody thought about, like an empty list
  • changes nobody asked for

In this lesson, you will learn to find each one with a short checklist.

Simple lesson: AI mistakes look like correct code. A checklist helps you look in the right places.

A Real-World Example

Think about checking a train ticket before a long trip.

  • The name looks right. But is it spelled correctly?
  • The date looks right. But is it the 14th or the 15th?
  • The train number looks right. But does that train exist on that day?

You do not read the ticket once and say "looks fine". You check each field.

Code review is the same. Each item on the checklist is one field to check.

What You Will Learn

In this lesson, you will learn:

  1. How to catch a made-up API: a method or package that does not exist.
  2. How to spot off-by-one mistakes in loops and counts.
  3. A list of edge cases to try on every change.
  4. How regular expressions can look right and still be wrong.
  5. A review checklist you can use on any AI change.

Made-Up APIs

What a Made-Up API Is

API = the functions and methods a language or library gives you.

Made-up API = a method or package the AI used that does not exist. People also call it a hallucinated API.

  • The AI saw many similar names while it was trained.
  • So it may guess a name that sounds right.
  • For example, prices.sum(). Python has sum(). JavaScript arrays do not have .sum().

Press ▶ Run tests.

  • The Tests tab: red. "prices.sum is not a function".
  • The Problems tab: the type checker already marked it. "Property 'sum' does not exist".
  • Now try: change the line to return prices.reduce((a, b) => a + b, 0); and run again. Green.

Rung 2 catches made-up methods for free.

  • Run the type checker (tsc --noEmit) on every AI change.
  • A red squiggle on a method name is often a made-up API.
  • For packages, check that the name really exists before you install it. You learn how in Security and Dependency Checks.

Simple lesson: if a method name surprises you, check that it exists.

Off by One

Off by one = a count, loop or limit that is one too many or one too few.

Where it hides:

  • < vs <= in a loop or a rule
  • starting a loop at 1 instead of 0
  • Math.floor vs Math.ceil when you count pages or boxes
  • "up to 10" vs "less than 10"

A Loop That Leaves Someone Out

Press ▶ Run tests.

  • The Tests tab: red. The bill was split into 2 shares, not 3.
  • Why: the code uses people - 1 as the length.
  • Now try: open src/split.ts and fix the length to people. Run again.

Pages That Do Not Add Up

Press ▶ Run tests. Green.

  • The test: 20 items at 10 per page is 2 pages. Correct.
  • Now try: add a test for 21 items. It should be 3 pages. Run again. Red.
  • Why: Math.floor(21 / 10) is 2. The last item has no page. It needs Math.ceil.

Animation: 21 items fill page 1 and page 2 with 10 each. One item is left over. Math.floor gives 2 pages and the last item falls off. Math.ceil gives 3 pages.

Page 1: items 1–10

Page 2: items 11–20

Page 3: item 21 Math.floor(21 / 10) = 2 → item 21 is lost Math.ceil(21 / 10) = 3 ✓

Off by one: the item that does not fill a whole page still needs a page.

Simple lesson: at every <, <=, start index and rounding call, ask "one more or one less?"

Edge Cases

Edge case = an input at the end of the normal range, or an unusual input.

The happy path is the usual input, like a cart with 3 items. Agents test the happy path well. They often miss the edges.

The Edge Case List

Try these on every change:

  1. Empty: an empty list, an empty string, no items.
  2. Zero: 0 items, ₹0, 0%.
  3. Boundary: exactly the limit, like ₹500 in "₹500 or more".
  4. Rounding: paise, like ₹10.25 or ₹33.33.
  5. Text: spaces, capitals, letters with accents like é, and symbols like ₹.
  6. Dates and time zones: midnight, month end, and users in other time zones.

Press ▶ Run tests. Green.

  • Now try: add expect(averageRating([])).toBe(0); in a new test. Run again.
  • The Tests tab: red. "expected NaN to be 0".
  • Why: 0 divided by 0 is NaN. A new product would show "NaN stars".

NaN = "not a number". JavaScript gives NaN for maths that has no answer, like 0 / 0.

A Check That Looks Right

Regular expressions are a common place for quiet mistakes.

Press ▶ Run tests, then 🐞 Plant bugs.

  • The rule: an Indian PIN code has exactly 6 digits, and the first digit is not 0.
  • The code: /\d{6}/ finds 6 digits anywhere. So abc560001 passes.
  • The Bug check tab: your 2 tests catch none of the 5 hidden bugs.
  • Now try: add tests for 'abc560001', '060001', '56000' and '5600011'. All should be false.

Simple lesson: the happy path is where the AI is strong. The edges are where you check.

Scope Creep in Review

You met scope creep in Reading an AI Diff. In review, add one question:

  • Does every changed file belong to the task?

A task to fix the GST rate should not rename a function in 14 files.

The Review Checklist

Use this list on every AI change. It goes in your verification pack at the end of the course.

  1. Diff vs summary: is every claim backed by a line?
  2. Made-up APIs: does every method and package exist? Is the type check clean?
  3. Off by one: check every <, <=, start index and rounding call.
  4. Edge cases: empty, zero, boundary, rounding, text, dates.
  5. Tests: would they fail if the code were wrong? Any weakened, deleted or skipped test?
  6. Scope: does every changed file belong to the task?

Do not raise false alarms just to be safe.

  • A false alarm is a "problem" that is not really a problem.
  • Too many false alarms waste time, and people stop listening.
  • Flag a problem only when you can say what goes wrong.

Simple lesson: a short checklist, used every time, finds more than a long read done once.

Use It at Work

  • Made-up methods: npx tsc --noEmit catches most of them before any test runs.
  • Made-up packages: npm view <name> must find the package before you install it.
  • Edges: for each changed function, try empty, zero, one, the exact boundary and a negative value.
  • Ask the agent to list them:
For each function you changed, list the edge cases (empty, zero, one, the boundary,
negative) and the test that covers each one. Mark any edge with no test.
  • Then read the list. A missing edge is your next test.

TL;DR

  1. Code review = reading a change carefully to find problems before it is accepted.
  2. Made-up API = a method or package that does not exist. The type check often catches it.
  3. Off by one = one too many or one too few. Look at <, <=, start indexes, floor and ceil.
  4. Edge case = an input at the end of the normal range:

    • empty, zero, boundary
    • rounding, text, dates
  5. NaN = "not a number", for example 0 / 0.
  6. Review checklist = diff vs summary, APIs, off by one, edges, tests, scope.

Common mistakes

MistakeWrong ideaCorrect ideaWhat goes wrong
Trusting a method name"It sounds right, so it exists."Check it, or run the type check.The code crashes at run time.
Testing only the happy path"3 items works, so it works."Try empty, zero and the boundary."NaN stars" on every new product.
Ignoring <="It is basically the same as <."One character changes the count.A person is left out of the bill.
A regex without anchors"/\d{6}/ checks 6 digits."It finds 6 digits anywhere. Use ^ and $.abc560001 is accepted.
Flagging everything"Better safe than sorry."Flag only what you can explain.Real problems get lost in noise.

Check Your Understanding

Exercises

What to Remember

  • AI mistakes look like correct code. Use a checklist.
  • Run the type check. It catches many made-up APIs.
  • At every <, <=, floor and ceil, ask "one more or one less?"
  • Try the edges: empty, zero, boundary, rounding, text, dates.
  • Flag only problems you can explain.

Further Reading

Next: Auditing AI-Written Tests. You will run mutation testing on a test suite with 95% coverage and watch mutants survive.