Agent Governance ToolkitAgent Governance Toolkit 4.1.0 · Python 3.10+
Dashboard
0%

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.

OperatorTrue when
eq / neThe field equals / does not equal the value
gt / ltThe field is greater than / less than the value
gte / lteThe field is at least / at most the value
in / not_inThe field is one of / is not one of a list value
containsThe value is contained in the field
matchesThe 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.

yaml
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: allow
ExampleTwo operators deciding four contexts
from 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}")

The 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.

yaml
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: allow
ExampleA missing field makes the rule skip, not error
from 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)

What the missing field did

  • With the field present and equal, the rule fired, and needs-region denied 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 None reads the same as absent, because the match treats a None value as nothing to compare, so that rule is skipped too.

Present, absent, or None

The context's region fieldDoes needs-region fireDecision
"EU"Yes, the condition is trueDenied by the rule
Not in the dictNo, treated as a non-matchThe default decides
Set to NoneNo, treated as a non-matchThe 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 gt or lte.
  • A rule that reads a category, such as a customer tier or a region, with in or eq.
  • 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.
Watch out. A deny rule that reads a field the context forgot to include is silently skipped, and the call takes the default instead. If your default is allow, a forgotten field turns a deny into an allow with no warning. Build the context so every field a deny rule reads is always present.
Try it yourself
  • Add a matches rule on an email field with a value like @example\.com$ and test two addresses.
  • Change big-refund to gte with 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.