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

Conditions on a tool's arguments

A condition on an argument reads a value the tool was called with, such as a refund amount, so a rule can allow a small refund and deny a large one from the same tool.

Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0

The Permissions that depend on the context lesson read who was asking. A condition reads any field in the context, and the arguments of a call are fields too. The Writing your own policy rules lesson in the Python part capped a refund with a function, then showed that function never runs on the gate path. A condition in the policy file does cap the amount, and it is read the same way every other rule is.

Two rules on one amount

Pass the refund amount as a field in the context and compare it with an operator. gt blocks a refund over 50; lte allows one at 50 or under. The two conditions do not overlap, so the amount alone picks the rule.

python
POLICY = """
version: "1.0"
name: refund-amount
# a refund up to 50 runs automatically; anything larger is blocked
rules:

  - name: large-refund-blocked
    condition: {field: amount, operator: gt, value: 50}
    action: deny

  - name: small-refund-ok
    condition: {field: amount, operator: lte, value: 50}
    action: allow
"""

A small refund and a large one

The shop agent decided to refund order A-2291. Run its amount through the policy twice, once small and once large, and read which rule each one matched.

ExampleThe amount, not the tool name, picks the verdict
doc = load(POLICY)
evaluator = PolicyEvaluator(policies=[doc])

# the shop agent asked for a small refund, then a very large one
for amount in [40, 4000]:
    d = evaluator.evaluate({"tool": "refund", "amount": amount})
    print(f"amount {amount:>5}  allowed={d.allowed}  rule={d.matched_rule}")

What reading the argument bought you

  • The 40 refund was allowed by small-refund-ok, whose lte condition on amount held.
  • The 4000 refund was denied by large-refund-blocked, whose gt condition matched instead. Same tool, opposite verdicts.
  • The refusal names the rule, so an audit of the blocked call shows it was the amount that stopped it, not the tool.

The operators a condition can use

OperatorHolds whenGood for
eq / neThe field equals, or does not equal, the valueA role, a tenant, a flag
gt / lt / gte / lteThe field is above or below a numberAn amount, a quantity, a count
in / not_inThe field is one of a listAn allowed set of order types
containsThe value is inside the fieldA substring in a path or a query
matchesA regular expression matches the fieldA pattern in free text

Where a condition on an argument helps

  • A cap on an amount, where a refund, a transfer or a discount over a limit is refused.
  • A bound on a quantity, such as a bulk action that may touch only so many records at once.
  • A restricted value, where a field must be one of an allowed set, checked with in.
Watch out. An operator compares whatever type the field holds. gt on a string compares text, not numbers, so pass the amount as a number, not "4000", or the comparison is lexicographic and a large string can sort below a small one. The evaluator does not coerce the type for you.
Try it yourself
  • Add a middle band: a refund over 50 but at or under 500 is audited, not denied.
  • Swap amount for a quantity field and cap how many orders one call may refund.
  • Pass the amount as the string "4000" and watch the comparison change.

Little by little, you're building something great.