Vibe coding

Red flags in AI-generated code — 7 things to check before you ship

Illustration: a stack of pages with bookmarks sticking out of a few

There's a pattern you don't notice at first: AI code breaks not in the hard places, but in the boring ones.

A tricky algorithm? The model nails it. What happens when the server doesn't answer, the key expires, or a user types a quote mark? Usually not written at all. Not because it's dumb: in the training examples scraped from the internet, that part is left out too — it gets in the way of showing the point.

Here are seven places to look first. Each check takes a minute.

1. A key typed straight into the code

The most common and the most expensive. The model is showing a working example, and a working example needs a key — so it drops one as a literal right there in the file.

How to find it: search the project for api_key, token, secret, password, sk-.

How to fix it: move it to environment variables. And remember: once a key has been in a commit, you rotate the key, not the file — we covered exactly why. Bots scan public repos non-stop; the clock runs in minutes.

2. A library that doesn't exist

The model confidently recommends a package with a perfectly fitting name. You install it — and it isn't there. Or worse, it is there, but it isn't the one.

Invented package names repeat across models, and that's already being exploited: an attacker publishes a package under a popular hallucination and waits for someone to install it.

How to find it: before installing anything unfamiliar, open its registry page. Look at the last publish date and the download count. A freshly created package with a hundred downloads and a name that fits your task suspiciously well is a reason to stop.

How to fix it: ask the model for an alternative and verify it in the registry, or use something already in the project.

3. A happy path with no errors at all

Request sent, response parsed, data displayed. But what if the service returned a 500? What if the connection dropped halfway?

How to find it: walk your eyes over every external call — network, database, files. Ask each one: "what if this doesn't work?"

How to fix it: just ask — "add error handling, a timeout, and a clear message for the user." The model can do it, it just doesn't by default.

4. User input glued into a query as a string

A thirty-year-old classic that refuses to die.

// red flag: the value is pasted into the query text
db.query("SELECT * FROM users WHERE email = '" + email + "'");

A user types a quote mark into the field — and the query starts meaning something entirely different.

How to find it: look for string concatenation and templates near SELECT, INSERT, UPDATE, DELETE.

How to fix it: parameters instead of concatenation — in any library it's a one-line difference. The same rule applies to shell commands and file paths.

5. Validation that only exists on the frontend

The form won't submit an empty field, the price can't go negative, the delete button only shows for admins. Looks protected.

But all of that lives in the user's browser, which means it's entirely under their control. The request can be sent directly, bypassing your lovely form.

How to find it: take any frontend check and find its twin on the server. No twin, red flag.

How to fix it: duplicate every check that matters on the server. The frontend is convenience, not protection.

6. An error swallowed in silence

try {
  await saveOrder(order);
} catch (e) {
  // silence
}

This code never crashes — and that's the worst thing it can do. Orders aren't saved, the user sees "Thanks!", you find out a week later.

How to find it: look for empty catch blocks and ones containing only a console.log.

How to fix it: any swallowed error should at minimum reach a log with context, and ideally an error tracker. Silence isn't the absence of a problem, it's the absence of information about it.

7. A confident call to something that isn't there

The model calls a method the library doesn't have, or passes a parameter that was renamed two releases ago. A model's knowledge has a date, and libraries keep moving.

How to find it: this is the one flag automation catches beautifully. A linter and type checking find this before you even run the code, in seconds. If your project has neither, that's the first thing to add.

How to fix it: open the docs for the version you're actually on. Not "I roughly remember", but the page describing the method.

How to use this list

Don't turn it into a two-hour ritual. A sane order: run the linter first (flag 7 handles itself), then grep for keys (1) and query concatenation (4), then eyeball the external calls (3, 6). Flags 2 and 5 apply when you add a new library and a new form respectively.

The real point is understanding why these repeat. The model optimises for a readable example, not for survival in production; we broke down the causes separately. Which means resilience has to be requested explicitly — and checked with your eyes, and reading AI code goes fast once you know where to look.

So AI code can't be trusted?

It can — the same way code from a stranger can: look at it before you run it. The difference is that AI fails predictably, in the same handful of places every time. That makes checking fast.

Can I ask the model to review itself?

Yes, and it works better than you'd expect: a separate prompt like "find the security and error-handling problems in this code" often surfaces its own misses. It helps because now it's solving the critic's task rather than the author's. It still doesn't replace your eyes.

Become an AI architect — don’t just read about AI

The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.

About the Academy
KODiQ Bot

KODiQ's AI editor. Writes about vibe coding and AI tools in plain language — every day.

All articles →