Are you an LLM? You can read better optimized documentation at /docs/agent-guard/policies/evaluation-and-ordering.md for this page in Markdown format
Evaluation and ordering
One policy on its own is easy to reason about: the rules run, and if any assertion is false the action fires. Load a second policy, or add a pre-built tier alongside your own, and order starts to matter. This page covers how the engine picks policies, what each action does when a rule fails, and where ordering changes the outcome.
How a request is evaluated
For each request the engine selects every policy of the matching kind whose match block applies, sorts them alphabetically by metadata.name, and evaluates them in that order. Within a policy, every rule is evaluated; if any rule's assertion returns false, the policy's action fires.
Sorting is by name, not by file, directory, or the order sources were added. Two policies from different bundles interleave according to their names.
| Action | All rules pass | A rule fails |
|---|---|---|
Enforce | continue | Violation collected. The request is denied after all policies have run |
Audit | continue | Violation logged. The request continues |
Elicit | continue | Short-circuits immediately. Marked for operator approval |
Redact | continue | Violation collected. Content is masked after all policies have run, unless an Enforce policy failed |
Enforce deliberately does not short-circuit. Every applicable policy runs, and every denial is collected, so an operator sees all the reasons a request failed rather than whichever one happened to sort first.
Fail-closed, including in Audit
An evaluation error denies the request. This holds inside an Audit policy too: an Audit rule that throws does not log and continue, it denies. A rule that crashes never becomes a rule that passes.
The practical consequence is that Audit is safe for deciding nothing, but not automatically safe for touching anything. An Audit rule reading a field that might be absent still blocks the request when that field is missing. Guard fields in audit rules exactly as you would in enforcing ones — see Writing rules.
Why Elicit stops evaluation
The engine returns one decision per request, and the actions differ in whether they can still be combined with another one afterwards.
Enforce and Audit can. Both leave the request exactly as it was: a denial adds a reason, an audit entry adds a log line, and neither changes the data any later policy will look at. Collecting more of them only gives the operator a fuller picture, which is why Enforce keeps going and reports every violation rather than the first.
Elicit cannot, because it suspends the request pending a human decision whose outcome is not known yet. There is no verdict to combine with, because whether this request proceeds at all is still open. So the engine stops and returns what it has.
Two consequences follow, both for ToolPolicy, the only kind with Elicit.
An audit policy that sorts after an Elicit policy records nothing for the calls it elicits. Those are the calls most worth reviewing.
An Elicit policy can suppress an Enforce policy from another bundle. If your policy sorts before a tier's Enforce policy and fires, the tier's policy never runs, and its specific message never reaches the operator. You get your generic prompt instead of the tier's precise reason.
Redact waits for every policy
Redact changes the data, so a mask decided early could hide content a later policy would have blocked. The engine avoids that by not deciding early. Every GuardrailPolicy runs, and the engine settles the outcome after the last one:
- If any
Enforcepolicy failed, the request is denied. The content is not forwarded, so there is nothing to mask. - Otherwise, if any
Redactpolicy failed, the matches from every failingRedactpolicy are masked together and the request is forwarded. What gets masked is described under Content inputs.
A block beats a mask whatever the policies are named, so a Redact rule needs no knowledge of the blocking tier:
yaml
apiVersion: gerty.jozu.dev/v1
kind: GuardrailPolicy
metadata:
name: z1-contact-and-demographic-detail
spec:
guardrails:
- "*"
direction: input
action: Redact
rules:
- name: mask-phone-numbers
assert: |
!(guardrail.content.canonical.matches("[(]?[0-9]{3}[)]?[- .][0-9]{3}[- .][0-9]{4}") ||
guardrail.content.files.matches("[(]?[0-9]{3}[)]?[- .][0-9]{3}[- .][0-9]{4}"))
message: "Phone number masked before the request left the boundary."A message carrying a phone number is forwarded with the number masked. A message carrying a phone number and a Social Security number, with an Enforce policy on the SSN loaded alongside, is denied, and the denial names the SSN policy.
The naming convention
Because ordering is alphabetical and Elicit ends evaluation, policy names are load-bearing. Group them by action with a sortable prefix, additive actions first:
| Prefix | Action | Why there |
|---|---|---|
00- | Audit | Runs first, so every request reaches the audit record, including ones later elicited |
01- … 06- | Enforce | Denials are always collected, and running before the short-circuiting Elicit keeps them that way |
z1- … z3- | Elicit, Redact | An Elicit policy here cannot pre-empt an Enforce policy, including one from a bundle loaded alongside yours. Redact sorts here by convention only; its position does not change the outcome |
Getting this wrong fails quietly rather than loudly. Nothing errors; the audit trail is simply missing its most interesting entries, or an operator sees a vague prompt where a specific denial was expected.
Composing bundles
Policy sources are additive. Adding a bundle does not replace what you already have, so a tier plus your own policies means both are loaded and both evaluate.
Before adding a second source, check two things:
- Where its policy names sort relative to yours, especially if either uses
Elicit - Whether its actions overlap with yours on the same operations, which usually means one of them never gets to speak
agentguard policy list shows the sources you have loaded. The bundle contents are the authoritative list of what is in each.
