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.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}withexpression,action, orscopesapplies at once, as in earlier releases. Tracer writes a new version and publishes it in one step. The same applies toPATCH /v1/limits/{limit_id}withmaxAmount,scopes, the time window, or the custom period. The expression of a rule accepts this edit only while the rule isDRAFT(code0351).- With
?draft=true, the samePATCHwrites a draft version instead, in any status. No evaluation reads a draft. A second draft edit replaces the draft. POST /v1/rules/{rule_id}/publishandPOST /v1/limits/{limit_id}/publishmake 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 emitsrule.updatedorlimit.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 answers409with code0603and publishes nothing. Read the new draft, review it, and publish it with its own number. WithdraftVersionand no pending draft, the answer is also0603. WithoutdraftVersion, publish takes the pending draft, whatever its number. - While a draft is pending, a
PATCHwithoutdraft=truethat changes versioned content answers409with code0602. Otherwise a later publish of the draft would undo that change in silence. Publish the draft first, or send the change withdraft=true. nameanddescriptionare not versioned. APATCHof 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.
currentVersion and draftVersion. The expression in it is still the current one:
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.
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
409 with code 0589. The policy starts unpublished, with an empty working set, and evaluates nothing:2
Set the rules, in evaluation order
3
Set the limits
Publish a revision
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}/revisionslists 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}/revertwith{"revision": 2}publishes a new revision that copies the pins of revision 2. The new revision carriesrevertedFrom. The published revision only moves forward, and the reverted one stays readable.
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}changesnameordescription. 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 answers409with code0600. Delete its bindings first.GET /v1/policieslists the policies that are not deleted, by name, with theirpublishedRevision.GET /v1/policies/{policy_id}also returns the working set.
409 with code 0595 (rule) or 0596 (limit). Deactivate it instead.
How a policy evaluates
A policy evaluates its rules in revision order:
- Tracer walks the rules whose scopes cover the transaction. A rule that is not
ACTIVEis skipped. - The first matching
ALLOWends the policy withALLOW. AnALLOWis an explicit exception: it shadows only the rules after it. Put aDENYthat must win before it. - A matching
DENYorREVIEWdecides the policy. - A rule that cannot conclude (an evaluation error, an inconclusive field, or the end of the
MAX_RULES_PER_REQUESTbudget) leaves the policyREVIEWwith the reasonrule_evaluation_error, unless a laterDENYorREVIEWmatches. AnALLOWafter it never lets the transaction through. This holds on the reserve and decide flows. OnPOST /v1/validations, a rule with an inconclusive field is left out of the decision instead, so a laterALLOWor the no-match default decides, and the response answersconclusive: false. Treat that answer as incomplete screening. See Absent and unavailable fields. - When no rule matches, the policy answers
ALLOWon the decide flow. OnPOST /v1/validations, it answersDEFAULT_DECISION_WHEN_NO_MATCH.
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 notINHERIT 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:
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.
To add a new rule to a published policy:
- Read the working set with
GET /v1/policies/{policy_id}. - Send the full list, with the new rule at the position you want, to
PUT /v1/policies/{policy_id}/rules. - Publish with
POST /v1/policies/{policy_id}/publish.
Error codes
The complete list is in the Tracer error list.

