Policy as Code for AI Agents: Enforce the Tool Decision<
A service agent can prepare a refund for customer review. A support ticket asks it to submit the refund directly. The runtime needs an independently verified answer about the agent, the customer account, the amount, and whether an authorized person approved that exact transaction.
Policy as code expresses rules in a form software can evaluate. For an agent, the useful place to apply the decision is before a protected action takes effect. The model proposes the action. An enforcement point obtains trusted facts, asks a policy engine for a decision, and acts on the result.
| Part | Responsibility | Evidence |
|---|---|---|
| Identity and request validation | Resolve principal, delegated scope, target, action, and parameters from trusted sources | Authenticated principal and validated request |
| Policy decision | Evaluate structured facts against the current policy | Decision, rule or reason, and policy version |
| Approval workflow | Obtain human approval tied to the exact action when required | Approval identity, expiry, and action binding |
| Enforcement point | Refuse, pause, or forward the request before its side effect | Correlated tool request and downstream result |

Conceptual diagram. Refund drafted and refund submitted. The gap is the missing approval check.
OPA and Cedar solve a decision problem
Open Policy Agent (OPA) evaluates structured input and policy written in Rego. The application, gateway, or another integrated component consumes the result and enforces it. OPA documentation
Cedar evaluates authorization requests in terms of a principal, action, resource, and context. The application must supply accurate inputs and enforce the result. Choose an engine based on the policy and integration you need. A human approval workflow can complement either. Cedar documentation
Bind the decision to what actually runs

Conceptual diagram. Policy decision, approval, and enforcement.
For the refund, tie approval to the agent identity, account, amount, destination, action, and expiry. Recheck authorization at execution and after changes. Treat a changed amount or target as a new request. Use scoped downstream credentials so a route that bypasses the wrapper still meets service-side limits.
Policy evaluation depends on its inputs. Do not accept a model’s statement that a person approved the refund as approval evidence. Use a trusted approval record. Define what happens when identity, policy, or approval evidence is unavailable. For a consequential write, withhold execution and surface the reason.

Proposed checklist. Denied writes and ledger evidence.
Test the allowed path and the denials
| Test | Expected outcome |
|---|---|
| Approved refund within limit | The exact approved transaction succeeds once |
| Same approval, changed amount or account | The request is refused before submission |
| Expired approval or revoked agent grant | The request and any queued retry are refused |
| Policy service unavailable | The protected write is withheld and recorded |
| Direct call around the agent wrapper | Downstream authorization rejects the unauthorized write |
Use synthetic accounts and inspect the destination ledger as well as the authorization log. Correlate the request, policy decision, approval, and outcome without retaining unnecessary sensitive content. Repeat the tests when policy, tool schema, or execution paths change.
See Secure AI Development for the surrounding engineering controls.