Many AI features contain a model call that should have been a simple if statement.

A model sorts support requests into four types, even though the form already asks for the type. A model pulls an order number out of an email, when a regular expression would find it every time. A model decides whether a user may open a document, which is really a permission check.

These calls work in the demo. In production they slow every request down and cost money each time, and once in a while they get the answer wrong. A rule that is wrong is wrong every time, so a test finds it quickly. A model that is wrong once in fifty runs passes most tests and then fails a customer.

Four questions to ask first

Could a simple rule do this?

If a lookup table, a database query or a regular expression can do the job, use it. It is faster, it costs nothing to run, and it behaves the same way every time, so you can test it properly. Save the model for input that is too messy for rules, such as free text, scanned documents or a reply that has to be written from scratch.

What happens when the answer is wrong?

Some mistakes are cheap. A person fixes the draft, or skims past a weak summary. Others are expensive, like a wrong amount, a refund that should not have gone out, or a file shown to the wrong person. The more a mistake costs, the more you need a check in plain code after the model. Sometimes that check ends up doing all the real work, and the model only adds cost.

Can you catch a mistake before it does damage?

It is fine for a model to suggest an action and for code to check it. It is risky to let the model's answer go straight into a database write or a payment, unless you can undo it.

Can you tell whether it is working?

If nobody can say what a correct answer looks like, nobody can tell whether the model is helping. In that case, write the eval before the feature, or leave the model out until you can.

A shape that works

Keep the core of the feature in plain code. That includes the business rules, the data access and the permissions. Use the model only for the parts that really are fuzzy, like working out what an email is asking for, drafting a reply or ranking a list of options. Treat its answer as a suggestion, and have code or a person check it before anything changes.

Most agents that work well in production are built this way. They are ordinary workflows with a few model steps inside, which is the point of Most agents are workflows wearing a costume. Because the flow is code, you can read it, test it and debug it.

The problem that hides

An unnecessary model call rarely breaks in an obvious way. Responses get a little slower, the bill grows with traffic, and now and then a strange result appears. Each strange result looks like a one-off, so nobody sees the pattern. Teams usually respond by tweaking the prompt, when the better fix is to remove the call.

Removing it is often easy. For a week, log what goes into the model and what comes out. If the answers fall into a few groups that depend on a few fields, you have found the rule. Write that rule in code. Keep the model only for the cases the rule cannot handle, and send those to a person when a mistake would be costly.

Where a model is the right tool

A model is worth its cost when nothing else can do the job. Reading unstructured text, writing language, matching meaning instead of exact keywords, and handling odd requests that no rule expected are all good uses. In those cases the cost and the occasional mistake buy you something code cannot do.

Pick one feature and list every model call in it. Next to each one, write the rule that could replace it, or the reason no rule can. Start your cleanup with the calls that have a rule next to them.

Terms in this piece

About this article

Format
Article
Level
Architect
Read
3 min read
Published
Nov 6, 2026

Considered pieces on one idea.