# Capture rules

Approve, review or reject each captured photo by your own rules, on where and on what it was taken and how far it was from an address you know.

Capture rules decide each photo as it lands. A rule reads the shot's facts (its GPS, network, device, tier and its distance from an address you sent) and says **Approve**, **Review** or **Reject**. The first rule that matches decides. With no rules, each shot's checks decide. Capture rules are a [policy](https://provenanceauth.com/docs/concepts/policies.md): the same rule format, versions and simulate as every product.

A capture rule never asks the person to capture again. The capture page shows the same finished screen whatever the outcome, and the person never sees it.

**Availability:** every plan, for rules whose conditions each read one fact and all have to hold, as many as you need. A rule that matches any of its conditions, backtests and trial runs are on Pro and above.

**Before you begin:** read [capture requests](https://provenanceauth.com/docs/attest/guides/capture-requests.md), and send [reference addresses](https://provenanceauth.com/docs/attest/guides/capture-requests.md#compare-shots-with-an-address) on a request when a rule compares a shot with an address.

## 1. Write the rules

Rules live at [`PUT /v1/attest/capture_policies`](https://provenanceauth.com/docs/api/capture-policies.md#put-v1-attest-capture-policies). In the console, open **Rules › Captures**.

```json
{
  "note": "review photos far from the loss, reject mock locations",
  "document": {
    "rules": [
      { "id": "mock-location", "label": "Mock location", "when": [{ "fact": "capture.gps_mock", "op": "eq", "value": true }], "require": { "deny": true } },
      {
        "id": "far-from-loss",
        "label": "More than 5 km from the loss address",
        "when": [{ "fact": "capture.min_distance_km.loss_address", "op": "gt", "value": 5, "if_unavailable": "match" }],
        "require": { "approval": true }
      }
    ]
  }
}
```

Each rule takes one action:

| `require` | Action | The shot is |
| --- | --- | --- |
| `{ "frictionless": true }` | Approve | `approved`, unless one of its checks failed |
| `{ "approval": true }` | Review | `in_review`, for you to decide in your own system |
| `{ "deny": true }` | Reject | `rejected`. The capture still completes and the photo is kept |

An Approve rule never clears a failed check: a failed attestation, a suspected virtual camera, a flagged image, a decisive photo check that failed, or the device tier the request asked for not met. Such a shot is `in_review` with `outcome_reason: "capture_rule_approve_held"`.

A rule below one that always decides first never runs. The write still saves, and says so in `warnings` (`shadowed_by`).

## 2. The facts a rule reads

| Fact | Type | Meaning |
| --- | --- | --- |
| `capture.min_distance_km.<ref>` | km | The distance from the fix to the reference, less the fix's accuracy: the distance the evidence supports at least |
| `capture.distance_km.<ref>` | km | The distance from the fix to the reference |
| `capture.timezone_matches.<ref>` | yes/no | The device's UTC offset is the one in use at the reference |
| `capture.network_country_matches.<ref>`, `capture.network_region_matches.<ref>`, `capture.network_city_matches.<ref>` | yes/no | The network's country, region or city is the reference's (the city only with its switch on) |
| `capture.gps_present`, `capture.gps_source`, `capture.gps_accuracy_m`, `capture.gps_mock` |  | The fix, where it came from (`device_signed`, `browser_reported`, `none`), its accuracy in metres, and a mock location Android reported |
| `capture.network_country`, `capture.network_region` | ISO codes | The network's country and region |
| `capture.network.vpn_or_proxy`, `capture.network.hosting_provider` |  | `likely` or `not_detected`; a published cloud range |
| `capture.os`, `capture.os_version`, `capture.os_attested` |  | The OS, its version, and whether Android's key attestation proved it |
| `capture.clock_offset_s`, `capture.exif_consistent` |  | The device clock less ours; the photo's own tags agree with the capture |
| `capture.tier`, `capture.destination` |  | The device tier, and where it was opened (`web`, `company_app`, `provenance_app`, `app_clip`) |
| `capture.screen_or_print`, `capture.risk_score` |  | The [screen-or-print check](https://provenanceauth.com/docs/attest/concepts/risk-scoring.md#the-screen-or-print-check) (`suspected` or `clear`; absent when not checked), and the shot's risk score out of 100 |
| `capture.document_type`, `capture.document_accepted` |  | On an ID shot, the [document type](https://provenanceauth.com/docs/attest/guides/capture-requests.md#document-type) (`passport`, `driving_license`, `not_a_document`, ...) and whether the request accepts it; absent when the check didn't run |

`<ref>` names a reference by its kind:

| `<ref>` | The reference |
| --- | --- |
| `loss_address` | `kind: "loss"` |
| `person_address` | `kind: "person"` |
| `business_address` | `kind: "business"` |
| `shipping_address` | `kind: "shipping"` |
| `other_address`, `other_address_2` | the first and second `kind: "other"` |

A fact the shot couldn't give is absent, with a [reason code](https://provenanceauth.com/docs/platform/reason-codes.md) such as `permission_denied` or `geocoder_not_configured`. A condition on an absent fact doesn't match. Add `"if_unavailable": "match"` to a condition to match it instead, as the rule above does: a photo with no distance to the loss address goes to Review too.

## 3. Read the outcome

Each shot's checks on the request carry its outcome, and each item and the completed request carry the worst one (Rejected over In review over Approved). `checks`, what the checks found, stays beside it.

```json
"items": [
  {
    "index": 0,
    "outcome": "in_review",
    "policy": {
      "version": 4,
      "rule": {
        "id": "far-from-loss",
        "name": "More than 5 km from the loss address",
        "phase": "assess",
        "action": "review",
        "conditions": [{ "fact": "capture.min_distance_km.loss_address", "op": "gt", "value": 5, "actual": 12 }]
      }
    }
  }
]
```

`policy` is the rule that decided, with each condition and the value it compared (`actual`). Only the deciding rule is listed, and a comparison with an address appears only there. `policy` is null when no rule matched and the shot's checks decided.

When no rule matches, the fallback rows decide. Set `fallback` on the document to change either, such as `"fallback": { "flagged": "reject" }`:

| Row | When | Built-in outcome | Takes |
| --- | --- | --- | --- |
| `passes` | The shot's checks passed | `approve` | `approve`, `review`, `reject` |
| `flagged` | A check flagged the shot | `review` | `approve`, `review`, `reject` |

A shot the fallback decided names it in its reason, such as `capture_fallback_rejected`. An Approve still never clears a failed hard check or an unmet device tier.

The same fields are on the `attest.capture_request.item_captured` and `attest.capture_request.completed` webhooks. Read Review and Reject from them and decide in your own system.

## 4. Try rules before they decide

- [`POST /v1/attest/capture_policies/simulate`](https://provenanceauth.com/docs/api/capture-policies.md#post-v1-attest-capture-policies-simulate) runs a draft against one shot's facts, with `unavailable` for facts the shot couldn't give and `checks_failed` for checks it failed.
- [`POST /v1/attest/capture_policies/backtest`](https://provenanceauth.com/docs/api/capture-policies.md#post-v1-attest-capture-policies-backtest) replays a draft over the shots of the last 30 days, from the facts each shot recorded.
- A trial run (Pro): publish a draft with `trial_days`. Each shot records what the draft would have decided, and [`GET /v1/attest/capture_policies/trial`](https://provenanceauth.com/docs/api/capture-policies.md#get-v1-attest-capture-policies-trial) lists where it differed. Nothing it decides is enforced.

## 5. From the SDK

Save a draft, publish it when it's ready, then read each request's assessment: its outcome, the rule that decided and each shot's context.

```ts
const draft = await provenance.attest.capturePolicies.createDraft({ rules }, { note: "review photos far from the loss" });
await provenance.attest.capturePolicies.publishVersion(draft.version);

const assessment = await provenance.attest.captureRequests.assessment(request.id);
// assessment.outcome: "approved" | "in_review" | "rejected"; assessment.policy: the deciding rule
```

```python
draft = provenance.attest.capture_policies.create_draft({"rules": rules}, note="review photos far from the loss")
provenance.attest.capture_policies.publish_version(draft["version"])

assessment = provenance.attest.capture_requests.assessment(request["id"])
```

[`GET /v1/attest/capture_requests/{id}/assessment`](https://provenanceauth.com/docs/api/capture-requests.md#get-v1-attest-capture-requests-id-assessment) answers `404` `capture_assessment_not_ready` until the first photo lands.

## Let your team change them in your admin

`<provenance-rules>` shows your capture rules to your claims staff inside your own admin tool, with the values you choose as blanks and bounds. Mint it with an Attest key and `object_id: "capture"`; it previews in counts of photos and publishes like the console. See [rules in your admin](https://provenanceauth.com/docs/embeds/rules.md).

## Limitations

- A distance says where the device reported it was when the photo was taken, signed by the device key in your app or reported by a browser. It doesn't prove where a person lives or works.
- An address reference is placed at its postal code or city, not its street, so a distance to it is as close as that. Rules on `capture.min_distance_km.<ref>` already subtract the difference. An address the geocoder can't place has no distances (`geocode_not_found`); send it as coordinates instead.
- Rules run as each shot lands, with the rules live at that moment. A change applies to the shots that land after it.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `402` [`plan_required`](https://provenanceauth.com/docs/platform/errors.md#plan_required) | A rule matches any of its conditions (`match: "any"`) below Pro | Split it into one rule per condition, or move to Pro. |
| `400` [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid) on `rules.N.when` | A fact that isn't a capture fact, or a named list | Use a `capture.*` fact from the table. |
| `400` [`policy_invalid`](https://provenanceauth.com/docs/platform/errors.md#policy_invalid) on `rules.N.require` | Anything but `frictionless`, `approval` or `deny`, or more than one | Give each rule one action. |
| `403` [`insufficient_scope`](https://provenanceauth.com/docs/platform/errors.md#insufficient_scope) | The key isn't an Attest key | Use an Attest key. |

## See also

- [Capture requests](https://provenanceauth.com/docs/attest/guides/capture-requests.md)
- [Rules in your admin](https://provenanceauth.com/docs/embeds/rules.md)
- [Outcomes](https://provenanceauth.com/docs/reference/outcomes.md)
- [Reason codes](https://provenanceauth.com/docs/platform/reason-codes.md)
