Sub topic 5
Scenarios: turning a typology into a rule
This chapter assumes you know what a typology and a red flag are, and that you can read basic Python. It also assumes you know the transaction fields from the data-inputs chapter: customer ID, type, amount and timestamp. The goal is to follow one typology, structuring, as it becomes a testable rule with parameters, and to see where such rules go wrong.
What a scenario is
A typology describes a laundering behavior in words. A scenario is the machine-executable version of one slice of that behavior. It selects data, applies logic and produces alert records.
A typology is usually vague. "Customers break up cash deposits to avoid reporting" cannot run on a database. A scenario must answer every question the sentence leaves open:
- Which customers or accounts does it apply to?
- Which transactions count?
- What does "break up" mean numerically?
- Over what period?
- What is written out when the logic is satisfied?
Teams document these answers in a scenario specification. A typical specification has these parts:
| Part | Question it answers | Structuring example |
|---|---|---|
| Typology | What behavior are we hunting? | Splitting cash deposits to stay under a reporting limit |
| Population | Whose activity is evaluated? | Retail segment customers |
| Filter | Which transactions are candidates? | Cash deposits between 8,000 and 10,000 |
| Logic | What pattern must appear? | At least 3 candidates inside a rolling window |
| Parameters | Which values can be tuned? | `floor`, `ceiling`, `lookback_days`, `min_count` |
| Output | What does an alert record hold? | Customer, window start and end, count, total |
From idea to logic
Start from the red flag, then make each word measurable.
- "Cash deposits" becomes a filter on the transaction type field. Decide whether ATM, branch and night-safe deposits all count. Your data must have a consistent type code for them.
- "Just under the limit" becomes a band,
floor <= amount < ceiling. The ceiling is the reporting threshold. The floor decides how far below it still looks suspicious. - "Several" becomes a count,
min_count. - "In a short time" becomes a rolling window of
lookback_days. - "By the same person" becomes a grouping key. Here it is
customer_id. Grouping by account would miss someone who spreads deposits over several accounts.
The decisions in this list are where scenarios differ most between institutions. Two teams can start from the same typology and write different rules, each defensible.
A scenario as data
Keeping parameters outside the logic lets analysts adjust them without changing code. It also lets you apply different values per segment.
PARAMS = {
"retail": {"lookback_days": 7, "min_count": 3, "floor": 8000, "ceiling": 10000},
"small_business": {"lookback_days": 7, "min_count": 5, "floor": 8000, "ceiling": 10000},
}
SCENARIO = {
"id": "structuring_cash",
"typology": "structuring",
"population": "retail",
"transaction_filter": "type == cash_deposit and floor <= amount < ceiling",
"group_by": "customer_id",
}
print(SCENARIO["id"], PARAMS[SCENARIO["population"]])The second segment needs a higher min_count because a small business deposits cash often as part of normal trade. Segments are covered in a later chapter. The point here is that the logic is shared and only the parameters differ.
The rule in code
This function implements the specification. It filters candidates, groups them per customer, and slides a window over each customer's sorted history.
from collections import defaultdict
from datetime import datetime, timedelta
def structuring_alerts(transactions, params):
"""Alert when a customer makes several cash deposits just under a limit
inside a rolling window."""
window = timedelta(days=params["lookback_days"])
by_customer = defaultdict(list)
for t in transactions:
if t["type"] == "cash_deposit" and params["floor"] <= t["amount"] < params["ceiling"]:
by_customer[t["customer_id"]].append(t)
alerts = []
for customer_id, txns in by_customer.items():
txns.sort(key=lambda t: t["timestamp"])
start = 0
for end, current in enumerate(txns):
while current["timestamp"] - txns[start]["timestamp"] > window:
start += 1
hits = txns[start:end + 1]
if len(hits) >= params["min_count"]:
alerts.append({
"customer_id": customer_id,
"scenario": "structuring_cash",
"window_start": hits[0]["timestamp"],
"window_end": hits[-1]["timestamp"],
"txn_count": len(hits),
"total_amount": sum(t["amount"] for t in hits),
})
break # one alert per customer per run
return alerts
params = {"lookback_days": 7, "min_count": 3, "floor": 8000, "ceiling": 10000}
transactions = [
{"customer_id": "C1", "type": "cash_deposit", "amount": 9500, "timestamp": datetime(2026, 3, 2, 10, 0)},
{"customer_id": "C1", "type": "cash_deposit", "amount": 9200, "timestamp": datetime(2026, 3, 3, 15, 30)},
{"customer_id": "C1", "type": "cash_deposit", "amount": 9800, "timestamp": datetime(2026, 3, 5, 9, 15)},
{"customer_id": "C2", "type": "cash_deposit", "amount": 9500, "timestamp": datetime(2026, 3, 2, 11, 0)},
]
for a in structuring_alerts(transactions, params):
print(a["customer_id"], a["txn_count"], a["total_amount"])
# C1 3 28500C1 has three qualifying deposits within about three days, so the rule fires. C2 has one, so it does not.
How the window works
The two pointers, start and end, mark the current window. For each new deposit, start advances until the oldest deposit in the window is no more than lookback_days old. The slice txns[start:end + 1] is then every deposit in the window ending at the current one. Because the list is sorted by timestamp, each element is visited a small number of times, so the cost per customer grows roughly linearly with their candidate count, plus the sort.
The alert reports the first window that reaches min_count. It does not report the largest window, so a customer who keeps depositing for weeks still produces an alert covering only the earliest qualifying burst.
Edge cases to test
Most defects in scenarios sit at boundaries. Write tests for them, because a rule that looks right on typical data often fails here. Append this to the script above:
def dep(cid, amount, ts):
return {"customer_id": cid, "type": "cash_deposit", "amount": amount, "timestamp": ts}
# The ceiling is exclusive: a deposit of exactly 10000 is not a candidate.
assert structuring_alerts(
[dep("A", 9500, datetime(2026, 3, 1)), dep("A", 9500, datetime(2026, 3, 2)),
dep("A", 10000, datetime(2026, 3, 3))], params) == []
# The floor is inclusive: three deposits of exactly 8000 qualify.
assert len(structuring_alerts(
[dep("B", 8000, datetime(2026, 3, 1)), dep("B", 8000, datetime(2026, 3, 2)),
dep("B", 8000, datetime(2026, 3, 3))], params)) == 1
# A span of exactly 7 days is inside the window.
assert len(structuring_alerts(
[dep("C", 9000, datetime(2026, 3, 1, 10, 0)), dep("C", 9000, datetime(2026, 3, 4, 10, 0)),
dep("C", 9000, datetime(2026, 3, 8, 10, 0))], params)) == 1
# One minute past 7 days drops the first deposit out of the window.
assert structuring_alerts(
[dep("D", 9000, datetime(2026, 3, 1, 10, 0)), dep("D", 9000, datetime(2026, 3, 4, 10, 0)),
dep("D", 9000, datetime(2026, 3, 8, 10, 1))], params) == []
print("boundary tests passed")The rule's behavior at these four boundaries is a design decision. Whether exactly 10,000 is inside or outside the band matters, because 10,000 is often the very amount the typology revolves around. Record the choice in the specification so reviewers and auditors can see it was deliberate.
Failure modes and gotchas
- Wrong grain. Grouping by account misses customers who spread deposits across accounts. Grouping by customer can over-alert on joint accounts or on related parties. Decide the entity first.
- Time handling. Compare timestamps in one time zone. Decide whether the window is measured in calendar days or in 24-hour periods. A deposit made late on a Friday and posted on Monday raises the question of which date the rule uses: transaction date, posting date or value date.
- Currency. A band of 8,000 to 10,000 assumes one currency. Multi-currency data needs conversion before the filter, and the conversion rate then becomes part of the rule.
- Repeat alerts. The
breaklimits output to one alert per customer per run. If the scheduler runs daily and the same deposits stay inside the window, the same customer alerts again the next day. The alert generation and consolidation chapters cover how systems suppress these repeats. - Evasion by design. A fixed band is predictable. Someone who deposits 7,900 never enters it. Scenarios therefore come in families, with several bands and windows, and they are retuned over time.
- Data quality. If the cash type code is missing or inconsistent, the filter silently drops transactions. A scenario that never fires is not proof of clean activity, so test it against known cases.
- Over-specific rules. Every added condition lowers the false positives and the true positives together. A rule with five conditions may be accurate on the sample it was designed from and blind to variations.
Choosing parameter values
The values in PARAMS are starting hypotheses. Common sources are the legal reporting limit (for the ceiling), historical cases that analysts confirmed (for the floor and count), and the observed distribution of each segment's normal behavior. The next chapter treats thresholds and parameters in depth, including how they are set and changed under governance.
Exercise
In the structuring scenario, a customer makes cash deposits of 9,000 on March 1 at 10:00, 9,100 on March 5 at 10:00, and 9,200 on March 8 at 10:00. With lookbackdays = 7 and mincount = 3, does the rule alert? What changes if the third deposit is made on March 8 at 10:01? Name the exact comparison in the code that decides it.
Show answer
The rule alerts in the first case. The span from the first to the third deposit is exactly 7 days, and the code advances the window start only when the difference is strictly greater than the window (current timestamp minus the start timestamp > window). With the third deposit at 10:01 the span is 7 days and 1 minute, so the first deposit leaves the window, the window holds only 2 deposits, and the rule does not alert.
Exercise
A compliance officer wants the rule to catch customers who deposit 7,500 each time, because they suspect people have learned the 8,000 floor. Which parameter would you change, what side effect should you expect, and why is that side effect a cost?
Show answer
Lower floor (for example to 7,000). The band then admits more ordinary deposits, so more customers reach min_count and the number of alerts rises. Many of the extra alerts will be normal behavior, which raises analyst workload and lowers alert precision. The change should be tested against historical data first to measure the added volume.