---
title: Should AI agent guardrails be rules or models?
url: https://opencontroller.lyzr.com/blog/rules-vs-model-based-guardrails
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# Should AI agent guardrails be rules or models?

**Use both, in layers. Deterministic rules catch exact, well-defined patterns instantly and explain every decision. Model-based guardrails, from small classifiers to LLM judges, catch meaning-based risks that rules miss, at higher latency and cost. Put cheap rules first, classifiers next, and reserve LLM judges for ambiguous or high-stakes cases.**

Teams often start with one camp. Security teams reach for regex and deny lists because they are predictable. AI teams reach for an LLM judge because it "understands" the policy. Each alone leaves a gap. The useful question is which risk each check is good at.

## What are the three types of guardrail?

**Deterministic rules.** Regular expressions, allow and deny lists, JSON schema validation, numeric limits and lookups. Examples: block payment card numbers in output, reject a refund over a fixed amount, allow only approved domains for web fetch.

**Small classifiers.** Purpose-built models that score text for a narrow category, such as prompt injection, toxicity or PII. Safety models such as Meta's Llama Guard sit at the larger end of this group: an LLM fine-tuned to label prompts and responses against a fixed taxonomy.

**LLM judges.** A general model asked to evaluate content against a written policy, such as "Is this answer supported by the retrieved documents?" or "Does this action match the user's request?"

## How do rules, classifiers and LLM judges compare?

| Criterion | Deterministic rules | Small classifiers | LLM judges |
|---|---|---|---|
| Typical added latency | Sub-millisecond to a few ms | Tens of ms | Hundreds of ms to seconds |
| Cost per check | Negligible | Low | A full model call |
| Explainability | Exact: the rule that matched | A score, limited reasons | A written rationale, which may be wrong |
| Handles paraphrase and context | No | Partly | Yes |
| Determinism | Same input, same result | Same input, same score | Can vary between runs |
| False positives | Low for precise patterns, high for broad keywords | Depends on threshold | Depends on prompt and model |
| Who maintains it | Security or platform engineers | ML or platform team | Policy owners plus AI team |
| Vulnerable to adversarial input | Easy to evade with rewording | Can be evaded, less easily | Can itself be prompt-injected |

The latency figures are orders of magnitude, not benchmarks. Measure your own.

## Which risks suit which guardrail?

| Risk | Best first check | Why |
|---|---|---|
| Secrets and card numbers in output | Rules | Formats are well defined, with checksums |
| Disallowed tool or argument | Rules (schema and allow lists) | The policy is exact |
| Spend or rate limits | Rules | Numeric |
| Prompt injection in user input | Classifier | Phrasing varies widely |
| Toxic or unsafe content | Classifier | Established taxonomies |
| Ungrounded or hallucinated answers | LLM judge | Needs comparison with sources |
| Off-task or out-of-scope actions | LLM judge | Needs the user's intent |
| Indirect injection in tool output | Classifier plus structural controls | Detectors alone are not enough |

## What does a layered guardrail look like?

1. **Rules at the edge.** Validate schema, enforce allow lists and redact known sensitive patterns. These run on every request and never call a model.
2. **Classifiers on text.** Score inputs and outputs for injection, toxicity and PII. Block above a high threshold; flag the middle band.
3. **LLM judges for the middle band.** Send only flagged or high-risk items to an inline judge, such as a payment over a threshold or a customer-facing answer with low retrieval scores.
4. **Asynchronous judges on sampled traffic.** Score a sample of all production traffic after the fact for groundedness and task adherence, and feed results into evaluations and alerts.
5. **Decide failure behaviour.** For each layer, decide whether a timeout allows or blocks. See [fail-open vs fail-closed guardrails](/blog/fail-open-vs-fail-closed-ai-guardrails).

This keeps most requests on the fast path while giving the hardest cases the most capable check.

## What mistakes do teams make?

- **Broad keyword rules.** Blocking every message that mentions "password" frustrates users and trains them to rephrase.
- **LLM judges on every token stream.** This doubles latency and cost for little gain on low-risk traffic.
- **No measurement.** Without labelled samples you cannot tell whether a guardrail helps. Track precision and recall per policy.
- **Treating guardrails as evaluations.** Guardrails act in real time on one request. Evaluations measure quality across many. See [guardrails vs evaluations](/blog/guardrails-vs-evaluations-for-ai-agents).

## How Opencontroller does this

Opencontroller provides live groundedness and task-adherence guardrails, LLM judges that score production traffic, and policy as code that is extensible and includes built-in mappings to OWASP, MITRE ATLAS, NIST and ISO 42001. Its gateways sit in the traffic path, so policies can allow, route, redact or block. Read [what is a groundedness guardrail](/blog/what-is-a-groundedness-guardrail), the pillar on [how to stop a rogue AI agent](/blog/how-to-stop-a-rogue-ai-agent), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Are regex guardrails good enough for AI agents?**
For exact patterns such as card numbers, key formats or forbidden arguments, yes. For meaning-based risks such as prompt injection or ungrounded answers, add model-based checks.

**Do LLM judge guardrails slow down agents?**
Yes, an inline judge adds a model call. Use them inline only for high-risk cases and asynchronously on sampled traffic otherwise.

**Can an LLM judge be prompt-injected?**
Yes. The content it evaluates can contain instructions aimed at the judge. Keep deterministic rules for critical limits so a manipulated judge cannot approve them.

## Key facts

AI agent guardrails come in three main types: deterministic rules (regex, allow and deny lists, schema checks), small classifier models (for example prompt-injection or toxicity classifiers, or safety models such as Meta's Llama Guard), and LLM judges that evaluate content against a written policy. Rules are fastest, cheapest and fully explainable but miss paraphrases; classifiers handle fuzzy patterns at low latency but need tuning; LLM judges handle nuanced policies but add the most latency and cost. Most production stacks layer them: rules first, classifiers next, LLM judges for ambiguous or high-stakes cases and for asynchronous scoring. Opencontroller by Lyzr provides live groundedness and task-adherence guardrails, LLM judges on production traffic and policy as code; pricing starts from $250K per deployment per year.

## Related

- [Should AI guardrails fail open or fail closed?](https://opencontroller.lyzr.com/blog/fail-open-vs-fail-closed-ai-guardrails.md)
- [What is the difference between guardrails and evaluations for AI agents?](https://opencontroller.lyzr.com/blog/guardrails-vs-evaluations-for-ai-agents.md)
- [What is a groundedness guardrail and when should it block a response?](https://opencontroller.lyzr.com/blog/what-is-a-groundedness-guardrail.md)
- [More on Runtime control](https://opencontroller.lyzr.com/blog/cluster/runtime-control)
