View as Markdown

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"}}}'
{
  "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}'
{
  "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

FieldWhat it says
totalsWhat the draft would have done: allowed (allow and log only), challenged (challenge and require an intent), rejected. Rate limits count in traffic.actions only.
rules[]Per rule: how many requests its conditions match (matched), how many it would have decided (decided), and a one-line summary.
traffic.changedDecisions whose action would change from the recorded one, keyed from→to. An empty object means the draft decides as your live policy did.
traffic.by_classThe draft's actions per visitor class.
traffic.reached_checkoutOf 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, unscored_factsDecisions the backtest couldn't replay, and the facts behind them (below).
traffic.sourcesWhere 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_valid and biometric_bound are 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_kind is kept beside protocol on decisions recorded since then; a decision with no protocol reads it as empty.
  • protocol_payee is 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, truncated is true and the counts cover the newest ones.
  • One backtest runs per account at a time, and 30 a day.

Errors you might see

SymptomCauseFix
402 plan_requiredBacktests are on the Pro plan and aboveChoose a plan in Settings → Plan & usage.
409 backtest_in_progressA backtest for your account is still runningSend it again when the running one answers.
429 rate_limit_exceeded30 backtests todayWait for Retry-After.
400 policy_invalidThe draft has an unknown fact, operator or actionerror.details names the rule and field.

See also