Skip to main content
A policy is how you decide which rules and limits apply, in which order, and how strictly, for each ledger. You publish a policy as an immutable revision, and you bind it to a ledger with one instruction for its rules and one for its limits. What changes in your operation: every change to what a rule decides becomes a version. You apply it at once, or you edit a draft and publish it when you are ready. Every policy that holds the rule then gets a new revision that you can read back and revert. One ledger can enforce a policy while another ledger only reports what it would decide. Trade-off: you manage three objects instead of one. After your first publication, a rule or limit outside every published policy does not apply to the decide flow or to POST /v1/validations.
Policies, bindings, and rule and limit versions are available from the Midaz release that introduces policies. Policies apply to the decide flow of the Midaz ledger and to POST /v1/validations. The reserve flow of the ledger never reads them. It keeps evaluating every active rule and limit.
Who is this guide for? Risk and fraud analysts who decide what applies to each ledger, and the developers who automate that through the API. Read the Rules engine first for the expressions themselves.

How the pieces fit


A policy has two controls: RULES and LIMITS. Each control gets a verdict (what it decided) and an instruction (what the caller does with the verdict). The instruction comes from a binding, or from the fallback mode when no binding decides it.

Versions of rules and limits


What a rule decides and what a limit enforces are versioned. Every rule and limit that existed at the upgrade became version 1, current.
  • PATCH /v1/rules/{rule_id} with expression, action, or scopes applies at once, as in earlier releases. Tracer writes a new version and publishes it in one step. The same applies to PATCH /v1/limits/{limit_id} with maxAmount, scopes, the time window, or the custom period. The expression of a rule accepts this edit only while the rule is DRAFT (code 0351).
  • With ?draft=true, the same PATCH writes a draft version instead, in any status. No evaluation reads a draft. A second draft edit replaces the draft.
  • POST /v1/rules/{rule_id}/publish and POST /v1/limits/{limit_id}/publish make the draft the current version. In the same transaction, every published policy that holds the rule or limit gets a new revision with the new version. When the transaction commits, Tracer emits rule.updated or limit.updated.
  • Pass ?draftVersion= with the draft version you reviewed to publish only that draft. If someone saves a new draft between your review and your publish, the pending draft is another version. Tracer then answers 409 with code 0603 and publishes nothing. Read the new draft, review it, and publish it with its own number. With draftVersion and no pending draft, the answer is also 0603. Without draftVersion, publish takes the pending draft, whatever its number.
  • While a draft is pending, a PATCH without draft=true that changes versioned content answers 409 with code 0602. Otherwise a later publish of the draft would undo that change in silence. Publish the draft first, or send the change with draft=true.
  • name and description are not versioned. A PATCH of them changes the rule or limit at once, also while a draft is pending.
  • Status (ACTIVE, INACTIVE) is not versioned. A policy reads it live. When you deactivate a rule, it stops within one rule sync cycle (RULE_SYNC_POLL_INTERVAL_SECONDS). A deactivated limit takes no new hold, and the holds it already gave settle normally.
Write a new threshold of a rule as a draft:
The response is the current rule with its currentVersion and draftVersion. The expression in it is still the current one:
Publish the draft you reviewed, version 2:
policyRevisions lists the new revision of each published policy that holds the rule. GET /v1/rules/{rule_id}/versions and GET /v1/limits/{limit_id}/versions list every version, oldest first, with createdBy (user:<sub>, api_key:<label>, or system) and createdAt.
A draft does not reach traffic until you publish it. Publish without a draft answers 422 with code 0597, or 409 with code 0603 when you pass draftVersion.

Policies


A policy holds a working set and its revisions. The working set is what the next revision will hold. A revision is immutable: it pins each rule (with its position) and each limit at the version that was current when you published.

Create a policy and set its working set

1

Create the policy

The name is unique among the policies that are not deleted, from 1 to 255 characters. A name another policy holds answers 409 with code 0589. The policy starts unpublished, with an empty working set, and evaluates nothing:
2

Set the rules, in evaluation order

The list replaces the rules of the working set. It adds, removes, and reorders in one call. Each rule must exist and appear once. An empty list removes all rules.
3

Set the limits

Both calls answer with the working set:
Nothing evaluates differently until you publish.

Publish a revision

Revisions are numbered from 1. Only the latest revision of a policy evaluates. publishedBy is user:<sub> under Access Manager, api_key:<label> with the API key, or system. Publish answers 422 in two cases:
  • 0593: two bindings of the policy in one ledger have no relative order and can match the same transaction.
  • 0594: published policies would hold different versions of the same limit. The error names the policies and the versions.

Read and revert revisions

  • GET /v1/policies/{policy_id}/revisions lists the revisions, oldest first, with who published each one and when.
  • GET /v1/policies/{policy_id}/revisions/{revision} returns one revision with the rules and limits it pins.
  • POST /v1/policies/{policy_id}/revert with {"revision": 2} publishes a new revision that copies the pins of revision 2. The new revision carries revertedFrom. The published revision only moves forward, and the reverted one stays readable.
A revert never reactivates an inactive rule or limit, because status is live. A revert to a revision the policy does not have answers 404 with code 0590. A revert that would leave two versions of one limit across published policies answers 422 with code 0594.

Change or delete a policy

  • PATCH /v1/policies/{policy_id} changes name or description. Neither is part of a revision, so the change applies at once and publishes nothing.
  • DELETE /v1/policies/{policy_id} soft-deletes the policy, which then stops evaluating. Its revisions stay readable. A policy that bindings still attach to a ledger answers 409 with code 0600. Delete its bindings first.
  • GET /v1/policies lists the policies that are not deleted, by name, with their publishedRevision. GET /v1/policies/{policy_id} also returns the working set.
A rule or limit that a revision or a working set references cannot be deleted: Tracer answers 409 with code 0595 (rule) or 0596 (limit). Deactivate it instead.

How a policy evaluates


A policy evaluates its rules in revision order:
  1. Tracer walks the rules whose scopes cover the transaction. A rule that is not ACTIVE is skipped.
  2. The first matching ALLOW ends the policy with ALLOW. An ALLOW is an explicit exception: it shadows only the rules after it. Put a DENY that must win before it.
  3. A matching DENY or REVIEW decides the policy.
  4. A rule that cannot conclude (an evaluation error, an inconclusive field, or the end of the MAX_RULES_PER_REQUEST budget) leaves the policy REVIEW with the reason rule_evaluation_error, unless a later DENY or REVIEW matches. An ALLOW after it never lets the transaction through. This holds on the reserve and decide flows. On POST /v1/validations, a rule with an inconclusive field is left out of the decision instead, so a later ALLOW or the no-match default decides, and the response answers conclusive: false. Treat that answer as incomplete screening. See Absent and unavailable fields.
  5. When no rule matches, the policy answers ALLOW on the decide flow. On POST /v1/validations, it answers DEFAULT_DECISION_WHEN_NO_MATCH.
Policies evaluate in name order, then by id. One MAX_RULES_PER_REQUEST budget covers all of them. A rule pinned in two policies evaluates in each, under the instruction of each policy. A limit pinned in several policies is read once for each decision, at the most restrictive instruction among the policies that hold it, and holds capacity once.
Order replaces precedence. Without policies, Tracer evaluates every matching rule and decides DENY over REVIEW over ALLOW. Inside a policy, the order you set decides. That is what makes an ALLOW exception possible. Across policies, the combined verdict still takes DENY over REVIEW over ALLOW, but it is diagnostic only.

Bindings


A binding ties one policy to one ledger and, optionally, to one payment scheme. It has a selector, a position, and one action for each control: rulesAction and limitsAction.

Selector

The selector has one optional field, scheme. A binding with {"scheme": "PIX"} matches the Pix transactions of the ledger, compared without case. An empty selector ({}) matches every transaction of the ledger. Any other key in the selector answers 400 with code 0094.

Create a binding

position orders the bindings of one policy in one ledger, starting at 1. Omit it, or send 0, to append. A position another binding of the pair holds answers 409 with code 0592.

How Tracer picks the instruction

For each policy and each control, Tracer walks the bindings of the ledger by position. The first binding that matches and does not INHERIT the control decides it. When none does, the control takes the fallback mode.

Manage bindings

With only policy_id, the list returns the bindings of the policy across every ledger, ordered by ledger and then by position. Each binding create, change, reorder, and delete writes an audit event in the same transaction: BINDING_CREATED, BINDING_UPDATED, BINDING_REORDERED, or BINDING_DELETED. A reorder writes one BINDING_REORDERED event for each binding whose position changes. A policy delete writes POLICY_DELETED. Query them with GET /v1/audit-events?resource_type=binding or resource_type=policy. See Audit and compliance. A binding’s ledger and policy never change. To swap two positions, use PUT /v1/bindings/order with every binding of the policy in the ledger, once each. They take positions 1 to n in that order, in one write:
A list that does not name each binding exactly once answers 400 with code 0598. After a delete, the remaining positions keep their gaps and still order the bindings.

Check the effective instruction


GET /v1/bindings/effective shows, for one ledger and, optionally, one scheme, the instruction that each control of every published policy gets, and which binding decided it. It evaluates nothing and moves no limit. Tracer does not read ledger settings. Pass the ledger’s tracer.mode as fallback_mode (ENFORCE or ADVISORY). Without it, a control that no binding decides answers LEDGER_FALLBACK.
source is BINDING when a binding decided the control, FALLBACK otherwise.

Examples


Pix limits off, antifraud intact. Policy retail pins the antifraud rules and the daily limits. Ledger L has one binding of retail: selector {"scheme": "PIX"}, rulesAction INHERIT, limitsAction OFF. A Pix transaction of an enforce ledger evaluates the rules at ENFORCE (inherited, so the fallback decides) and reads no limit. A TED transaction matches no binding, and both controls take ENFORCE. Advisory for one ledger. Policy antifraud has one binding on ledger L2: selector {}, both controls ADVISORY. A transaction of L2 that matches a DENY rule answers the verdict DENY, the control ADVISORY with the effect PROCEED, and the outcome PROCEED. The ledger proceeds. The same transaction on any other ledger takes that ledger’s fallback, and under enforce it is refused. Limit on an unread segment. Ledger L3 runs advisory. Policy segments has one binding on L3: selector {}, both controls ENFORCE. A limit of the policy is scoped on segment S. When the ledger could not read the account’s segment, that limit answers REVIEW with the reason limit_context_unavailable, and the transaction is refused. When the account has no segment at all, the segment limit does not apply.

The first published policy


The upgrade to the release that introduces policies publishes no policy, and a new tenant database starts without policies. Until a tenant publishes its first policy, the decide flow and POST /v1/validations evaluate every active rule and limit, as the reserve flow does.
Plan your first publication. From the moment a tenant publishes its first policy, a rule or limit outside every published policy no longer applies to the decide flow or to POST /v1/validations. Put every active rule and limit that must still apply in that first policy. A rule you create or reactivate later applies there only after you add it to a policy and publish that policy. The reserve flow keeps evaluating every active rule and limit.
To add a new rule to a published policy:
  1. Read the working set with GET /v1/policies/{policy_id}.
  2. Send the full list, with the new rule at the position you want, to PUT /v1/policies/{policy_id}/rules.
  3. Publish with POST /v1/policies/{policy_id}/publish.

Error codes


The complete list is in the Tracer error list.

Quick reference