# Policies

A policy is your account's versioned list of rules that decides whether an agent's action, a checkout, a capture or a request is allowed, denied or sent to a person, in every product.

A policy is your account's versioned list of rules that decides whether something is allowed, denied or sent to a person for approval. Every product uses the same format: rules with `when` conditions and a `require`, saved as versions, simulated before you save and tested on live traffic before they enforce anything. You change what's allowed with no code change.

| Product | What its policy decides | Guide |
| --- | --- | --- |
| Identify | Which agents and bots get through to your site or API | [Write a traffic policy](https://provenanceauth.com/docs/identify/guides/traffic-policy.md) |
| Authorize | Whether an agent checkout is approved, challenged or rejected, and when buying from another agent needs a person | [Set your checkout rules](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md#4-set-your-checkout-rules), [seller rules](https://provenanceauth.com/docs/authorize/guides/buy-from-agents.md) |
| Attest | Whether a captured photo is approved, sent to review or rejected, and which signals a claim must carry | [Capture rules](https://provenanceauth.com/docs/attest/guides/capture-rules.md), [risk scoring](https://provenanceauth.com/docs/attest/concepts/risk-scoring.md) |
| Mandate | Whether an agent's action runs, is denied, or waits for a person's approval | [Build a policy](https://provenanceauth.com/docs/mandate/guides/policy-builder.md) |

The rest of this page uses the Mandate policy, which checks an agent's action at every verify; the other domains read their own facts with the same rules. [Domains](#domains) lists each one's path.

## When to use it

- Require a passkey or a person's approval above an amount, or for some action types.
- Deny actions outright, such as payments to counterparties outside an approved list.
- Rate-limit an agent, or hand the decision to your own service.

## How it works

1. **Your executor sends facts.** Verify reads facts from the token, from the request's `context`, and from Provenance itself, such as velocity and time.
2. **Rules run in order.** Each rule has `when` conditions (all of them, any of them or none of them, with one level of groups) and a `require`. The first rule that matches and whose requirement isn't met decides the result.
3. **Verify returns the outcome.** No failing rule means `valid: true`. Otherwise the result names the reason and the rule that decided (`policy`), or returns `approval_pending`.

1. **Facts**: token, context, velocity, time
2. **Rules, in order**: first unmet requirement decides
3. **Result**: valid, denied or approval_pending

The token checks (signature, expiry, description and payload) always run first. A condition on a fact that's missing doesn't match, so the rule doesn't apply. Accounts that never saved a policy use the default: hardware-backed devices above 500, and a passkey when `context.require_biometric` is `true`.

## Key fields

- `id` (string): Set by Provenance: `rul_` and a ULID, returned as `policy.rule.id`. Leave it out for a new rule; send it back unchanged to keep the rule across versions. See [rule ids](#rule-ids).
- `label` (string): Optional. The rule's name, such as "Large invoices". Evaluation never reads it.
- `when` (object[] | object): Conditions, each `{ fact, op, value }`. A list means all must match; `{ "match": "any", "items": [...] }` picks all, any or none (`"none"`, a NOT group) over conditions and groups. Empty matches every action. See [build a policy](https://provenanceauth.com/docs/mandate/guides/policy-builder.md#2-save-a-draft).
- `require` (object): What a matching action needs; see the table below.
- `reason` (string): Optional. Replaces the derived reason code in the result.

| `require` | Meets the rule when | Otherwise |
| --- | --- | --- |
| `biometric: true` | The approval behind the token was biometric (from Provenance's record of it, never a claim in the token) | `policy_biometric_required` |
| `hardware: true` | The approving device was hardware-attested (from the same record) | `policy_hardware_required` |
| `min_tier: "<tier>"` | The device's tier is at least `<tier>`: `simulated`, `software`, `tee`, `strongbox`, `sep` | `policy_tier_required` |
| `deny: true` | Never | `policy_denied` |
| `approval: true` | A person approved this token; add `approvers: N` for N people, and `individual: true` to keep it out of [batch approval](https://provenanceauth.com/docs/mandate/guides/batch-approvals.md) | `approval_pending`; see [step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md) |
| `webhook: "<name>"` | Your service answers `allow` | `policy_webhook_denied` |

With `approval: true`, a `route` chooses who gets the request, who it goes to next and how long it waits. It never changes what the rule requires. See [route approvals](https://provenanceauth.com/docs/mandate/guides/route-approvals.md).

### `auto_approve`

With `approval: true`, `auto_approve` holds up to 5 clauses that give the approval without a person. A clause approves when its own conditions hold, it's within its `limit`, the token isn't one of its spot checks, and no run-time guard needs a person.

The verify is then `valid`, the approval is recorded with `decided_via: "rule"`, and the ledger row carries `auto_approval`. A clause is refused where a person is always required (`auto_approve_not_allowed`). See [automate approvals](https://provenanceauth.com/docs/mandate/guides/automate-approvals.md).

```json
{
  "id": "invoices",
  "when": [{ "fact": "action_type", "op": "eq", "value": "pay_invoice" }],
  "require": {
    "approval": true,
    "auto_approve": [{
      "id": "northside-small",
      "label": "Northside invoices under $500",
      "when": [
        { "fact": "counterparty", "op": "in_list", "value": "auto_payees" },
        { "fact": "transaction_amount", "op": "lte", "value": 500 }
      ],
      "limit": { "window": "week", "max_amount": 2000 },
      "sample_rate": 20,
      "expires_at": "2027-01-29T15:00:00.000Z"
    }]
  }
}
```

### `external_confirmations`

A policy document may carry one `external_confirmations` section beside `rules`: the confirmations a person gave outside Provenance that count for your account. It is empty by default, it also governs your store's cart approvals, and it's on every plan. The issuers it lists are also the ones whose mandates cover a [checkout assessment](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md#third-party-mandates)'s cart.

```json
{
  "rules": [],
  "external_confirmations": {
    "accept": ["ap2_user_mandate", "spc"],
    "ap2_issuers": [{ "name": "Example Wallet", "jwks_url": "https://wallet.example/.well-known/jwks.json" }]
  }
}
```

- `accept` (string[]): The kinds that count: `ap2_user_mandate`, `spc`, `platform`.
- `ap2_issuers` (object[]): Required with `ap2_user_mandate`: each issuer's `name` and https `jwks_url`. Mandates are verified against these keys only. A listed wallet's mandate also covers a checkout assessment's cart, with or without `accept`.
- `acp_issuers` (object[]): ACP issuers you trust: each one's `name` and https `jwks_url`. A completion whose signed intent one of them signed covers a checkout assessment's cart.
- `platforms` (object[]): Required with `platform`: each agent platform's `name` and https `jwks_url`.

How each kind is checked: [ask once](https://provenanceauth.com/docs/authorize/guides/ask-once.md#5-accept-confirmations-given-outside-provenance).

## Facts

| Fact | Type | From |
| --- | --- | --- |
| `transaction_amount`, `action_type`, `counterparty`, and any other scalar you send | Scalar | `context` at verify |
| `require_biometric` | Boolean | `context` at verify |
| `action_description` | String | The verify request |
| `hardware_attested`, `biometric_bound` | Boolean | The approval record for the token |
| `device_trust_tier` | String | The approval record for the token |
| `payload_bound` | Boolean | Verify |
| `intent_token_age_seconds` | Number | Verify |
| `agent_id` | String | The approval record, for a [registered agent](https://provenanceauth.com/docs/mandate/guides/execution-binding.md#1-register-the-agent) |
| `hour_utc`, `weekday_utc` | Number | The verify time, in UTC (`weekday_utc` 0 is Sunday) |
| `approval.option_count`, `approval.chosen_option` | Number | The approval of a [choose-one](https://provenanceauth.com/docs/mandate/guides/offer-options.md) request |
| `approval.batched` | Boolean | An approval decided in a [batch](https://provenanceauth.com/docs/mandate/guides/batch-approvals.md) |
| `approval.group_size` | Number | A [group](https://provenanceauth.com/docs/mandate/guides/group-approvals.md) request |
| `order.amount`, `order.currency`, `order.item_count`, `order.skus`, `order.categories`, `order.channel`, … | Number, string, list | An intent whose payload is a cart, or a deal; see [route on what's in the order](https://provenanceauth.com/docs/mandate/guides/route-approvals.md#route-on-whats-in-the-order) |
| `counterparty.verified`, `counterparty.domain_verified`, `counterparty.has_record` | Boolean | A [deal](https://provenanceauth.com/docs/authorize/concepts/agent-commerce.md)'s seller (`action_type: "deal.accept"`) |
| `counterparty.deals_completed_count`, `counterparty.rating_count`, `counterparty.rating`, `counterparty.on_time_rate`, `counterparty.dispute_rate` | Number | A deal's seller; a rate or rating is absent until the seller has a record |
| `purpose.fit`, `purpose.check` | String | An action under a child grant: the pattern check (`inside`, `outside`, `untagged`) and the opt-in AI check (`consistent`, `unclear`, `inconsistent`, `unavailable`); see [keep subagents on task](https://provenanceauth.com/docs/mandate/guides/keep-subagents-on-task.md) |
| `delegation.depth`, `delegation.parent_agent`, `delegation.root` | Number, string | An action under a child grant: hand-offs from the person's grant, the agent that handed it on, and the person's grant |
| `delegation.over_limit` | String | The limit a person would be asked about (`amount`, `budget`, `dates`, `category`, `counterparty`, `block`, `uses`, `purchases`, `country`), or `none` under a child grant; see [over the limit at verify](https://provenanceauth.com/docs/mandate/guides/give-subagents-their-own-limits.md#over-the-limit-at-verify) |
| `run.depth`, `run.members_count`, `run.denials_count`, `run.out_of_scope_count` | Number | A token minted in an agent-team run; see [halt a run](https://provenanceauth.com/docs/mandate/guides/halt-a-run.md#5-let-the-run-guard-watch-the-team) |
| `network.loop_flagged` | Boolean | A deal's or tab's seller: its account trades mostly with one company or a small group, so those deals don't count toward its record |

The operators are:

| `op` | Matches when the fact |
| --- | --- |
| `eq`, `ne` | Equals, or doesn't equal, `value` |
| `gt`, `gte`, `lt`, `lte` | Compares to the number `value`; never matches a non-number |
| `in` | Is one of the array `value` |
| `matches` | Matches the glob `value`, with `*` and `?` |
| `in_list`, `not_in_list` | Is, or isn't, in the named list `value` |
| `contains`, `contains_any` | Is a list that holds `value`, or any of the array `value` |
| `is_empty`, `is_not_empty` | Is missing, `null`, an empty string or an empty list; or holds any other value. Takes `"value": true` |

Every operator except `is_empty` and `is_not_empty` doesn't match a missing or `null` fact, `ne` included. To act on a fact that isn't there, test it with `is_empty`:

```json
{ "fact": "billing.country", "op": "is_empty", "value": true }
```

A `"none"` rule or group holds when none of its conditions do, so a condition on a missing fact counts toward it:

```json
{ "match": "none", "items": [{ "fact": "billing.country", "op": "in", "value": ["US", "CA"] }] }
```

`0`, `false` and an external provider's `unavailable` answer are values, so `is_empty` doesn't match them; `if_unavailable` decides the provider case. On a request field, a path through a list (`items[].sku`) is empty when no element holds a value. Spend and request limits, canaries and probes always hold a number, so they don't take either operator.

## Try a rule

[`POST /v1/mandate/policies/simulate`](https://provenanceauth.com/docs/api/policies.md#post-v1-mandate-policies-simulate) evaluates a draft document against facts you supply, and changes nothing. Export the sandbox account key first:

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5

curl $PROVENANCE_API/v1/mandate/policies/simulate \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": { "rules": [{
      "label": "Wires over 10k denied",
      "when": [{ "fact": "action_type", "op": "eq", "value": "wire" }, { "fact": "transaction_amount", "op": "gt", "value": 10000 }],
      "require": { "deny": true }
    }] },
    "facts": { "action_type": "wire", "transaction_amount": 12000 }
  }'
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const draft = {
  rules: [{
    label: "Wires over 10k denied",
    when: [{ fact: "action_type", op: "eq", value: "wire" }, { fact: "transaction_amount", op: "gt", value: 10000 }],
    require: { deny: true },
  }],
};
const sim = await prov.mandate.policies.simulate({ document: draft, facts: { action_type: "wire", transaction_amount: 12000 } });
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
draft = {"rules": [{
    "label": "Wires over 10k denied",
    "when": [{"fact": "action_type", "op": "eq", "value": "wire"}, {"fact": "transaction_amount", "op": "gt", "value": 10000}],
    "require": {"deny": True},
}]}
sim = prov.mandate.policies.simulate(document=draft, facts={"action_type": "wire", "transaction_amount": 12000})
```

```json
{
  "object": "policy_simulation",
  "domain": "intent",
  "allowed": false,
  "reason": "policy_denied",
  "policy": {
    "id": "pol_3F9A1C7E52B04D8E6A1F27C9B4",
    "version": 0,
    "rule": {
      "id": "rul_01JD2Q8V5KX4T7M2R9B3C6D8EF",
      "name": "Wires over 10k denied",
      "phase": "assess",
      "action": "reject",
      "conditions": [
        { "fact": "action_type", "op": "eq", "value": "wire", "actual": "wire" },
        { "fact": "transaction_amount", "op": "gt", "value": 10000, "actual": 12000 }
      ]
    }
  }
}
```

`policy` is the rule that decided, the same block on every product: the policy's ID and the version that decided (0 for a draft you simulate, null for the built-in default), the rule's ID and name, its action (Approve, Challenge, Reject or Review), and each condition with the value the engine compared (`actual`). Only the deciding rule is listed. It is null when no rule decided.

## Save, roll back and reset

[`PUT /v1/mandate/policies`](https://provenanceauth.com/docs/api/policies.md#put-v1-mandate-policies) validates a document, saves it as the next version and makes it active. Versions never change once saved. Roll back by publishing an older one again with [`POST /v1/mandate/policies/versions/{version}/publish`](https://provenanceauth.com/docs/api/policies.md#post-v1-mandate-policies-versions-version-publish), or return to the default with [`DELETE /v1/mandate/policies`](https://provenanceauth.com/docs/api/policies.md#delete-v1-mandate-policies), which keeps the history.

**curl**

```bash
curl -s -X PUT $PROVENANCE_API/v1/mandate/policies \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "note": "cap wires at 10k",
    "document": { "rules": [{
      "label": "Wires over 10k denied",
      "when": [{ "fact": "action_type", "op": "eq", "value": "wire" }, { "fact": "transaction_amount", "op": "gt", "value": 10000 }],
      "require": { "deny": true }
    }] }
  }' | tee policy.json
export POLICY_VERSION=$(jq -r .version policy.json)
```

**Node**

```ts
const saved = await prov.mandate.policies.set(draft, { note: "cap wires at 10k" });
```

**Python**

```python
saved = prov.mandate.policies.set(draft, note="cap wires at 10k")
```

```json
{
  "object": "policy_version",
  "policy_id": "pol_6F2A91C04B7D3E58A1F09C2D47",
  "domain": "intent",
  "version": 1,
  "active": true,
  "note": "cap wires at 10k",
  "document": {
    "rules": [
      {
        "id": "rul_01JD2Q8V5KX4T7M2R9B3C6D8EF",
        "label": "Wires over 10k denied",
        "when": [{ "fact": "action_type", "op": "eq", "value": "wire" }, { "fact": "transaction_amount", "op": "gt", "value": 10000 }],
        "require": { "deny": true }
      }
    ]
  }
}
```

### Rule ids

Provenance sets each rule's `id`: `rul_` and a ULID, given when the rule is first saved and kept in every later version while the rule exists, so a rule id and a version name one rule text. The write returns the document as saved, with its ids; the policy itself has an `id` (`pol_…`) that stays the same on every version.

- Leave `id` out for a new rule. Send a saved rule back with its `id` to keep it.
- A `rul_` id this policy never had is replaced with a new one, so a rule copied from another account or a draft starts its own history.
- Any other `id` you send (such as one written before ids were set by Provenance) is kept on the rule as `legacy_id`, and sending it again names the same rule. A decision recorded with an old id still finds its rule.
- `rul_default_` is reserved for the default rows, which have the same ids in every account. A rule of your own can't use it (`400 policy_invalid`).

Invalid documents are refused with a `400` that points at the failing rule. A policy holds up to 50 rules of up to 10 conditions each.

## Test a version on live traffic

A shadow version runs on every verify alongside the active one, on the same facts, but never enforces anything: responses, approvals and notifications are unchanged, and the shadow's verdict is recorded on each decision. Saving activates a version, so to shadow one, return to the policy you want enforced and then mark the saved version with [`POST /v1/mandate/policies/versions/{version}/shadow`](https://provenanceauth.com/docs/api/policies.md#post-v1-mandate-policies-versions-version-shadow):

**curl**

```bash
curl -s -X DELETE $PROVENANCE_API/v1/mandate/policies \
  -H "Authorization: Bearer $PROVENANCE_KEY" > /dev/null
curl -X POST $PROVENANCE_API/v1/mandate/policies/versions/$POLICY_VERSION/shadow \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
await prov.mandate.policies.reset();
await fetch(`${process.env.PROVENANCE_API}/v1/mandate/policies/versions/${saved.version}/shadow`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` },
});
```

**Python**

```python
import httpx

api, headers = os.environ["PROVENANCE_API"], {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
prov.mandate.policies.reset()
httpx.post(f"{api}/v1/mandate/policies/versions/{saved['version']}/shadow", headers=headers)
```

```json
{ "object": "policy_version", "domain": "intent", "version": 1, "active": false, "shadow": true }
```

[`GET /v1/mandate/policies/shadow_report`](https://provenanceauth.com/docs/api/policies.md#get-v1-mandate-policies-shadow-report) then shows how the shadow compared: how many verifies it evaluated, where it disagreed with the active policy, and which decisions it would have denied. When the report looks right, activate the version. Stop shadowing with `DELETE /v1/mandate/policies/versions/{version}/shadow`. One version per domain can be the shadow.

## Lists

A list is a named set of values, such as approved suppliers, for `in_list` and `not_in_list` conditions. Lists are available on every plan, hold up to 10,000 entries, and are replaced whole on each write to [`PATCH /v1/account/policies/lists/{name}`](https://provenanceauth.com/docs/api/policy-builder.md#patch-v1-account-policies-lists-name):

**curl**

```bash
curl -X PATCH $PROVENANCE_API/v1/account/policies/lists/approved-suppliers \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "kind": "allow", "entries": ["acct_brindlecote_supplies", "acct_acme"] }'
```

**Node**

```ts
await fetch(`${process.env.PROVENANCE_API}/v1/account/policies/lists/approved-suppliers`, {
  method: "PATCH",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({ kind: "allow", entries: ["acct_brindlecote_supplies", "acct_acme"] }),
});
```

**Python**

```python
httpx.patch(f"{api}/v1/account/policies/lists/approved-suppliers", json={"kind": "allow", "entries": ["acct_brindlecote_supplies", "acct_acme"]}, headers=headers)
```

```json
{
  "object": "policy_list",
  "name": "approved-suppliers",
  "kind": "allow",
  "count": 2
}
```

A rule then reads `{ "fact": "counterparty", "op": "not_in_list", "value": "approved-suppliers" }` with `"require": { "deny": true }`.

## Advanced conditions

Velocity is on Pro and above (on every plan until 2026-11-17). Several approvers needs Enterprise. Below either, the save is refused with a `402` naming the rules.

| Construct | Plan | Shape | Use it for |
| --- | --- | --- | --- |
| Velocity | Pro | `{ "fact": "velocity", "metric", "window", "per", "op", "value" }` | Spend and request limits from the decision ledger. `metric` is `verify_count` or `amount_sum`; `window` is `1h` or `24h` (rolling) or `month` (the calendar month in UTC); `per` is `device`, `session`, `account` or `agent` (the registered agent the token names; a month counts per `account` or `agent`). Prior valid verifies count; the current one doesn't. |
| Several approvers | Enterprise | `"require": { "approval": true, "approvers": 2 }` | Actions that need that many different approvers. Each person counts once, and all of the account's API keys together count as one. A denial by any of them is final. On Pro, an [approval chain](https://provenanceauth.com/docs/mandate/guides/route-approvals.md#send-it-through-ordered-steps) step with `mode: "n_of_m"` asks several people instead. |

The policy builder's **Monthly limit per agent** template is a velocity rule: once an agent's approved spend this month reaches the amount, every further order asks.

```json
{ "id": "monthly-agent-limit", "when": [{ "fact": "velocity", "metric": "amount_sum", "window": "month", "per": "agent", "op": "gte", "value": 2000 }], "require": { "approval": true } }
```

A [policy webhook](https://provenanceauth.com/docs/mandate/guides/policy-webhooks.md) rule, `"require": { "webhook": "<name>" }`, asks your own service and needs Pro or above. Provenance posts the facts, signed like [webhooks](https://provenanceauth.com/docs/integrate/webhooks.md), and waits up to 3 seconds for its decision; no answer denies with `policy_webhook_unavailable`.

[Canary conditions](https://provenanceauth.com/docs/trace/guides/canary-policies.md) read a Trace canary score, such as `{ "fact": "canary", "set": "prompt_injection", "op": "gte", "value": 1 }`. They are on every plan, as are [Trace rules](https://provenanceauth.com/docs/trace/guides/trace-rules.md). The console's policy editor has starting templates for consumer payments, treasury, canary guardrails and agent sandboxes.

## Combine checks

Checkout, agent and Trace rules can stack weak checks. Every construct here is on every plan.

**Nested groups.** A group inside a rule's `when` can hold groups, three levels deep with the rule's own. A group can also hold when at least `n` of its items do (`"match": "at_least"`):

```json
{ "label": "Many weak signals", "when": { "match": "all", "items": [
  { "fact": "order.amount", "op": "gt", "value": 250 },
  { "match": "at_least", "n": 2, "conditions": [
    { "fact": "signal.new_device", "op": "eq", "value": true },
    { "fact": "agent.bot_score", "op": "gt", "value": 80 },
    { "fact": "customer.orders_90d", "op": "eq", "value": 0 }
  ] }
] }, "require": { "deny": true } }
```

**Signals.** A signal is a named check with no outcome. Rules read it as `signal.<key>`, true or false. A signal can read other signals; a loop is refused with `policy_cycle`. Signals, scorecards and rule groups work on checkout, agent, capture, Trace and issuer rules; on capture and issuer rules they read that rule set's own facts.

```json
{ "signals": [{ "label": "New device", "when": [{ "fact": "device.first_seen_days", "op": "lt", "value": 2 }] }] }
```

You name each signal with `label` and can rename it at any time. Its `key` comes from the first label (`new_device`) and doesn't change after that.

**Scorecards.** A scorecard adds up points from signals and checks, and rules act on the total. Each row reads a signal or its own `when` and carries points from -100 to 100. Rules read `scorecard.<key>.score` (the total) and `scorecard.<key>.matched` (how many rows matched):

```json
{ "scorecards": [{ "label": "Order risk", "rows": [
    { "signal": "new_device", "points": 25 },
    { "label": "Large order", "when": [{ "fact": "order.amount", "op": "gt", "value": 500 }], "points": 25 }
  ] }],
  "rules": [{ "label": "High risk", "when": [{ "fact": "scorecard.order_risk.score", "op": "gte", "value": 50 }], "require": { "deny": true } }] }
```

A row whose fact is unavailable follows `if_unavailable` below and adds nothing by default. When fewer rows can be read than `min_available` (all rows but one, unless you set it), the total itself is unavailable. A rule set holds up to 10 scorecards of 30 rows.

**Rule references and rule groups.** A rule can read another rule saved before, by its short id: `rule.R-103.matched` is true when that rule's conditions hold for this request, whatever decided first.

A rule group names an ordered set of rules: list it under `groups` and set `group` on each of its rules. The group's rules still run in order as ordinary rules, and `group.risk_checks.outcome` reads what they give on their own: the outcome of the first of them that matches, else `none`.

```json
{ "label": "Risk checks flagged it", "when": [{ "fact": "group.risk_checks.outcome", "op": "in", "value": ["reject", "challenge"] }], "require": { "approval": true } }
```

A rule that reads itself, or two that read each other, is refused with `policy_cycle`. A rule that approves on model-scored facts alone saves; the version's plan lists it in `approve_on_tier3_only`.

**Sub-flows.** A sub-flow is a named block of rules you keep once and run from more than one rule set: your checkout rules and your agent rules can both call "New customer checks". Create it with `POST /v1/account/policies/flows`, save its rules as a version (`POST /v1/account/policies/flows/{key}/versions`) with the facts it reads (`inputs`) and anything callers can read besides its outcome (`outputs`), then publish one. Its rules give one of the four outcomes; its outcome is the first rule that matches, else `none`.

A rule set lists the flows it calls under `flows` and reads `flow.<key>.outcome`, `flow.<key>.version` and each output, or takes the outcome as its own with `"require": { "flow": "<key>" }` (the flow's `none` passes to the next rule):

```json
{ "flows": [{ "key": "new_customer_checks" }],
  "rules": [{ "label": "New customer checks", "when": [{ "fact": "order.amount", "op": "gt", "value": 100 }], "require": { "flow": "new_customer_checks" } }] }
```

A call follows the latest version by default, so publishing a new version changes every rule set that follows it at once. Pin a rule set with `{ "key": "new_customer_checks", "follow": "pinned", "version": 3 }` to keep a version until you move the pin.

Before a version is published, each rule set that follows the latest runs its backtest with the new version (`POST /v1/account/policies/flows/{key}/versions/{version}/backtest`). When Challenge plus Reject moves by more than 5 points in any of them, publishing needs `acknowledge_rate_change: true`: one acknowledgement covers every rule set that follows, whoever publishes.

A rule set can call a sub-flow only when its domain has every input; a save or a publish that would break this is refused with `policy_flow_input_missing`, naming the facts or the rule sets.

Each decision records the versions it ran on (`flow.<key>.version` in its facts), so a replay of an old decision runs on what it ran on. Sub-flows call sub-flows up to three deep; a loop is refused with `policy_cycle` and its path. A sub-flow a published rule set calls can't be archived (`policy_flow_in_use`). Checkout and agent rules call sub-flows.

**When a fact is unavailable.** A fact your rules read can come back unavailable: a provider timed out or isn't set up. `if_unavailable` says what that means, on a condition, a rule or the whole document (`settings.if_unavailable`), the most specific first:

| Setting | What happens |
| --- | --- |
| `skip` | The condition doesn't match |
| `match` | The condition matches and the rule's outcome applies |
| `ask` | The condition matches and a person is asked instead of the rule's outcome. Issuer rules refuse it |

With no setting, a condition reads the fact as it always has. Trace rules keep `fail_closed` and `fail_open` for Trace findings.

**Spot checks.** A Reject rule rejects records nobody can label later. Turn on spot checks with `"require": { "deny": true, "sample_rate": 20 }` and 1 in 20 of the records it would reject is challenged instead, chosen from the record's id. They're off until you set `sample_rate` (2 to 100), on checkout, agent, capture and Trace rules.

A spot-checked capture goes to In review and a Trace action to Review. Trace rules at phase `completion` and issuer rules refuse spot checks, because nobody can answer in time.

**The path that decided.** When the deciding rule nests, reads a signal, a scorecard, another rule or a group, or met an unavailable fact, its `policy` block carries `trace`: the rule's path as a tree, each part with its value and whether it matched, a scorecard with its rows. Facts that were unavailable are listed in the block's `unavailable` with the reason. A flat rule's block is unchanged.

```json
"trace": { "nodes": [{ "kind": "scorecard", "key": "order_risk", "label": "Order risk", "score": 80, "op": "gte", "value": 75, "result": true,
  "rows": [{ "label": "Large order", "points": 50, "matched": true }, { "label": "Has items", "points": 30, "matched": true }] }] }
```

**Before and after on past records.** A backtest (`POST /v1/authorize/policies/backtest` and the other policies' `backtest`) replays each recent record under your live version and the draft. Beside its counts it returns `rates` (each outcome's share and order value under both, and the change in points) and `changes` (the records whose outcome would change, newest first). On checkout rules it also returns `labels`: true positive declines, false positive declines, missed and allowed for both versions, with what the draft newly stops.

**The records that would change.** A backtest of a checkout or agent policy that had records to compare is kept and returns an `id`. `GET /v1/authorize/policies/backtest/{id}/changes` pages them, newest first. The newest 20 backtests per policy are kept, with at most 500 records each.

**Publishing a tested draft.** Send `version` in place of `document` to backtest a saved draft. If that backtest moves Challenge plus Reject by more than 5 points, publishing the draft answers 409 `policy_rate_change_unacknowledged` with the change. Publish again with `acknowledge_rate_change: true`. Restoring an earlier version and starting a trial run are never asked.

A rejected order can't be disputed, so it counts as right or wrong only when a label says so; otherwise it is "No label yet". Under 20 labelled orders, `enough_labels` is false and the figures are only counts.

**Checks at save.** A save is refused when a condition names a fact no rule set can read (`policy_fact_unknown`), uses an operator that never matches the fact's type (`policy_type_mismatch`), or goes past a cap (`policy_too_large`: 50 signals, groups three levels deep). A condition kept exactly as your live version had it only warns, in the plan's `warnings`.

## Domains

Each policy domain is versioned separately and has its own path:

| Path | Decides |
| --- | --- |
| `/v1/mandate/policies` | Agent decisions, as on this page |
| `/v1/authorize/policies` | Whether an agent checkout is approved, challenged or rejected ([checkout rules](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md#4-set-your-checkout-rules)); the [seller rules](https://provenanceauth.com/docs/authorize/guides/buy-from-agents.md) templates are saved here as rules |
| `/v1/attest/risk_policies` | Attest's [risk thresholds and required signals](https://provenanceauth.com/docs/attest/concepts/risk-scoring.md) |
| `/v1/attest/capture_policies` | Whether each captured photo is approved, in review or rejected ([capture rules](https://provenanceauth.com/docs/attest/guides/capture-rules.md)) |
| `/v1/identify/policies` | Which agents and bots [Identify](https://provenanceauth.com/docs/identify/guides/traffic-policy.md) lets through |

## Related

- [Write a traffic policy](https://provenanceauth.com/docs/identify/guides/traffic-policy.md)
- [Assess an agent checkout](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md)
- [Capture rules](https://provenanceauth.com/docs/attest/guides/capture-rules.md)
- [Build a policy](https://provenanceauth.com/docs/mandate/guides/policy-builder.md)
- [Step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md)
- [Biometric approval](https://provenanceauth.com/docs/mandate/guides/biometric-approval.md)
- [Route approvals](https://provenanceauth.com/docs/mandate/guides/route-approvals.md)
- [Automate approvals](https://provenanceauth.com/docs/mandate/guides/automate-approvals.md)
- [Policy webhooks](https://provenanceauth.com/docs/mandate/guides/policy-webhooks.md)
- [Decision ledger](https://provenanceauth.com/docs/mandate/concepts/decision-ledger.md)
- [Reason codes](https://provenanceauth.com/docs/platform/reason-codes.md)
