AWS Builder Center
How we built a formally verified fraud rules engine on AWS

How we built a formally verified fraud rules engine on AWS

> Formally verified fraud rules on AWS: Z3 proves correctness before deployment, Cedar enforces hard stops that can't be bypassed at runtime, and Drools handles stateful velocity rules. Plus UORF, an open rule format for writing a rule once and generating it for several engines.

Data and Ai lead at AWS
Updated 16 November 2026: UORF, the rule format in this post, has changed since publication. It's now industry-neutral and is being prepared for release as an AWS open source project. The examples now use rules based on public US regulations, and the UORF and Dogwood sections describe what the first release will include.

Every financial institution runs a rules engine. Somewhere in your technology stack there is a list of conditions, such as IF the counterparty is a confirmed sanctions match THEN block the payment. For most teams, the confidence that these rules work correctly comes from testing. You write test cases. You add edge cases after incidents. You run the suite before each deploy.

This post argues that testing is not enough — not because testing is poorly done, but because of what testing structurally cannot tell you. It cannot tell you whether a rule can ever fire at all. It cannot tell you whether a sophisticated attacker could construct a transaction that navigates through your rulebook without triggering any block. And it cannot tell you whether two rules that are supposed to be mutually exclusive can actually co-fire on some input no one thought to test.
We encountered all three failure modes when we built the Fraud Rule Engine. This post explains the architecture we used to solve them — three layers, three tools, each providing a guarantee the others cannot.



The three problems with testing-only rule governance

Dead rules. A rule can be syntactically valid and semantically broken. A condition like  aws:SourceVpce StringEquals "*"  in an IAM policy looks like a wildcard, but  *  is a literal string, not a glob. The policy effectively never matches anything. As Neha from the AWS Automated Reasoning Group demonstrated in  ARG: How AWS Service Teams use Automated Reasoning for Security , even experienced security engineers looking at such policies can miss the issue. The same pattern occurs in fraud rules: a condition that looks like it fires on all wire transfers, but due to a type mismatch or an off-by-one, never does. Testing only catches dead rules when you explicitly test for the case that should fire.
Bypass chains. In a tiered rules engine, Tier 1 rules should block before Tier 2–4 rules evaluate. But if salience is misunderstood — it controls evaluation order, not prevention of execution after a fact insert — a Tier 3 rule might fire after a Tier 1 block has already been issued. The transaction gets a secondary decision that shouldn't exist. No test catches this unless you specifically constructed a scenario that exercises the exact interaction.
Rule interaction violations. Two rules designed to be mutually exclusive — one fires for card fraud, one for AML structuring — may actually share a satisfying input. A transaction that triggers both produces an ambiguous outcome. In a system with dozens of rules across multiple channels, the combinatorial space of possible interactions is enormous. A test suite covers the cases you anticipated. It says nothing about the cases you didn't.



The three-layer model

The Fraud Rule Engine (FRE) addresses these three problems with three independent layers, each providing a guarantee the others cannot:
PRE-DEPLOYMENT RUNTIME TIER 1 RUNTIME TIERS 2–4
───────────────── ───────────────── ─────────────────
Z3 Theorem Prover → Cedar / AVP → Drools Rete (ECS)
Mathematical proof Structural hard-stop Stateful evaluation
before any deploy sub-ms, every txn velocity + aggregation

The integration contract is minimal: transactions arrive on an  Amazon Kinesis  data stream ( fre-transaction-stream ) enriched with velocity signals and risk attributes. Decisions are emitted to an  Amazon EventBridge  bus ( fre-decision-bus ). No changes to the host fraud platform are required.



The intellectual foundation: why automated reasoning?

In 2018, Byron Cook — founder and director of the AWS Automated Reasoning Group — published the first public description of Zelkova, an internal AWS service that uses automated reasoning to analyze IAM policies. Zelkova now powers  IAM Access Analyzer for S3 ,  AWS Config  managed rules,  Amazon Macie ,  Amazon GuardDuty , and several other services. Cook described the capability this way in 2025: "I brought this sort of capability to Amazon starting about 10 years ago."
The insight behind Zelkova — and behind the FRE's Z3 layer — is that policies are logical formulas. An IAM policy statement can be translated into a mathematical expression over variables (principal, action, resource, conditions). A fraud rule is the same structure: a formula over transaction attributes. Once you have a formula, you can use an SMT solver to ask questions about it over the entire input space, not just the test cases you thought to write.
Zelkova uses this to answer: "Is this S3 bucket publicly accessible?" The FRE uses the same technique to answer: "Can this tier-gate be bypassed? Can this rule ever fire? Can these two rules co-fire when they shouldn't?"
The tool is  Z3  — Microsoft Research's open-source SMT (Satisfiability Modulo Theories) solver, licensed under MIT. Z3 takes a logical formula and either proves it is true for all possible values of the variables, or returns a counterexample: concrete values that make it false. The counterexample is the part that makes this actionable in practice. When Z3 finds a bypass chain, it doesn't just say "there's a problem" — it returns the exact transaction attributes that exploit it.



Building block 1: Z3 formal verification

Architecture

The Z3 Prover runs as a Docker  AWS Lambda  function (1,024 MB, 5-minute timeout). It is invoked as a gate in the deploy pipeline — before any rulebook change reaches production. Proof artefacts are written to  Amazon S3  for regulatory audit.

What it checks

We run five categories of proof on every deploy. We label these I1–I5 for reference — the underlying SMT operations are standard satisfiability queries, but the taxonomy is our own:
Label
Check
What Z3 proves
I1
Joint satisfiability
Can two rules that shouldn't co-fire simultaneously actually do so?
I2
Bypass chains
Can a lower-tier action execute after a higher-tier block has been issued?
I3
Outcome amplification
Do two rules together produce a more severe outcome than either alone intended?
I4
Mutual exclusion
Are supposedly exclusive rules provably exclusive over all inputs?
I5
Dead rules
Is there any valid input that makes this rule fire at all?

Results from the first run

Against a 27-rule example rule set, Z3 returned 63 findings. Most were I5 dead rules (conditions that could never be satisfied together) and I2 bypass chain risks. None were bugs in the traditional sense. They were proof obligations the rule authors hadn't explicitly reasoned about. The most instructive finding was a pair of rules that are meant to interact: an account takeover rule that blocks at high salience, and a lower-tier velocity rule that flags. Z3 flagged the pair as  I1_JOINT_SAT CRITICAL , because one transaction can satisfy both. That was the correct finding. The block is meant to win, and only a structural tier gate in the lower rule stops it producing a second decision on the same transaction. The finding confirmed the gate was necessary: without its  not FraudDecision(action == "BLOCK")  condition, both rules would produce decisions.



Building block 2: Cedar and Amazon Verified Permissions

Why Cedar for fraud compliance?

Testing validates the cases you anticipated. Cedar's forbid-wins semantics provide a structural guarantee independent of testing. If any  forbid  policy matches a transaction, the decision is  DENY  — unconditionally, regardless of how many  permit  policies also match. This is not a configuration option. It is the language definition, as specified in the  Cedar policy language reference .
The distinction matters for compliance: you can tell a regulator that a sanctions check cannot be bypassed because the authorization language's evaluation procedure makes it structurally impossible, not because a test suite says so.

Cedar on AWS: choosing the right service

Cedar is available via two distinct AWS services. Choosing the wrong one is a common mistake:
 Amazon Verified Permissions (AVP)  launched GA on June 13, 2023. It is purpose-built for application-level fine-grained authorization — RBAC/ABAC for users, accounts, and domain entities. It is fully supported by  AWS CloudFormation  and  Terraform . The principal is your application's user or account. The resource is your application's data or transaction. This is the right choice for the FRE: we are authorizing financial transactions, not constraining LLM agent behavior.
Policy in Amazon Bedrock AgentCore uses Cedar to constrain what AI agents can invoke through the AgentCore Gateway. As explained in  Why Policy in Amazon Bedrock AgentCore chose Cedar for securing agentic workflows , the enforcement point is the Gateway intercepting every MCP tool call before it reaches the tool. The IaC resource is  CedarPolicy  in the AgentCore Control Plane API. This is the right choice when the thing you're constraining is an LLM agent, not a payment. Cedar was accepted into the CNCF as a Sandbox project in October 2025, reflecting its growth as an open authorization standard beyond AWS.
For a complementary perspective on Cedar in financial services — specifically applying it to LLM decision governance — see  Defense-in-depth governance for LLM decisions on AWS Bedrock . The architectural insight is consistent: Cedar provides the deterministic enforcement layer that the LLM itself cannot be trusted to enforce.

The 5 + 1 policy design

The FRE's AVP policy store holds exactly six policies: five  forbid  statements and one catch-all  permit . The count is fixed — no additions without a security review. Velocity-based rules never go in Cedar; they require enrichment signals (velocity counts, account history) that Cedar cannot access because it evaluates each request statelessly.
// Confirmed sanctions match: always block
@id("sanctions_confirmed_match")
forbid (
principal,
action == FRE::Action::"wire_transfer",
resource
)
when {
resource has counterpartySanctionsStatus &&
resource.counterpartySanctionsStatus == "CONFIRMED_MATCH"
};

// Catch-all: no structural objection, so the payment goes on to Drools
@id("default_permit")
permit (principal, action, resource);

The catch-all  permit  at the bottom is essential. Cedar is default-deny — without an explicit permit, every transaction would be blocked. The  permit  says: if none of the five  forbid  policies matched, Cedar has no structural objection. The transaction proceeds to Drools.

The deployment lesson that cost us a day

Set membership in Cedar uses  [list].contains(x) . The expression  x in [list]  looks like it should work, but  in  is Cedar's entity-hierarchy operator — it tests whether an entity is a descendant of another entity's hierarchy. It does not perform scalar set membership.  resource.beneficiaryCountry in ["IR","KP"]  fails AVP STRICT validation at policy write time.  ["IR","KP"].contains(resource.beneficiaryCountry)  is correct. This is confirmed in the  Cedar language reference . Test your policies locally with the Cedar CLI before pushing to AVP.



Building block 3: Drools Rete on ECS Fargate

Why stateful rules need a different engine

Cedar evaluates one request at a time against static attributes. It cannot count how many wire transfers an account has made in the last 24 hours, because it has no access to transaction history. Rules that require  COUNT_LAST ,  SUM_LAST , or multi-event patterns — card testing velocity, structuring detection, account takeover signals — need a stateful engine with Working Memory.
The Fraud Rule Engine uses  Drools 10  running on  Amazon ECS  Fargate (Java 17, Spring Boot 3.2.5, 2 vCPU / 4 GB, auto-scaling 2–10 tasks at 70% CPU).

The Rete algorithm and why it matters for large rulebooks

Rete is a pattern-matching algorithm for efficiently evaluating large sets of rules against a changing set of facts. Its key property: instead of re-evaluating every rule from scratch when a new fact arrives, Rete builds a compiled network of condition nodes that share partial matches. When a dozen rules share the condition  transactionType == "WIRE_TRANSFER" , that condition is evaluated once and its result is shared across all of them.
The saving grows with the rulebook. Rete trades memory for speed, and its performance is in theory independent of the number of rules ( Rete algorithm ).

The salience / not() distinction

Important:  salience  controls evaluation order — which rule fires first when multiple rules are active simultaneously. It does not structurally prevent a lower-tier rule from executing after a higher-tier block has been inserted.
The structural tier gate is the  not FraudDecision(transactionId == $tx.id, action == "BLOCK")  negative condition. Once a BLOCK  FraudDecision  fact exists in Working Memory, this condition prevents lower-tier rules from activating. Salience ensures the BLOCK fires first;  not()  ensures lower tiers see the result.
// salience 800 = evaluation order (fires after Tier 1)
// not FraudDecision(action == "BLOCK") = structural gate
// → this rule cannot activate if a BLOCK decision already exists
//
// Cash structuring: cash deposits of 10,000 USD or less that together
// exceed 10,000 USD within 3 days (31 CFR 1010.311, 31 U.S.C. 5324).
// The 3-day count and sum are computed upstream and arrive as facts.
rule "CASH-STRUCTURING: Deposits kept under the reporting threshold"
salience 800
when
$tx : Transaction(transactionType == "CASH_DEPOSIT",
currency == "USD", amount <= 10000)
$cust : CustomerFacts(
customerId == $tx.customerId,
smallCashDepositCount3d >= 2,
smallCashDepositSum3d > 10000
)
not FraudDecision(transactionId == $tx.id, action == "BLOCK")
then
insert(new FraudDecision($tx.id, "FLAG", 80, "CASH_STRUCTURING",
"Cash structuring pattern"));
end

A sanctions block shows how this composes across tiers:
SANCTIONS-MATCH (salience 1100, BLOCK) → fires first, inserts BLOCK into Working Memory
CASH-STRUCTURING (salience 800, FLAG) → not() prevents activation, gated
UNUSUAL-ACTIVITY (salience 700, FLAG) → not() prevents activation, gated




Building block 4: UORF, one rule format for several engines

The portability problem

Fraud rules usually live in each platform's own language, so moving a rule to another platform, or running it on two, means rewriting it by hand. The same rule can then behave slightly differently in each place, especially around priorities, time windows and missing data. General standards get partway: DMN decision tables and PMML are stateless, and W3C RIF has no time windows. None of them records what fraud and compliance rules depend on: priority, whether a rule is final, time windows, and structured outcomes with reason codes.

Unified Open Rule Format (UORF)

I created UORF for this project as a fraud rule format. It has since become industry-neutral. A small core defines how every rule matches, ranks and acts, and domain profiles add the vocabulary for a field, such as fraud and anti-money-laundering, or AI agent governance. Because every rule has the same structure, the Z3 checks in this post can run on any UORF rule set, and translators can generate engine code from it.
Here is the structuring rule from the Drools example, written in UORF:
{
"uorf_version": "0.2",
"profile": "fsi-fraud@0.1",
"rule_id": "FSI-CASH-001",
"name": "Cash deposits kept at or under 10,000 USD that total more than 10,000 USD within 3 days",
"subject": "transaction",
"category": "STRUCTURING",
"mechanism": "AGGREGATE_WINDOW",
"priority": { "tier": "standard_risk" },
"conditions": [
{ "field": "transaction_type", "op": "eq", "value": "CASH_DEPOSIT" },
{ "field": "currency", "op": "eq", "value": "USD" },
{ "field": "amount", "op": "lte", "value": 10000 },
{ "aggregate": { "fn": "count", "filter": [
{ "field": "transaction_type", "op": "eq", "value": "CASH_DEPOSIT" },
{ "field": "currency", "op": "eq", "value": "USD" },
{ "field": "amount", "op": "lte", "value": 10000 } ] },
"op": "gte", "value": 2 },
{ "aggregate": { "fn": "sum", "of": "amount", "filter": [
{ "field": "transaction_type", "op": "eq", "value": "CASH_DEPOSIT" },
{ "field": "currency", "op": "eq", "value": "USD" },
{ "field": "amount", "op": "lte", "value": 10000 } ] },
"op": "gt", "value": 10000 }
],
"window": { "duration": "P3D", "anchor": "rolling", "group_by": ["customer_id"] },
"action": { "outcome": "FLAG", "outcome_class": "REVIEW", "route": "aml_review",
"reason_code": "CASH_STRUCTURING", "obligations": ["audit_log", "fsi-fraud.consider_sar"] }
}

Unlike the Drools version, the 3-day count and sum are part of the rule, so a translator can compute them, or refuse the rule if its engine can't.
I'm preparing UORF for release as an AWS open source project. The first release will include the specification, profiles for fraud and for AI agent governance, a validator, the Z3-based verifier, and translators that generate Cedar policies and schemas and Dogwood temporal policies. A Drools translator is planned for a later release. I'll link to the repository here when it's public.



Deployment lessons

Five things that broke during the initial deployment, and what actually fixed them:
1. Cedar on AWS: choose the right service. We initially built against "AgentCore Policy (Cedar)" resources. For transaction authorization,  Amazon Verified Permissions  is the correct service — it is the purpose-built Cedar authorization service for application-level RBAC/ABAC with CloudFormation and Terraform support.
2. Cedar set membership syntax.  x in [list]  fails AVP STRICT validation —  in  is an entity-hierarchy operator. Use  [list].contains(x) .
3. ARM Mac → ECS Fargate architecture mismatch. Building Docker images on an Apple Silicon Mac produces ARM64 images. Fargate expects x86_64. Build flags:  --platform=linux/amd64  in the Dockerfile and in the CDK asset bundling configuration.
4. Drools 10 MVEL crash. Root cause: missing  org.drools:drools-mvel  JAR. Setting  -Ddrools.parallelRulesBuildThreshold=-1  disables parallel builds and masks the symptom. The correct fix is explicitly adding  drools-mvel  to the classpath or migrating to Drools' executable model, which deprecates MVEL in Drools 10.
5. Python wheels in Lambda.  pydantic_core  is a Rust binary wheel. A wheel installed on an ARM Mac will not load on Lambda's x86_64 Linux runtime. Either cross-compile with  --platform manylinux2014_x86_64 --only-binary :all: , or eliminate the Pydantic dependency and use stdlib-only code — which is what we chose for the Rule Generator Lambda.



What's next: Dogwood and temporal Cedar

The blog so far describes a clean split: Cedar handles stateless hard-stops, Drools handles stateful velocity rules. That split exists because Cedar — as deployed in Amazon Verified Permissions today — evaluates one request at a time with no access to transaction history. A velocity rule that counts a card's payments in the last hour needs a running count, which means Drools Working Memory.
AWS  Dogwood  changes this equation. Dogwood is a governance language that extends Cedar with temporal conditions —  formerly within 1h ,  since ,  once , and windowed aggregations over an event history. It compiles down to standard Cedar; the temporal predicates become  context.*  slots that a temporal engine fills at runtime from the event trace.
Here is an illustrative velocity rule in Dogwood: block a card payment when the same card has already made 10 or more payment requests in the past hour.
// Illustrative velocity rule: block a card payment when the same card
// has already made 10 or more payment requests in the past hour.
@id("card_velocity_1h")
forbid (
principal,
action == FRE::Action::"card_purchase",
resource
)
when temporal {
exists (n: Long).
(count for (t: Timepoint).
where (formerly within 1h (FRE::Action::"card_purchase"::request{ input.cardId: context.input.cardId } && tp(t)))) == n
&& n >= 10
};

In Drools, the same rule needs the count computed first: an enrichment step that keeps per-card counts, a store to hold them, and the Rete engine reading them as facts. In Dogwood, the count is a condition over the event history, evaluated by whichever engine holds that history.
Where a payment is made by an AI agent calling a tool through  Amazon Bedrock AgentCore  Gateway, AgentCore evaluates Dogwood temporal policies itself, over the agent's session, with conditions that look back up to 24 hours. For payments that don't go through an agent, you need a temporal engine of your own: the  open source Dogwood repository  provides a reference interpreter for understanding the language, and it isn't intended for production use.
What stays in Drools with Dogwood:
  • Rules that look back further than the engine's history allows, such as a 90-day dormancy check, or a 3-day structuring window where history is limited to 24 hours
  • Patterns across many entities, such as mule networks where money fans in and out across accounts
  • Rules that set state for other rules to read later, such as marking a card as compromised
What could migrate to Dogwood:
  • Velocity and count rules whose windows fit within the engine's history
  • Sum rules, such as the total amount in a window, where the window fits
  • Sequential event patterns (login → password reset → wire transfer within 10 minutes)
The architectural implication: the three-layer model becomes two layers for most rules — Z3 (pre-deploy proof) and Cedar + Dogwood (runtime enforcement with temporal awareness). Drools stays for the rules that genuinely need cross-entity graph traversal or long-horizon state.
This is the direction for the Fraud Rule Engine: velocity rules move from Drools to Dogwood where the history window allows, under one Cedar-based language. UORF's first release already generates Dogwood temporal policies alongside Cedar, and checks them with the Dogwood command-line tool.



Conclusion

Three tools, three guarantees:
  • Z3 proves correctness before deployment across the entire input space. Testing cannot do this.
  • Cedar makes compliance blocks structurally bypass-proof at runtime. Testing cannot do this either.
  • Drools Rete evaluates stateful velocity, temporal, and multi-event rules with Working Memory. Cedar cannot do this.
Each layer handles what the others cannot. None of them replaces the others. Together, they make fraud rule governance something you can reason about formally rather than test exhaustively.
UORF, the rule format, is being prepared for release as an AWS open source project under Apache 2.0. I'll link to it here when it's public. Contributions of new profiles, rules and engine translators will be welcome.



Related reading

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article