Verifying AI output

How to catch subtle bugs in AI-generated code quickly, write tests that prove correctness, and turn model mistakes into strong interview signal.

7 min read

At some point during an AI-assisted interview, the assistant will hand you code that looks completely reasonable and is quietly wrong. Maybe a comparison is flipped, an off-by-one skips the last grid row, or a recursive function passes small tests and blows the stack on the scaling phase. Candidates at Meta routinely report models that look great on simple warmup prompts and then slip repeatedly once constraints stack up.

Shopify's engineering leaders have even noted publicly that they like seeing an assistant produce flawed or messy code mid-round, because your reaction shows whether you actually understand the system.

A 60-second verification loop

Run this quick pass every time you bring generated code into the editor:

  1. Read every line of the diff. Flag anything you didn't ask for — extra dependencies, silent fallbacks, or refactored helpers you didn't touch.
  2. Run the tests immediately. Run the targeted suite first, then the full suite if it finishes in a second or two, and call out the numbers aloud.
  3. Probe one edge case. Either write a quick unit test or dry-run a minimal boundary case by hand.
  4. Sanity-check complexity. Ask whether the inner loop will still hold up when Phase 3 bumps the input size by 100x.

Seven bugs AI assistants produce constantly

When you scan generated code in an interview, check these seven spots first:

Failure pattern Typical example Fast way to catch it
Boundary off-by-one Skipping the final row/column, or miscounting an inclusive 7-day window Test size 0, size 1, and the exact threshold value
Hallucinated or misordered API Calling a helper method that doesn't exist, or flipping (row, col) arguments Execute the code early; never trust static reading alone
Silent input assumptions Assuming lists are sorted, non-empty, or keys are unique State the assumption aloud and test the counterexample
Hidden quadratic loops Calling list.remove(), in list, or recomputing aggregates inside a loop Trace big-O against the Phase 3 scale target
Symptom patching Hardcoding if weekday == Saturday instead of fixing the underlying calendar logic Ask "why did this fail?" before asking for a patch
Convention drift Raising raw ValueError or duplicating a store query when the repo already has custom error types and services Compare the diff against an existing sibling function
Unasked-for over-engineering Adding retry loops, logging config, or caching layers nobody requested Trim the diff back to what the current phase requires

Writing tests that actually carry weight

Existing starter tests usually cover only the happy path. Adding one or two sharp tests per phase protects you from regressions and gives interviewers clear verification signal:

  • Degenerate inputs: empty collection, single-cell grid, capacity=0, or duplicate entries.
  • Exact boundaries: the exact expiry timestamp, the rightmost cell of a row, or the exact 7-day reopen cutoff.
  • Core invariants: properties that must always hold regardless of input (e.g., every rendered maze row keeps identical width, or a merged ticket never triggers SLA alerts).

On runnable kits, Agentic Rounds grades your test suite automatically by running it against seeded bugs (mutants of the reference solution) and counting how many your own tests catch.

Turning a bad AI answer into a strong signal

When you catch a bug in generated code, walk the interviewer through three beats before fixing it:

  1. Name the defect: "This returns a valid path, not the shortest path."
  2. Explain the root cause: "It wrote a DFS with a stack instead of BFS with a queue, so the first exit it hits isn't guaranteed to be minimal."
  3. State your fix: "I'll swap this to collections.deque directly — it's five lines and avoids another prompt round trip."

That sequence hits Verification, Understanding, and Handling bad output all at once.

Practise this

Keep reading

All articles →