Policy conditions and a missing field
A condition is the {field, operator, value} part of a rule: it names one field of the context, an operator, and a value to compare against, and the rule fires only when that comparison is true.
Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0
The Writing a policy in a YAML file lesson matched on the action field with eq. A condition can read any field with any of ten operators, and there is one behaviour, around a field the context does not contain, worth seeing proven rather than guessed.
The ten operators
Every rule carries exactly one condition. The operator decides how the field is compared with the value.
| Operator | True when |
|---|---|
eq / ne | The field equals / does not equal the value |
gt / lt | The field is greater than / less than the value |
gte / lte | The field is at least / at most the value |
in / not_in | The field is one of / is not one of a list value |
contains | The value is contained in the field |
matches | The field matches the value as a regular expression |
Reading a number and a membership
This file denies a refund over one hundred with gt, and allows a gold or platinum customer with in. The context dictionary carries whichever fields the rules read.
version: "1.0"
name: refund-conditions
rules:
- name: big-refund
condition: {field: amount, operator: gt, value: 100}
action: deny
- name: vip
condition: {field: tier, operator: in, value: [gold, platinum]}
action: allow
defaults:
action: allowfrom agent_os.policies.schema import PolicyDocument
from agent_os.policies.evaluator import PolicyEvaluator
check = PolicyEvaluator(policies=[PolicyDocument.from_yaml("refunds.yaml")])
# each context carries only the field its rule reads
for ctx in [{"amount": 40}, {"amount": 250}, {"tier": "gold"}, {"tier": "bronze"}]:
d = check.evaluate(ctx)
print(f"{str(ctx):22} allowed={d.allowed!s:5} rule={d.matched_rule}"){'amount': 40} allowed=True rule=None
{'amount': 250} allowed=False rule=big-refund
{'tier': 'gold'} allowed=True rule=vip
{'tier': 'bronze'} allowed=True rule=NoneThe forty-unit refund matched no rule and took the allow default; the two-hundred-and-fifty refund tripped big-refund; the gold customer matched vip; the bronze customer matched nothing and fell through to the default.
A condition on a field the context does not have
Here is the part to see for yourself. This file denies an EU order with a condition on a region field. When a context has no region key, the rule does not match, so the call is not denied. It is treated as false, not as an error and not as a reason to stop.
version: "1.0"
name: region-rule
rules:
- name: needs-region
condition: {field: region, operator: eq, value: EU}
action: deny
message: EU orders are blocked
defaults:
action: allowfrom agent_os.policies.schema import PolicyDocument
from agent_os.policies.evaluator import PolicyEvaluator
check = PolicyEvaluator(policies=[PolicyDocument.from_yaml("region.yaml")])
# one context has the field the rule reads, the others do not
print("region EU :", check.evaluate({"region": "EU"}).matched_rule)
print("no region :", check.evaluate({"action": "refund"}).matched_rule)
print("region None :", check.evaluate({"region": None}).matched_rule)region EU : needs-region no region : None region None : None
What the missing field did
- With the field present and equal, the rule fired, and
needs-regiondenied the EU order. - With the field absent, the rule was skipped, so the deny never happened and the decision took the default. A missing field reads as a non-match, never as an error.
- A field present but set to
Nonereads the same as absent, because the match treats aNonevalue as nothing to compare, so that rule is skipped too.
Present, absent, or None
| The context's region field | Does needs-region fire | Decision |
|---|---|---|
"EU" | Yes, the condition is true | Denied by the rule |
| Not in the dict | No, treated as a non-match | The default decides |
Set to None | No, treated as a non-match | The default decides |
Where a condition on a field matters
- A rule that reads a numeric limit, such as a refund amount or a token count, with
gtorlte. - A rule that reads a category, such as a customer tier or a region, with
inoreq. - A rule that must see a field to deny, where you make sure the context always carries that field so the deny cannot be skipped.
Related
- Previous: Writing a policy in a YAML file
- Next: Which rule wins: priority
- Add a
matchesrule on anemailfield with a value like@example\.com$and test two addresses. - Change
big-refundtogtewith a value of 40 and watch the forty-unit refund now deny. - Evaluate
{"tier": "gold", "amount": 250}and see which of the two rules matches first.
Every expert started right here.