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.
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.
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}")amount 40 allowed=True rule=small-refund-ok amount 4000 allowed=False rule=large-refund-blocked
What reading the argument bought you
- The 40 refund was allowed by
small-refund-ok, whoseltecondition onamountheld. - The 4000 refund was denied by
large-refund-blocked, whosegtcondition 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
| Operator | Holds when | Good for |
|---|---|---|
eq / ne | The field equals, or does not equal, the value | A role, a tenant, a flag |
gt / lt / gte / lte | The field is above or below a number | An amount, a quantity, a count |
in / not_in | The field is one of a list | An allowed set of order types |
contains | The value is inside the field | A substring in a path or a query |
matches | A regular expression matches the field | A 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.
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.Related
- Previous: Permissions that depend on the context
- Next: Context that changes at runtime
- See also: Writing your own policy rules
- Add a middle band: a refund over 50 but at or under 500 is audited, not denied.
- Swap
amountfor 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.