Note
Which decisions should happen before an LLM runs?
Put Deterministic Guards Before the LLM
Why identity, repetition, eligibility and lifecycle checks should run before an AI workflow spends tokens or allows the model to act.
Note
Which decisions should happen before an LLM runs?
Why identity, repetition, eligibility and lifecycle checks should run before an AI workflow spends tokens or allows the model to act.
An LLM should not be the first component that sees every problem.
Some decisions are already known, testable and cheap: whether a contact opted out, whether a message is repeating, whether a resource belongs to the current tenant, or whether a workflow has already reached a terminal state. Sending those questions to the model adds cost and uncertainty without adding useful intelligence.
The safer pattern is simple: resolve deterministic boundaries first, then let the model work inside what remains.
Models are useful when the input is ambiguous and the system needs language understanding or flexible reasoning. They are a poor replacement for invariants.
An invariant should produce the same answer for the same state. Examples include:
These rules belong in typed code with tests. Asking a model to infer them makes the most important boundary probabilistic.
The ordering matters. A guard that runs after model setup may prevent an unsafe effect, but it has already paid the latency and token cost. A guard at ingress can stop the workflow before any expensive work begins.
A practical pre-model layer can evaluate:
Each guard should return an explicit outcome, not only true or false. A
blocked identity check, legal opt-out and automated-counterpart loop are
different events. If they collapse into one generic failure, the system becomes
harder to operate and its metrics become less trustworthy.
A guard that silently returns is difficult to debug. Production boundaries should leave enough evidence to answer:
That does not mean logging sensitive input indiscriminately. It means designing an outcome taxonomy that preserves the decision without exposing data that does not belong in logs.
The difference is operationally important. "Agent failed" says very little. "Automated counterpart detected before model call" explains the outcome, the cost avoided and why the conversation closed.
There is a failure mode on the other side: turning every heuristic into a hard gate. Overly aggressive rules create false positives and prevent the model from handling the ambiguity it was introduced to solve.
Good deterministic guards have narrow responsibilities:
If a rule requires broad interpretation of language and has no stable boundary, it may belong in a classifier or model-assisted evaluation instead.
Pre-model guards reduce more than token spend. They make the system easier to reason about.
Security decisions become auditable. Safety outcomes become countable. Loops become bounded. Operators can distinguish expected termination from incidents. The model receives a smaller and cleaner problem.
The strongest guardrail is often not a longer prompt. It is a small piece of deterministic code placed before the model, with an explicit status and a test that proves where the workflow stops.