Policy library
Policy templates
Ready-made Cedar policies for the actions agents most often get wrong. Copy one, change the limits, and load it into Riskbound.
| Template | Tools it guards | What it stops |
|---|---|---|
| refunds | refund | Large refunds. The reference policy from docs/use-case-refunds.md |
| payments | send_payment, add_payee | Large payments, money to new payees, other currencies |
| data-export | export_customer_data | Bulk exports, personal data leaving the company |
| records | bulk_update_records, delete_records | Mass changes and deletes, changes to protected tables |
send_email | Mass mail, attachments to outsiders, denied domains | |
| access | grant_access, revoke_access | Admin grants, agents granting to themselves, long grants |
| cloud-spend | provision_resource | Costly resources, GPUs, unknown regions |
| code-execution | run_code | Code outside a sandbox, known dangerous commands |
Three templates model whole support desks, for the industries where agents already handle money with customers:
| Template | Tools it guards | What it stops |
|---|---|---|
| marketplace | issue_refund, send_replacement, issue_goodwill_credit, change_delivery_address | Large refunds, refund abuse, address changes after shipping |
| food-delivery | refund_order, credit_wallet, pay_partner_incentive, cancel_order | "Not delivered" claims on delivered orders, repeat refunders, costly cancellations. Amounts in INR |
| ride-hailing | adjust_fare, waive_cancellation_fee, pay_driver_adjustment, deactivate_account | Refunds above the fare, large driver payouts, deactivation without a person |
Each folder has three files:
<name>.cedar: the policy.README.md: what it guards, the params it expects, and how to tune it.cases.json: example requests and the outcome each one must get.
How a template decides#
Riskbound has four outcomes. A policy grants one of three Cedar actions, and
Riskbound asks about them in this order (docs/adr/0002):
| Cedar action | Outcome if permitted |
|---|---|
act | allow: the action runs |
act_with_approval | ask_human: it waits for a person |
dry_run | dry_run: only the caller's dry-run handler runs. Offered only when the caller has one |
| none of them | block |
A forbid beats every permit, so a hard limit is one forbid with no
action in its scope. A forbid on Action::"act" alone sends a request to a
person instead of blocking it (see cloud-spend).
The params a guard sends become context. Riskbound adds three keys of its
own, which a request cannot overwrite: context.tool, context.agent and
context.spent_today_minor.
Rules every template follows#
- Amounts are whole numbers in minor units (
amount_minor: 48000is $480.00). Cedar has no floats, and Riskbound refuses fractions. - A missing param blocks. If a policy reads a param the request did not
send, Cedar cannot evaluate it and Riskbound blocks with
policy_error. The agent must send every param the template lists. - Every policy is scoped to its tool, so templates combine into one policy set without touching each other. Ids are unique across the library.
- No rule means block. A tool no policy mentions is blocked with
no_matching_policy.
Load a template#
A tenant has one live policy set. To use several templates, join them into
one file. These commands store a new version and make it live. They need an
admin key (npm run db:seed:dev prints one) and jq.
export RISKBOUND_ADMIN_KEY=rb_admin_...
cat policies/refunds/refunds.cedar policies/payments/payments.cedar \
| jq -Rs '{source: ., note: "refunds and payments templates"}' \
| curl -s -X POST "http://localhost:8200/v1/policies" \
-H "authorization: Bearer $RISKBOUND_ADMIN_KEY" -H 'content-type: application/json' -d @-The answer has a version. Nothing changes until you make it live:
curl -s -X POST "http://localhost:8200/v1/policies/2/activate" \
-H "authorization: Bearer $RISKBOUND_ADMIN_KEY" -H 'content-type: application/json' \
-d '{"actor": "you@example.com"}'A new version replaces the old one. Policies are never edited in place.
Try a change before it goes live#
/v1/policies/simulate answers one request against a draft and the live
policy, and records nothing:
jq -Rs '{source: ., agent: "support-bot", tool: "send_payment",
params: {amount_minor: 250000, currency: "USD", payee_is_new: true}}' \
policies/payments/payments.cedar \
| curl -s -X POST "http://localhost:8200/v1/policies/simulate" \
-H "authorization: Bearer $RISKBOUND_ADMIN_KEY" -H 'content-type: application/json' -d @-Test a template#
test/policy-templates.spec.ts runs every cases.json through the real
policy engine, alone and with all templates joined. CI runs it. After you
change a limit, change the cases to match and run:
npx vitest run test/policy-templates.spec.tsA case looks like this. reasons lists the policy ids that decided it.
dry_run_supported, spent_today_minor and agent are optional.
{
"name": "a $480 refund waits for a person",
"tool": "refund",
"params": { "amount_minor": 48000, "currency": "USD" },
"expect": { "outcome": "ask_human", "reasons": ["refund-needs-approval"] }
}What policy does not cover#
The daily spend cap and the rate limit are settings on the agent
(POST /v1/agents), not policy text, because they depend on history. Pause,
kill and the tenant kill switch also sit outside policy. All of them block
before policy is asked.