Skip to content

AI engineering · 20 September 2026 · 7 min read

Code that looks safe: why AI agents hide errors, and how to make them refuse

AI coding agents love defaults, caps and fallbacks. They make code look careful and turn errors into wrong numbers nobody can trace. Here's why it happens and how we make refusing the easy path.

  • AI engineering
  • AI coding agents
  • Code review
  • Testing
  • Fintech
  • For engineers
  • For CTOs and tech leads
In this article
  1. What does "looks safe" code look like?
  2. Where have we seen it?
  3. Why is a crash better than a wrong number?
  4. Why do AI agents do this so much?
  5. How do you make refusing the easy path?
  6. Isn't refusing everything going to annoy users?
  7. Five rules for code that refuses
  8. What does this mean for your business?
  9. What should your team do first?
  10. FAQ

The short answer: AI coding agents often make code feel safer by quietly hiding errors: capping a value that's too big, defaulting a missing one, skipping one that won't parse. The code doesn't crash and the tests pass, but the error hasn't gone away. It has turned into a wrong number further down the line, where nobody can trace it back. The fix is to make refusing the default: impossible input is rejected loudly with a named error, the shortcuts that hide errors fail the build, and every exception has to be justified in writing.

It's the habit we catch most often in AI-written code, and the one most likely to slip through review, because it looks like good practice. Here's what it looks like, why agents do it, and how we stop it.

What does "looks safe" code look like?

It looks like this:

  • An amount above the limit gets capped to the limit, so the request goes through with a different number.

  • A missing price defaults to zero, so a calculation runs on nothing.

  • A name that's too long gets cut to fit the database column.

  • A counter that reaches its maximum just stays there and keeps reporting the same number.

  • A value that won't parse gets replaced with a sensible-looking fallback.

Each one reads as careful, defensive code. In a code review, most people would nod it through. That's what makes it dangerous.

Where have we seen it?

Everywhere agents write code, but here's a concentrated example. We had agents build an exploratory version of a new front end for a real-time data platform, quickly, to learn where the hard parts were. When we reviewed it, the same habit showed up again and again:

  • an event from an unknown source was shown as "live"

  • a value that wasn't a number became an invisible gap on a chart, and a missing one was silently skipped

  • a negative age, which can't happen, was quietly turned into zero

  • a missing position marker was treated as the very start

  • an unrecognised tab fell back to the first tab

  • switching to an area that didn't exist simply did nothing

Not one of those would crash. Every one of them would show a user something untrue, or nothing at all, with no sign that anything was wrong.

Why is a crash better than a wrong number?

Because a crash is honest. It tells you, immediately and in roughly the right place, that something's wrong. You fix it in an hour.

A wrong number does the opposite. It travels. A capped amount is stored, summed, reported and acted on. A defaulted price feeds a calculation that feeds a signal that someone trades on. By the time anyone notices, the cause is several steps and possibly several weeks away, and you're not looking for a bug any more. You're auditing data.

In fintech, that's the expensive kind of failure: the kind that's discovered by a customer, a reconciliation or a regulator, not by your monitoring.

Why do AI agents do this so much?

Because they're working towards code that compiles, passes its tests and doesn't fall over, and a fallback is the quickest way to make an error disappear. An agent that hits an awkward case, such as a value that might be missing, has two options. It can add a refusal, which means a new error type, handling in every caller and probably a test. Or it can add a default and move on. Left to itself, it often picks the default.

It isn't malicious, and it isn't really a flaw in any particular model. It's an agent hitting the target it was given. So the fix isn't to ask more nicely. It's to change what the target is.

How do you make refusing the easy path?

We don't leave this to judgement. Four things do the work.

Impossible input is refused, loudly. It's rejected with a named error that says what was wrong, and the caller has to deal with it. An amount over the limit is refused, never capped. Where the language allows it, impossible values can't be represented at all: a value with a valid range becomes a type whose constructor checks it, so no code can skip the check.

The shortcuts fail the build. Our linter bans the convenience methods that quietly substitute a default, or let a number stop at its maximum instead of reporting that it's run out. An agent reaching for one gets an error, not a warning.

Exceptions are written down. Sometimes capping really is correct: an estimate, a value that's floored at zero by its meaning. Those few places go on an allowlist with the reason next to each one, and a check fails the build for anything not on the list. The exception becomes a decision someone made, not a habit someone copied.

Reviewers look for it by name. "Does this hide an error?" is one of the questions every review has to answer, alongside correctness and security.

Counters get the same treatment. A number that grows over the life of a system, like a sequence, a total or an offset, grows with checked arithmetic. If it ever runs out, that's a named error that's reported, not a number that silently wraps round to zero or sticks at its maximum.

Isn't refusing everything going to annoy users?

Refusing doesn't mean showing users an error for every oddity. It means the system stops pretending. The refusal happens at the edge, where bad input arrives, and the user sees a clear message, or the screen shows that something is unavailable, instead of showing a plausible wrong answer.

It also doesn't mean defending against everything imaginable. A refusal is usually one line, in one place, and it makes errors visible. Building elaborate protection against scenarios that can't realistically happen is a different thing, and usually a mistake. Refuse what's impossible. Don't armour against what's implausible.

Five rules for code that refuses

1. Refuse impossible input with a named error

Never default, cap, truncate or quietly swallow an error just to keep a function simple.

2. Make impossible values unrepresentable

If a value has a valid range, give it a type that checks the range when it's created.

3. Ban the lenient shortcuts mechanically

Put the helpers that substitute a default, or stop a number at its maximum, on your linter's banned list. A rule an agent can't break beats a rule it's asked to remember.

4. Justify every exception in writing

Keep an allowlist for the places where capping or defaulting is genuinely right, with the reason for each.

5. Ask "does this hide an error?" in every review

Make it a named question, so it's checked every time, not when someone happens to notice.

What does this mean for your business?

For a business, a wrong number is far more expensive than a crash. A crash is noticed in minutes. A wrong number can sit in your data for weeks, and you hear about it from a customer, a reconciliation or a regulator, followed by refunds, corrections and some awkward conversations.

You can test your own systems for this without reading a line of code. Ask your team: "When something unexpected comes in, does our system refuse it, or does it guess?" In anything touching money, a system that guesses quietly is a liability. A system that refuses, clearly and early, is one you can trust.

What should your team do first?

  • Search your codebase for silent fallbacks: defaults, caps and truncation on values that matter, such as money, prices, quantities and identities. Ask of each one whether it should be an error instead.

  • Ban one lenient shortcut in your linter this week, and see how many places it catches.

  • Add the question to your review brief: "Does this change hide an error?"

  • Tell your agents explicitly that refusing is preferred over defaulting, and back it with the lint rule so it doesn't depend on them remembering.

FAQ

Why do AI coding agents add so many defaults and fallbacks? Because a fallback is the fastest way to make an error stop appearing, and agents are working towards code that runs and passes. The fix is to make refusing the easy path: named errors, a linter that bans the lenient shortcuts, and reviewers who ask whether a change hides an error.

What's wrong with defensive programming? Nothing, when it means checking inputs and refusing bad ones. The problem is "defensive" code that hides errors instead of reporting them. A default that turns a missing price into zero isn't defending anything. It's covering up a problem until it's more expensive to find.

Isn't it safer to keep the system running than to fail? Only if the system's output is still correct. A system that keeps running and produces wrong numbers is less safe than one that stops and says why, especially where money or trading decisions depend on the output.

How do you stop agents writing silent fallbacks? Don't rely on instructions alone. Ban the shortcuts in your linter, require a written reason for each exception, and have reviewers check for hidden errors by name.


We embed engineers who build software where a wrong number is expensive. If your team wants AI-written code that fails honestly, we're happy to talk.

All articles

Read something that sounds like your problem?

A free 15-minute intro with our CEO. Bring the article, and he’ll tell you which service fits, if any. If a spreadsheet and two rules would do the job, we’ll say so.