Policy library
Refunds
The reference template. It is the policy in docs/use-case-refunds.md, and
npm run db:seed:dev makes it live for the local support-bot agent. Every
example in examples/ runs against it.
What it guards#
| Tool | When an agent calls it |
|---|---|
refund | To give a customer money back for an order |
Params#
| Param | Type | Required | Meaning |
|---|---|---|---|
amount_minor | whole number | yes | The refund in minor units. 4000 is $40.00 |
order_id, currency | string | no | Recorded with the decision; the policy does not read them |
Outcomes#
| Request | Outcome | Policy id |
|---|---|---|
| Up to $100 | allow | refund-small |
| Over $100, up to $500 | ask_human | refund-needs-approval |
| Over $500 | block | refund-hard-cap |
No amount_minor | block | policy_error |
Tune it#
- Change
10000inrefund-smallto move the line for refunds that run on their own. - Change
50000in bothrefund-needs-approvalandrefund-hard-capto move the cap. Keep them equal, or amounts between the two are blocked withno_matching_policy. - Put a daily total and a rate limit on the agent, not in policy:
POST /v1/agentswithdaily_spend_cap_minorandrate_per_minute.
This template must stay the same as the refund policy in
scripts/seed-dev.ts and test/helpers.ts. The template test checks it.
The policy#
This is refunds.cedar as it is in the repository.
// Refunds by a support agent. The reference policy from
// docs/use-case-refunds.md, and the one `npm run db:seed:dev` makes live.
//
// Tool: refund
// Params: amount_minor (whole number, minor units such as cents)
//
// up to $100 allow
// over $100 to $500 ask a human
// over $500 block
@id("refund-small")
permit (principal, action == Action::"act", resource == Tool::"refund")
when { context.amount_minor <= 10000 };
@id("refund-needs-approval")
permit (principal, action == Action::"act_with_approval", resource == Tool::"refund")
when { context.amount_minor <= 50000 };
@id("refund-hard-cap")
forbid (principal, action, resource == Tool::"refund")
when { context.amount_minor > 50000 };