Identify · Guide
Backtest traffic rules
Before a traffic rule blocks or challenges anyone, replay it over the traffic you already recorded. The backtest runs the same evaluator as the hosted check and the middleware over your recorded decisions and tells you what would have changed: how many requests each rule would have decided, which decisions would have gone a different way, and how many of the visits it would have stopped went on to place an order.
Before you begin: a traffic policy draft, recorded traffic (hosted checks, or middleware and edge reports), and a key on the Pro plan or above.
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_ent_E7nT2vQ9bW4mK8sYd3cFjLh6gAe1pR5x
1. Record a request
The backtest replays decisions you already recorded. On a new account, send one hosted check first, here a script calling your checkout:
curl -s -X POST $PROVENANCE_API/v1/identify/assessments \
-H "Authorization: Bearer $PROVENANCE_KEY" \
-H "Content-Type: application/json" \
-d '{"request":{"method":"POST","url":"https://harborbean.example/checkout","headers":{"user-agent":"python-requests/2.32.3"}}}'
const check = await (await fetch(`${process.env.PROVENANCE_API}/v1/identify/assessments`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
request: { method: "POST", url: "https://harborbean.example/checkout", headers: { "user-agent": "python-requests/2.32.3" } },
}),
})).json();
import os, httpx
check = httpx.post(
f"{os.environ['PROVENANCE_API']}/v1/identify/assessments",
headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
json={"request": {"method": "POST", "url": "https://harborbean.example/checkout",
"headers": {"user-agent": "python-requests/2.32.3"}}},
).json()
{
"object": "traffic_assessment",
"class": "declared_bot",
"decision": { "action": "allow", "shadow": null },
"action": "checkout",
"source": "hosted"
}
With no active policy the check allows the request; the draft below would have challenged it.
2. Replay a draft
Send the draft as document; leave it out to replay the active policy. days is 1 to 30 (30 by default).
curl -s -X POST $PROVENANCE_API/v1/identify/policies/backtest \
-H "Authorization: Bearer $PROVENANCE_KEY" \
-H "Content-Type: application/json" \
-d '{"document":{"rules":[{"id":"challenge-bots","label":"Challenge bots at checkout","when":[{"fact":"agent.class","op":"in","value":["suspected_bot","declared_bot"]}],"then":{"action":"challenge"}}],"default":"allow"},"days":30}'
const backtest = await (await fetch(`${process.env.PROVENANCE_API}/v1/identify/policies/backtest`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
document: {
rules: [
{
id: "challenge-bots",
label: "Challenge bots at checkout",
when: [{ fact: "agent.class", op: "in", value: ["suspected_bot", "declared_bot"] }],
then: { action: "challenge" },
},
],
default: "allow",
},
days: 30,
}),
})).json();
import os, httpx
backtest = httpx.post(
f"{os.environ['PROVENANCE_API']}/v1/identify/policies/backtest",
headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"},
json={
"document": {
"rules": [{"id": "challenge-bots", "label": "Challenge bots at checkout",
"when": [{"fact": "agent.class", "op": "in", "value": ["suspected_bot", "declared_bot"]}],
"then": {"action": "challenge"}}],
"default": "allow",
},
"days": 30,
},
).json()
{
"object": "policy_backtest",
"available": true,
"days": 30,
"requests": 1,
"truncated": false,
"totals": { "allowed": 0, "challenged": 1, "rejected": 0 },
"rules": [
{ "rule_id": "challenge-bots", "label": "Challenge bots at checkout", "outcome": "ask", "action": "challenge", "matched": 1, "decided": 1, "per_week": 0.2, "summary": "Last 30 days: would have challenged 1 request, about 1 a month" }
],
"traffic": {
"actions": { "allow": 0, "log_only": 0, "rate_limit": 0, "challenge": 1, "require_intent": 0, "reject": 0 },
"changed": { "allow→challenge": 1 },
"by_class": { "declared_bot": { "challenge": 1 } },
"reached_checkout": { "stopped": 1, "visits": 0, "flagged": 0 },
"unscored": 0,
"unscored_facts": [],
"sources": { "hosted": 1, "middleware": 0, "edge": 0 },
"lists_as_of": "now"
}
}
3. Read the result
| Field | What it says |
|---|---|
totals | What the draft would have done: allowed (allow and log only), challenged (challenge and require an intent), rejected. Rate limits count in traffic. only. |
rules[] | Per rule: how many requests its conditions match (matched), how many it would have decided (decided), and a one-line summary. |
traffic. | Decisions whose action would change from the recorded one, keyed from→to. An empty object means the draft decides as your live policy did. |
traffic. | The draft's actions per visitor class. |
traffic. | Of the visits the draft would block or challenge that your live policy allowed (stopped), how many a checkout assessment or a store order named (visits), and how many of the orders those visits placed were disputed or flagged (flagged): a chargeback or fraud, a refund abuse, a cart approval the customer denied, or an order your store rejected (order outcomes). |
traffic., unscored_ | Decisions the backtest couldn't replay, and the facts behind them (below). |
traffic. | Where the replayed decisions came from. Middleware and edge reports are what your integration sent, and may be sampled. |
Check reached_checkout before a rule blocks: a rule that would have stopped visits that went on to place orders stops customers too.
What a backtest can't replay
A decision keeps the facts a rule reads, with these exceptions:
intent_validandbiometric_boundare kept on decisions recorded since November 2026. An older decision that carried a person's approval can't be scored on them; a decision without a person reads both as false.protocol_kindis kept besideprotocolon decisions recorded since then; a decision with no protocol reads it as empty.protocol_payeeis never kept, because it names another business.
When a rule that could have decided a request names one of these facts and the decision didn't keep it, the decision is counted under unscored, never guessed. Middleware and edge reports send these facts from the next release of @provenanceauth/identify. in_list and not_in_list read each list as it is now (lists_as_of: "now").
Limits
- The window is 1 to 30 days, and never longer than your account's decision retention (Settings → Identify).
- The newest 20,000 decisions in the window are replayed; past that,
truncatedis true and the counts cover the newest ones. - One backtest runs per account at a time, and 30 a day.
Errors you might see
| Symptom | Cause | Fix |
|---|---|---|
402 plan_ | Backtests are on the Pro plan and above | Choose a plan in Settings → Plan & usage. |
409 backtest_ | A backtest for your account is still running | Send it again when the running one answers. |
429 rate_ | 30 backtests today | Wait for Retry-After. |
400 policy_ | The draft has an unknown fact, operator or action | error. names the rule and field. |
See also
- Write a traffic policy: simulate a single request, then roll out in shadow mode
- Traffic rule suggestions: drafts built from your recorded traffic, each with its backtest
- Traffic assessment: the facts a rule reads
- API reference:
POST /v1/identify/policies/backtest