# Get rule suggestions

Report what happened to your orders, then review checkout rule drafts built from them, each with its evidence and a backtest, and try one in shadow mode before you publish it.

Use rule suggestions to find checkout rules your own orders argue for. Provenance looks for groups of orders where chargebacks, fraud and other bad outcomes cluster, and drafts up to three rules from them. Each draft comes with the numbers behind it and a backtest over your last 30 days. Nothing changes until a person tries the draft in shadow mode and publishes it.

**Before you begin:** a store sending orders to Provenance ([assess checkouts](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md) or [hold Shopify orders](https://provenanceauth.com/docs/authorize/guides/shopify.md)), and a key with the `authorize` scope. Rule drafts are on the Pro plan and above, with a few drafts during the Free trial; the monthly draft limit per plan is on the [pricing page](https://provenanceauth.com/pricing). An owner or admin turns the assist on first, in **Account → AI assists** ([AI assists](https://provenanceauth.com/docs/account/ai-assists.md)).

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

## How a draft is made

Statistics compute every number; a model only picks and names.

| Step | Who does it | What happens |
| --- | --- | --- |
| Label orders | Statistics | Each order in the last 90 days gets the worst label its sources give (below). |
| Check the floor | Statistics | At least 200 orders spanning at least 2 weeks, with at least 5 disputed or flagged. Below it, nothing is sent to the model. |
| Find groups | Statistics | Groups of orders that share one to three facts, each with at least 10 orders and 5 disputed or flagged, ranked by how far their rate sits above your overall rate. The top 30 go to the model as counts. |
| Draft | The model | Picks up to three groups that make sensible rules, writes each as conditions and an action, and adds a label and an explanation. |
| Check | Statistics | Every fact, operator and value must be in your catalog and the values you've seen. The evidence is counted again on your orders, and the draft is backtested against your live rules. A draft that fails any check is dropped. |

The model's explanation is shown under a fixed line: "Written by a model from these numbers. The numbers and the backtest are the source of truth." An explanation that names a number the evidence doesn't hold, or any address, link or id, is replaced by a sentence built from the evidence (`explanation_source: "template"`).

A draft is marked `limited_data` until your account has 500 orders over the last 30 days. Treat a draft with limited data as a lead to check, and lean on its backtest.

## 1. Report what happened to orders

Drafts learn from outcomes. Some reach Provenance on their own; report the rest on the assessment or the store order.

| Label | Where it comes from | Counts as |
| --- | --- | --- |
| `chargeback` | A reported outcome, a chargeback matched to the order, or an evidence pack made for it | disputed |
| `fraud` | A reported outcome, or a network fraud report you filed on the order's token or agent within 30 days | disputed |
| `refund_abuse` | A reported outcome, or refunds on your connected Stripe account or Shopify shop that repeat for the same shopper or agent (three in 90 days) | flagged |
| `customer_denied` | The customer denied the cart approval | flagged |
| `store_rejected` | Your store rejected the order in review, or staff cancelled a held store order | flagged |
| `legitimate` | A reported outcome. It clears the flagged labels, never a chargeback or fraud | clean |

Report any label whose source includes a reported outcome, with an optional `note` of up to 280 characters. The latest report on an order wins and every report is kept. Reporting is free. Here an order is assessed and then reported as a chargeback:

**curl**

```bash
export ASSESSMENT_ID=$(curl -s -X POST $PROVENANCE_API/v1/authorize/checkout_assessments \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cart":{"order_id":"ord_8813","total":42000,"currency":"USD","merchant_id":"harborbean","origin":"https://harborbean.example","items":[{"sku":"grinder-pro","name":"Burr grinder","quantity":1,"unit_amount":42000}]}}' | jq -r .id)
curl -s -X POST $PROVENANCE_API/v1/authorize/checkout_assessments/$ASSESSMENT_ID/outcome \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"outcome":"chargeback","note":"Card holder disputed the charge"}'
```

**Node**

```ts
const api = process.env.PROVENANCE_API;
const headers = { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" };
const assessment = await (await fetch(`${api}/v1/authorize/checkout_assessments`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    cart: {
      order_id: "ord_8813", total: 42000, currency: "USD", merchant_id: "harborbean", origin: "https://harborbean.example",
      items: [{ sku: "grinder-pro", name: "Burr grinder", quantity: 1, unit_amount: 42000 }],
    },
  }),
})).json();
const outcome = await (await fetch(`${api}/v1/authorize/checkout_assessments/${assessment.id}/outcome`, {
  method: "POST",
  headers,
  body: JSON.stringify({ outcome: "chargeback", note: "Card holder disputed the charge" }),
})).json();
```

**Python**

```python
import os, httpx

api = os.environ["PROVENANCE_API"]
headers = {"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}
assessment = httpx.post(f"{api}/v1/authorize/checkout_assessments", headers=headers, json={
    "cart": {"order_id": "ord_8813", "total": 42000, "currency": "USD", "merchant_id": "harborbean",
             "origin": "https://harborbean.example",
             "items": [{"sku": "grinder-pro", "name": "Burr grinder", "quantity": 1, "unit_amount": 42000}]},
}).json()
outcome = httpx.post(f"{api}/v1/authorize/checkout_assessments/{assessment['id']}/outcome", headers=headers,
                     json={"outcome": "chargeback", "note": "Card holder disputed the charge"}).json()
```

```json
{
  "object": "order_outcome",
  "id": "oot_01M81B2Q7ZC4D8F2H6K0N4R8T2",
  "assessment_id": "cas_01M81B2Q6XW3B7E1G5J9M3Q7S1",
  "store_order_id": null,
  "outcome": "chargeback",
  "kind": "disputed",
  "source": "api",
  "note": "Card holder disputed the charge",
  "reported_at": "2026-11-22T10:02:11.204Z"
}
```

For a store order, send the same body to `POST /v1/authorize/store_orders/{id}/outcome`. To report one outcome on up to 100 orders, send `{ "outcome": "fraud", "ids": [...] }` to [`POST /v1/authorize/order_outcome_batches`](https://provenanceauth.com/docs/api/assessments.md#post-v1-authorize-order-outcome-batches); it answers once per ID. Another account's order answers `404`.

### How an order ended

You rarely need to report anything. Each checkout assessment and store order carries `ending`: how the order ended, worked out from what Provenance heard, with where it came from.

```json
{ "ending": { "outcome": "legitimate", "source": "quiet_period", "at": "2026-11-20T15:04:11.000Z" } }
```

| `source` | What it means |
| --- | --- |
| `chargeback` | A dispute on your connected payment account matched the order |
| `network_report` | A fraud report you filed on the order's token or its agent |
| `refund` | A refund on your connected Stripe account or Shopify shop: `refunded`, or `refund_abuse` when refunds repeat for the same shopper or agent |
| `approval_denied` | The shopper declined |
| `staff_cancel` | Your review rejected it, or staff cancelled a held order |
| `quiet_period` | The order went ahead, your payment connection was listening, and 14 days passed with no dispute or refund: `legitimate` |
| `reported` | An outcome you reported |

`ending` is `null` while nothing is known: an order under 14 days old, or a store with no payment connection. The worst wins, so a later chargeback replaces a quiet `legitimate`, and a report never clears a chargeback or fraud. It is a reading only: it changes nothing about the order, the guarantee or a chargeback response.

In the console, an order's detail shows **How it ended** with **Change** for a correction, and the Orders list has **Set how it ended** for the rows you tick.

## 2. Get drafts

The nightly job drafts for every account with the assist on. To draft now, refresh; it runs once a day, and each draft shown counts toward your monthly limit.

> **Note: These calls need the assist on**
>
> The sandbox has no model provider, so the requests below answer `503 ai_assist_unconfigured` there. The responses shown come from a test provider.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/policies/rule_suggestions/refresh \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const refresh = await (await fetch(`${process.env.PROVENANCE_API}/v1/authorize/policies/rule_suggestions/refresh`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` },
})).json();
```

**Python**

```python
import os, httpx

refresh = httpx.post(f"{os.environ['PROVENANCE_API']}/v1/authorize/policies/rule_suggestions/refresh",
                     headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}).json()
```

```json
{
  "object": "rule_suggestion_refresh",
  "domain": "checkout",
  "result": "drafted",
  "created": 1,
  "open": [
    {
      "object": "authorize_rule_suggestion",
      "id": "prs_01M81AY7FHVYNM5DWABPYQWC9W",
      "domain": "checkout",
      "status": "open",
      "label": "First-time agent orders",
      "rule": {
        "id": "draft-c52be145f4",
        "label": "First-time agent orders",
        "when": [
          { "fact": "store.agent_order", "op": "eq", "value": true },
          { "fact": "store.customer_order_count", "op": "eq", "value": 0 }
        ],
        "require": { "approval": true }
      },
      "action": "ask",
      "description": "If all of: Placed by an AI agent is true; and Customer's past orders is 0, then challenge the shopper",
      "explanation": "12 of 24 orders in this group were flagged or disputed, against 6% of all orders.",
      "explanation_source": "model",
      "explanation_label": "Written by a model from these numbers. The numbers and the backtest are the source of truth.",
      "evidence": {
        "orders": 24,
        "flagged": 12,
        "disputed": 12,
        "rate": 0.5,
        "baseline_rate": 0.0577,
        "total_orders": 260,
        "total_flagged": 15,
        "window_from": "2026-08-24T09:56:00.600Z",
        "window_to": "2026-11-22T09:56:00.600Z",
        "by_label": { "fraud": 12 },
        "flagged_caught": 12
      },
      "backtest": {
        "object": "policy_backtest",
        "days": 30,
        "requests": 260,
        "totals": { "allowed": 236, "challenged": 24, "rejected": 0 },
        "rules": [
          { "rule_id": "draft-c52be145f4", "label": "First-time agent orders", "outcome": "ask", "matched": 24, "decided": 24, "per_week": 5.6, "summary": "Last 30 days: would have challenged 24 times, about 6 a week" }
        ]
      },
      "limited_data": true,
      "policy_version": null,
      "shadow_version": null,
      "published_version": null,
      "dismissed_until": null,
      "created_at": "2026-11-22T09:56:00.600Z",
      "updated_at": "2026-11-22T09:56:00.600Z"
    }
  ]
}
```

`result` says what the run did:

| `result` | Meaning |
| --- | --- |
| `drafted` | At least one new draft passed every check (`created` counts them). |
| `no_draft` | The run found nothing that passed, or the model proposed nothing. |
| `below_floor` | Fewer than 200 orders, under 2 weeks of orders, or fewer than 5 disputed or flagged. Nothing was sent. |
| `cap_reached` | Your monthly draft limit is used. Drafts resume on the first of next month. |
| `budget_reached` | The deployment's model budget for the day is used. Try again tomorrow. |
| `error` | The model call failed. No draft is shown, and nothing partial is kept. |

`open` lists the open drafts, at most three per policy. List every suggestion with `GET /v1/authorize/policies/rule_suggestions` (open, shadowed and the last 90 days; filter with `?status=`), or read one with `GET /v1/authorize/policies/rule_suggestions/{id}`.

### Suggestions runs: rules, signals and scorecards

A Suggestions run goes further than the drafts above. It reads your live rule set, and the writing model looks for patterns with read-only SQL over your own order decisions (at most 20 queries a run). It sees grouped counts and sums, never an order or a personal column. It drafts up to five candidates: a new rule, signal or scorecard, or a change to one you have. A suggestion never approves orders.

Each candidate is put into your rule set and checked as a save would be. Then it is tested with a read-only query over the last 90 days of orders, and the query's text is kept in `test.sql` for you to read. A candidate is kept only when it adds at least 5 true positive declines and no more false positive declines than true ones.

A kept one also carries `replay`: your live rules and the draft replayed over the last 30 days, with the four labelled results and their value. Suggestions keep counts only, never order ids.

| Call | What it does |
| --- | --- |
| `GET /v1/authorize/policies/rule_suggestions/settings` | The pace, when the next run is due, and the "Run now" left this month. |
| `PATCH /v1/authorize/policies/rule_suggestions/settings` | Set the pace: `daily`, `weekly` (the default), `biweekly`, `monthly` or `off`. |
| `POST /v1/authorize/policies/rule_suggestions/runs` | Run now. Four a month; after that, `429` until next month, and the scheduled runs go on. |
| `GET /v1/authorize/policies/rule_suggestions/runs` | The last runs: result, reason, queries, what was kept and dropped. |

We pay for runs, scheduled or not, so they don't count toward your monthly drafts. A run needs at least 200 orders across 14 days (`below_floor` otherwise). If the model or the query layer can't be reached, the run ends `unavailable` with the reason and stores nothing. Findings you send from an [investigation](https://provenanceauth.com/docs/account/investigations.md) go through the same test.

## 3. Read a draft

| Field | What it says |
| --- | --- |
| `rule`, `description`, `action` | The rule as it would be written into your policy, the same rule in words, and its action. |
| `evidence` | Counted on your orders over the last 90 days: how many the rule matches (`orders`), how many were disputed or flagged, their rate against your overall rate (`baseline_rate`), and the counts per label. |
| `backtest` | Your live rules plus this one, replayed over the last 30 days: what it would have challenged, rejected or allowed. |
| `explanation`, `explanation_source` | Why the rule may help, from the model (`model`) or from the evidence (`template`). |
| `limited_data` | True until your account has 500 orders over the last 30 days. |
| `warning` | Present on a draft that rejects or blocks (below). |

A draft may propose any action, rejecting included. A rejected customer can't show you what they would have done next, so shadow mode can't tell you how many good orders a reject rule would lose. A draft that rejects carries `warning` saying so; read its evidence before you shadow it.

## 4. Try it in shadow mode

Shadowing creates a draft version of your policy (your live rules plus this one) and runs it in shadow beside the live version. Live decisions don't change.

**curl**

```bash norun
curl -s -X POST $PROVENANCE_API/v1/authorize/policies/rule_suggestions/prs_01M81AY7FHVYNM5DWABPYQWC9W/shadow \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const shadowed = await (await fetch(`${process.env.PROVENANCE_API}/v1/authorize/policies/rule_suggestions/prs_01M81AY7FHVYNM5DWABPYQWC9W/shadow`, {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` },
})).json();
```

**Python**

```python
import os, httpx

shadowed = httpx.post(
    f"{os.environ['PROVENANCE_API']}/v1/authorize/policies/rule_suggestions/prs_01M81AY7FHVYNM5DWABPYQWC9W/shadow",
    headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
).json()
```

```json
{
  "object": "authorize_rule_suggestion",
  "id": "prs_01M81AY7FHVYNM5DWABPYQWC9W",
  "status": "shadowed",
  "policy_version": null,
  "shadow_version": 1,
  "published_version": null
}
```

To change the draft first, open it in the console's rule editor from its suggestion card under **Rules**, edit it, and shadow the edited version. Read how often the shadow version disagreed with the live one in the shadow report (`GET /v1/authorize/policies/shadow_report`).

## 5. Publish it

Going live is the same publish as for any version: `POST /v1/authorize/policies/versions/{version}/publish` with the suggestion's `shadow_version`. The publish is recorded and sends `authorize.policy.published`, and the suggestion moves to `published`.

If the draft isn't useful, dismiss it with `POST /v1/authorize/policies/rule_suggestions/{id}/dismiss`. It is hidden for 90 days, and the same rule isn't suggested again in that time. An open draft older than 30 days, or one computed against a version that has since been replaced, is checked again by the next run and expires if it fails the checks.

When a draft is created, `authorize.rule_suggestion.created` is sent to your webhook endpoints with the rule, the evidence counts and the backtest totals. Dismissing or shadowing sends nothing.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `503` [`ai_assist_unconfigured`](https://provenanceauth.com/docs/platform/errors.md#ai_assist_unconfigured) | This deployment has no model provider | Nothing to fix on your side; reported outcomes still work. |
| `403` [`ai_assist_off`](https://provenanceauth.com/docs/platform/errors.md#ai_assist_off) | The checkout assist is off for your account | An owner or admin turns it on in **Account → AI assists**. |
| `402` [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required) | Rule drafts are on the Pro plan and above, and your Free trial has ended | Choose a plan in **Settings → Plan & usage**. |
| `429` [`rate_limit_exceeded`](https://provenanceauth.com/docs/platform/errors.md#rate_limit_exceeded) | A refresh already ran today, or "Run now" was used four times this month | Wait for `Retry-After`; the scheduled runs still come. |
| `404` [`resource_missing`](https://provenanceauth.com/docs/platform/errors.md#resource_missing) | No such suggestion, assessment or store order on your account | Check the id. |

## See also

- [Traffic rule suggestions](https://provenanceauth.com/docs/identify/guides/traffic-rule-suggestions.md): the same drafts for your traffic policy
- [AI assists](https://provenanceauth.com/docs/account/ai-assists.md): the switches, what is sent and the provider
- [Assess an agent checkout](https://provenanceauth.com/docs/authorize/guides/assess-checkouts.md): the checkout policy and its default rules
- [Policies](https://provenanceauth.com/docs/concepts/policies.md): versions, shadow mode and publishing
