Why AI code looks right - and isn't
Understand the idea
Syntactically clean code can still encode the wrong rule. AI often optimizes for looking finished, not for being correct on your contract.
The track's central claim
This is the thesis of the track, not a side note: AI-generated code is often syntactically clean, conventionally named, and easy to skim - and still wrong for your problem. The model is rewarded for producing something that looks like working software. Your job is correctness against a contract the model does not own.
That gap is not rare bad luck. Teams shipping with assistants keep rediscovering the same shape of failure: a helper that passes the demo input, a catch that silences an error, a string check that almost means equality. The code reads like a junior engineer who memorized patterns and skipped the product rule.
AI Lab · spot the flaw
AI-generated login lookup that "works" on the demo email
Asked for a helper that finds a user by email typed into a login form. The model returned clean, familiar Array code. The demo email "ada@example.com" works. Something subtler is wrong.
javascript
function findUserByEmail(users, query) {
const normalized = String(query).trim().toLowerCase();
return users.find((user) =>
user.email.toLowerCase().includes(normalized)
);
}
// Demo that persuaded the author:
const users = [
{ id: 1, email: "ada@example.com" },
{ id: 2, email: "ada.lovelace@example.com" },
{ id: 3, email: "grace@example.com" },
];
findUserByEmail(users, "ada@example.com"); // -> user 1, looks fineWhy plausible code wins the glance test
Familiar APIs reassure you. includes, try/catch, map, and "safe" defaults are patterns you have seen in good codebases. Glance review checks shape, not intent. If you stop at shape, you rubber-stamp a of correctness - not always an invented API, often an invented rule.
| Looks fine | Hidden miss | Pressure test |
|---|---|---|
| email.includes(query) | Substring identity | Query ada against two Ada addresses |
| catch { return 0 } | Silent wrong total | Missing catalog id |
| await in a tight loop myth | Still one JS thread | Busy loop after await |
| Comment says continue | Break still aborts | Batch with two bad files |
What clean snippets commonly miss
Watch for three recurring misses. First, the demo never ran: empty input, partial matches, duplicates, slow networks. Second, security and auth boundaries stated softly in prose and implemented as convenience checks. Third, intent drift: the code solves a neighboring problem ("find a string") instead of yours ("authenticate this exact account").
None of those misses require exotic bugs. They require a model that finishes the sentence that usually appears after "users.find".
Pressure-test with your contract
Write the rule in one sentence before you read the snippet. "Login email must match exactly after lowercasing." Then choose an input that would fool a softer rule. Run that input. If the snippet fails, you found the real review. If it passes, pick a second boundary. Do not ask the same model to certify its own patch without an independent expectation.
Build a habit before you trust the patch
Treat every generated change as untrusted until a contract check says otherwise. That habit is the whole point of AI Lab in this track: judgment under realistic conditions, not another page of tips. Looking right is the model's strength. Deciding whether it is right is yours.
Mental model
FOLLOW THE VALUE
includes looks busy and correct.
01 / 03Trace the transformation
Live example
The demo shows a substring email lookup that looks ordinary and still encodes the wrong identity rule.
Your console output appears here.
Guided challenge
Name the real flaw
The third log says exact. Change it to substring to name what the helper actually does.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
ada ada@example.com substring not-exact review-me
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Make a variation, test an assumption, or break the example on purpose. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 150 XP. You can always revisit it.