AI
Rules vs AI automation: when to stay deterministic, and how to hybridize the rest

· 5 min read
When should you use fixed rules instead of AI, and how do you combine the two?
If a fixed fact can decide the outcome, and it costs less to write a rule than to run a model, I keep AI out of it. For the cases a rule can't cover, I use AI as a tiebreaker, and I configure that part so it behaves as consistently as a language model can.
Earlier this year we were sorting a client's inbox. The first version let an AI model decide which folder each message belonged in. It started putting real replies into junk. We told it not to junk mail from certain senders, and it still did, because the model was still the one making the call.
The fix was not a better prompt. It was to stop asking the model to do work a rule could do. Fixed rules ran first. AI only saw the mail those rules couldn't classify. That inbox is a clear picture of a choice I make on a lot of builds: when should a step be deterministic, when should it be probabilistic, and if you use a model, how do you keep it on a short leash?
When a rule is the better tool
If a fixed fact decides the outcome, and the economics favor it, build it as a rule and keep AI out.
A rule is deterministic. The same input gives the same output every time. If this sender always goes in this folder, that's a rule. A language model is probabilistic. It is choosing a likely next answer, not looking up a fact. Ask it the same question twice and you can get two different results, especially as the prompt, the model, or the surrounding text changes. That's drift. A rule doesn't drift.
The economics are what decide whether it's worth writing the rule. I look at four things.
Cost per run. A rule is a comparison. It costs almost nothing and finishes immediately. A model call costs money and adds time, every single time the step runs. If this decision happens on every incoming email, every invoice, every new row, that adds up.
Error cost. What happens when the step is wrong? Filing a newsletter in the wrong folder is annoying. Filing a reply from someone you're actively talking to into junk is a real loss. When the mistake is expensive and you can write a rule, the rule is the cheaper system, even if it takes longer to set up.
Maintenance. A rule list has to be updated when a new sender appears. That's real work. The trade is that you can read the list, explain it, and test it. A model can look cheaper because it "just figures it out," until you can't say why it filed something, and you can't prove it won't do it again.
Speed. Rules are fast. If the rest of the workflow is waiting on a classification, I don't pay a model delay for a decision that was already knowable.
When the economics don't favor a pure rule is equally clear. If the wording changes from one vendor to the next, and you'd spend weeks enumerating phrases you'll never finish, a model is doing work a list can't do. That's the leftover, not the default.
Rules first, AI as a tiebreaker
The hybrid I use is simple. Rules decide first. AI handles only the leftover ambiguous cases, as a tiebreaker, and I keep it away from anything destructive.
On that inbox, we rebuilt the sorter around lists of senders and domains the client confirmed. Mail from this address goes here. Mail from this domain goes there. A reply in an active conversation stays out of junk. Those are facts, so they became rules.
AI was reserved for the cases the lists couldn't settle, like whether a message was actually a payment notice when the wording changed from one vendor to the next. And it was kept off the high-cost actions. It was not allowed to decide that something was junk. A client's email can sound promotional, or use a phrase the model associates with spam, and still be a real person you cannot afford to miss. If that message lands in junk and sits there, a lot of mail hosts will delete it after about 30 days. So junk, and anything else that's hard to undo, stays on rules. If no rule matches, the safer default is to leave it in the inbox for a person to see.
That's the guardrail I want on a hybrid. The model can classify the leftover. It doesn't get to take the action that disappears work, spends money, or emails a customer without a check.
How I make the AI part more consistent
You can't make a language model fully deterministic. You can make it a lot more consistent, and a lot easier to control.
I turn the temperature down. A lower temperature makes the model less likely to wander. Setting it to zero gets you closer to the same answer each time, but it is not a guarantee. Under the hood there is still some variation, so I treat temperature as a consistency control, not as a lock.
I don't let it answer in free prose when the step is a classification. I ask for structured output, usually JSON, with a fixed set of labels. The model has to pick from the folders I already defined, or return "unknown." It doesn't get to invent a new category.
I give it one job per step, and a narrow prompt to match. If the step is "is this a payment notice or not," that's the whole job. I don't also ask it to rewrite the subject, guess the priority, and decide whether to junk the message. One job is easier to test, and when it fails you can see which job failed.
A few examples of the borderline cases help more than a long explanation. I show it two or three real messages that almost belong in two folders, and the label I want. That's usually enough to steer the leftovers without stuffing the prompt with rules that should have been actual rules.
I also set a threshold for "not sure." If the model is on the fence, it doesn't act. The step falls back to a rule, or to a person. I don't treat a high confidence score as proof it's right. Models are often sure when they're wrong. The useful part of a threshold is the low end: when it hesitates, stop.
Then a check runs on whatever it hands back, no AI involved. Is the label one of the allowed ones? Are the required fields there? If not, the output doesn't go through. I put a yes-or-no check after every AI step for the same reason. The model can guess. The gate in front of the rest of the system is a rule.
And I log it. What came in, whether a rule fired or the model did, what it returned. When the same leftover shows up a few times, it shouldn't stay a leftover. It should become a rule.
The point isn't to avoid AI. It's to spend it where a guess is actually needed, and to keep the rest of the system on rails you can inspect, replay, and trust.