Unit 03.02: Validating what the agent asked for
Arguments produced by an agent are untrusted input that happens to have arrived from inside your own system.
Shape checks and policy checks
Some checks are about type and format. Others encode a business limit, and those are the ones worth being deliberate about.
The example below validates three refund requests.
POLICY LIMITS
maximum refund 500.00
currencies USD, EUR
account format ACC- followed by digits
PROPOSED ACTION VERDICT
account ACC-1187, 240.00 USD ALLOW
account ACC-1187, 9000.00 USD BLOCK amount exceeds 500 limit
account 1187, 240.00 BTC BLOCK currency not permitted
account format wrong
The 9,000 request is a well-formed number and a well-formed account. It
fails on policy, not on shape -- which is why the limit is a written rule
and not a type.
The 9,000 request passes every type check - it is a number, it is positive, the account is well formed - and fails the policy one. That limit is not a validation detail; it is a decision about how much this automation may move, and it belongs in a written rule where an auditor can read it and a check can enforce it.
The same limit written into an instruction is a request to a component that has already been handed the amount.
The mistake this prevents
The mistake is validating types and stopping. A schema will accept a refund of ninety thousand because ninety thousand is a number. Write the ceiling separately, as data, near the top of the file.
Takeaway
Validate shape and policy as separate layers. Policy limits belong in a written rule, where they can be audited and checked.
