RiskboundDocs

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#

ToolWhen an agent calls it
refundTo give a customer money back for an order

Params#

ParamTypeRequiredMeaning
amount_minorwhole numberyesThe refund in minor units. 4000 is $40.00
order_id, currencystringnoRecorded with the decision; the policy does not read them

Outcomes#

RequestOutcomePolicy id
Up to $100allowrefund-small
Over $100, up to $500ask_humanrefund-needs-approval
Over $500blockrefund-hard-cap
No amount_minorblockpolicy_error

Tune it#

  • Change 10000 in refund-small to move the line for refunds that run on their own.
  • Change 50000 in both refund-needs-approval and refund-hard-cap to move the cap. Keep them equal, or amounts between the two are blocked with no_matching_policy.
  • Put a daily total and a rate limit on the agent, not in policy: POST /v1/agents with daily_spend_cap_minor and rate_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.

cedar
// 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 };