Rules and presets
Every decision comes from the project's rules. A rule reads fields of the event (and the signals Defraudo adds to it) and, when its condition matches, either ends evaluation or adds points to the score.
Bands
Each rule has a band that says what a match does:
| Band | On a match |
|---|---|
trust | Ends evaluation with allow and score 0. |
hard_block | Makes the decision block; the score stays the sum of the scoring rules. |
high, medium, low | Adds the rule's score_delta (from −200 to 200) to the score. |
monitoring | Adds nothing; the rule id appears in flags. |
Trust rules are checked first, then hard-block rules, then the scoring and monitoring rules together in ascending priority. A rule with stop_on_match ends that pass when it matches. The final score is never below 0.
The score is compared with the project's thresholds: at or above block gives block, at or above review gives review and opens a case, otherwise allow. See How it works for the full request lifecycle.
Statuses
| Status | Meaning |
|---|---|
draft | Being written. Not evaluated. |
shadow | Evaluated on every event and recorded, but its points never count and it is not shown in the response breakdown. Use it to measure a rule on live traffic. |
active | Evaluated and counted. |
archived | Retired. |
A published rule is never edited in place: changing it means publishing a new version. Promoting a version to active archives the other live versions of the same rule; publishing a version to shadow leaves the active one in place.
Presets
A preset is a ready-made rule set with recommended thresholds. A new project starts on Essentials.
| Preset | Rules (active / shadow) | Thresholds review / block | For |
|---|---|---|---|
| Essentials | 29 (24 / 5) | 25 / 250 | Any business. Blocks only on hard evidence: your own lists, reputation marks, sanctions, known fraud and chargeback users. Email, IP, device and velocity signals add points toward review and cannot block on their own at the recommended thresholds. |
| iGaming Standard | 66 (40 / 26) | 30 / 60 | Casinos and sportsbooks without an affiliate or transaction feed. Multi-accounting is counted per project. |
| iGaming Advanced | 72 (43 / 29) | 30 / 60 | The full iGaming pack, including brand-scoped multi-accounting and the affiliate, registration-ratio and digit-count rules. Available to verified operators only. |
Both iGaming presets watch the deposit and payout method (payment.account_ref): one wallet or IBAN on 2 accounts adds 40 points, on 3 or more it hard-blocks deposits, withdrawals, payments and payouts. Accounts are counted across your projects of one environment, with no time limit, and the account being scored counts too, so accounts arriving at the same moment still see each other. A project that wants a block from the second account sets the hard-block rule to 2 accounts itself.
Both iGaming presets also block a web action sent without a device fingerprint (R-HB-WEB-NO-FP): it fires only when the event says context.platform: "web" and carries no fp_id the project knows, on any event type. Native-app events and events without platform are not affected; trusted and VIP users are exempt. See Device fingerprint.
The active / shadow split is how a preset ships. A rule that needs a signal source your project does not have configured stays in shadow.
Switching presets
Switch the project's preset yourself on the dashboard's Rules page: Change set lists the Defraudo presets on offer and the sets your company saved, and History lists past switches. The owner and project admins switch; analysts can open the preview and the history; viewers see the current set and the history. Save as set keeps the project's current rules as a set your other projects can switch to. Each switch works the same way:
- Preview. The switch is replayed against up to 10 000 of the project's events from the last 30 days, showing the decision mix before and after and the rules that move the most decisions. Events without a stored snapshot are skipped. A rule that reads a counter an event did not record is left out on that event only; rules the project has never counted have no history to replay, so the preview names them and shadow mode measures them on live traffic. The preview also says when it hit its time or event limit.
- Apply. By default the new rules arrive in
shadow: active rules and thresholds stay as they are (an older shadow version of the same rule may be replaced). A switch can also apply at once. - Confirm or cancel. A shadow switch never completes by itself. Confirming it moves the new rules to their target status (rules whose signal source is not configured stay in shadow), retires the rules the preset drops and, when requested, moves the thresholds to the preset's recommendation. Cancelling undoes what the switch changed.
- Roll back. The latest completed switch can be rolled back once no other switch is pending. Thresholds move back only if nobody changed them since.
Cancel and rollback leave alone any rule a person changed after the switch, and report the rules they could not restore. Rules you wrote yourself are never touched by a switch.
Writing rules
Rules can be drafted, simulated and published from the dashboard's Rules page or through the API.
A rule definition:
{
"id": "R-CUSTOM-HIGH-DEPOSIT",
"band": "medium",
"score_delta": 25,
"priority": 100,
"condition": {
"op": "and",
"conditions": [
{ "op": "eq", "field": "event_type", "value": "deposit" },
{ "op": "gt", "field": "payment.amount_cents", "value": 500000 }
]
}
}
Conditions:
| Operator | Use |
|---|---|
and, or | Combine conditions. A condition can nest at most 10 levels and 200 nodes. |
eq, neq, gt, gte | Compare a field with a value. |
in, not_in | Field is (not) one of a list. |
regex | Text match in RE2 syntax (no lookaround or backreferences). |
exists | Field is present and not null. |
count, count_distinct | Count events per value of field (dimension names the bucket) over a window (5m, 15m, 1h, 3h, 24h, 7d, 30d, 90d, 1y) and compare with compare (gt, gte, lt, lte, eq). |
ratio | Divides two counts and compares the result; a zero denominator is read as 1. |
payment_status_count | Counts the account's payments by their final status over a window. See Payment status counts. |
Things to know:
- A missing or null field never matches
neqornot_in:neqmatches only a field that is present and differs from the value. count_distinctneedsdistinctField. A count over90dor1yneedseventType.eventTypelimits any count to one event type;scope: "brand"counts within the event's own brand (windows up to 24h).- A project's active and shadow rules can use at most 12 distinct aggregates with windows of 7 days or longer.
- A regex pattern is at most 512 characters and 1 000 compiled instructions, and 10 000 instructions across the project's active and shadow rules. A field value longer than 512 characters never matches a regex.
- A country compared against
user.country,context.countryorpayment.billing_countryis stored as an uppercase ISO 3166-1 alpha-2 code whatever form you send it in.
Custom event names
A rule reads the name of a custom event in two ways:
{ "op": "eq", "field": "event_name", "value": "bonus_claim" }checks the event being scored (neq,inandnot_inwork too).eventNameon acountorcount_distinct(witheventType: "custom", any window, also on thecountterms of aratio) lets only custom events of that name into the count.
Three bonus claims by one account within 24 hours, checked only when the event being scored is itself a bonus claim:
{
"op": "and",
"conditions": [
{ "op": "eq", "field": "event_name", "value": "bonus_claim" },
{
"op": "count",
"dimension": "account_id",
"field": "external_account_id",
"eventType": "custom",
"eventName": "bonus_claim",
"window": "24h",
"compare": { "op": "gte", "value": 3 }
}
]
}
Without the first condition the count is checked on every event of the account, so while the account has three bonus claims inside the window the rule would also match its next login or deposit.
Payment status counts
payment_status_count counts the payments of the scored event's external_account_id by the final status you reported for them:
{
"op": "payment_status_count",
"statuses": ["failed"],
"eventTypes": ["deposit"],
"window": "1h",
"compare": { "op": "gte", "value": 3 }
}
| Field | Value |
|---|---|
statuses | 1 to 4 of completed, failed, cancelled, rolled_back. |
eventTypes | Optional. 1 to 4 of deposit, withdrawal, payment, payout; omitted counts all four. |
window | 1h, 3h, 24h, 7d, 30d or 90d. |
compare | gt, gte, lt, lte or eq with a number. |
- A payment counts under its latest status only, and only when that status was recorded inside the window. A
completedpayment laterrolled_backcounts asrolled_back. - The scored event itself is never counted.
- An event without
external_account_idnever matches. A status you never send counts as zero. - If the count cannot be read in time, the condition does not match.
- A simulation can count only events scored after the condition existed. When some evaluated events had no count,
warningscarriespayment-status-not-countedwith their number inevent_count.
A project's active and shadow rules can use at most 4 distinct payment status conditions. Conditions with the same statuses, event types and window count once, whatever their compare. Promoting a rule that would make it 5 is refused with 422: in the dashboard with code PAYMENT_STATUS_LIMIT_EXCEEDED and rule_ids listing the rules that carry one, through PUT /v1/rules/publish with COMPILE_ERROR. On the Rules page, validating a rule shows how many of the 4 the rule set uses, and a publish error when it would go over.
Rules API
| Endpoint | Scope | Does |
|---|---|---|
GET /v1/rules | rules:read | Lists the latest version of every rule, plus older versions that are still active or in shadow. page_size defaults to 50, at most 100. rule_id narrows the list to the rules you name, up to 100: ?rule_id=R-HB-WEB-NO-FP,R-MED-REP-SUSPICIOUS-PAYMENT-REF or the parameter repeated. Each rule's name is its readable name. |
POST /v1/rules/draft | rules:write | Creates up to 100 draft rules at once (all or nothing). definition.id must equal rule_id. |
PUT /v1/rules/{public_id} | rules:write | Edits a draft. |
POST /v1/rules/simulate | rules:write | Replays a rule against recent events (up to 2000, about 2 seconds). |
PUT /v1/rules/publish | rules:publish | Moves up to 100 rules to shadow, active or archived in one transaction. The new set takes effect on the next event. |
A simulation runs the candidate inside the project's current active rules, so a terminal rule or stop_on_match earlier in the order can keep it from being reached. Before reading the numbers, check truncated, excluded_no_snapshot and warnings. A second simulation while one is running gets 429.
Request and response shapes are in the API reference.