Sub topic 8
What an Alert Contains and When It Is Created
This chapter assumes you know how a scenario is defined, how thresholds and parameters control it, and how a rule is evaluated over a lookback window. You should also be able to read short Python functions. Here we look at the output of evaluation: the alert record. We cover what goes into it, what makes the system create one, and what happens when the same behavior is found twice.
An alert is a record, not a verdict
A rule match is a transient result inside a job. An alert is that result written to storage as a record with its own identity and lifecycle. Analysts, auditors, and tuning reports all work from the record, not from the rule.
An alert does not say a customer is laundering money. It says that a scenario's conditions were met, on specific data, under specific parameters. A good alert lets a reviewer answer three questions without opening the monitoring engine:
- What fired, and why?
- Which transactions and which customer does it concern?
- Under which version of the rules and data was it produced?
If the record cannot answer these, the analyst has to rebuild the context by hand. That slows review and makes later model validation difficult.
What an alert contains
Alert content falls into four groups. The table lists typical fields. Names vary between products, and the groups are what matter.
| Group | Typical fields | Purpose |
|---|---|---|
| Identity | alert ID, scenario name, scenario version, run ID | Uniquely identify the alert and the job that created it |
| Subject | customer ID, account IDs, segment | Say who the alert is about |
| Evidence | window start and end, transaction IDs, transaction count, total amount | Show the activity that satisfied the rule |
| Context | parameter values used, customer risk rating, creation time, status | Let a reviewer judge the alert and reproduce it |
Identity
The alert ID must be unique and stable. Once an analyst has written notes against an alert, the ID cannot change. Many systems also store the scenario version, so that a later change to the rule does not make old alerts look as if they were produced by the new logic.
Subject
Most scenarios alert on a customer, but some alert on an account, a counterparty, or a household. The subject type decides how alerts are later grouped into cases. An alert about an account still normally carries the customer ID, so it can be consolidated with other alerts for the same person or business.
Evidence
The summary numbers (count, total, window) are quick to read, but the list of transaction IDs is what makes the alert reviewable and testable. The analyst opens each transaction and checks the narrative, counterparty, and branch. The same list lets the system detect that two alerts describe overlapping activity.
The structuring_alerts function from the earlier chapters stores only a summary: txn_count, total_amount, and the window bounds. That is enough to show the idea, but a production alert should also keep the transaction IDs.
Context
Record the parameter values that were in effect, not just the name of the parameter set. Thresholds change during tuning. Without a snapshot you cannot explain later why an alert fired at a count of 3 when today's setting is 4. Store the customer's risk rating at creation time too, because it may change before the alert is reviewed.
When an alert is created
An alert is created when three conditions hold:
- The rule logic matches. For structuring, that means the count of qualifying deposits in the window reaches
min_count. - The match is new. It is not already covered by an open alert for the same subject and scenario.
- The match is not otherwise excluded. Examples are an allow-list entry, a customer exemption, or a transaction type the scenario ignores.
Condition 1 is what earlier chapters covered. Conditions 2 and 3 are where alert volume is shaped, and many surprising alert counts come from them.
Why the structuring example breaks after "one alert per run"
The structuring_alerts function uses break after the first match, so a customer gets at most one alert per run. That prevents a burst of alerts from one sliding window. It does not prevent duplicates across runs. If the job runs nightly with a seven-day lookback, the same three deposits fall inside the window on seven consecutive nights. Without a cross-run check, the customer gets seven alerts for one pattern.
A common fix is an overlap test against open alerts. A new match is a duplicate when it shares at least one transaction with an open alert for the same customer and scenario.
Building the record in code
The following code builds a full alert record and applies the overlap test. It is self-contained and runs as shown.
from datetime import datetime
def make_alert(customer_id, scenario, hits, params, params_version, run_id, created_at):
"""Build an alert record from the transactions that satisfied a rule."""
hits = sorted(hits, key=lambda t: t["timestamp"])
return {
"alert_id": f"{scenario}-{customer_id}-{run_id}",
"customer_id": customer_id,
"scenario": scenario,
"params_version": params_version,
"params_snapshot": dict(params),
"run_id": run_id,
"created_at": created_at,
"window_start": hits[0]["timestamp"],
"window_end": hits[-1]["timestamp"],
"txn_ids": [t["txn_id"] for t in hits],
"txn_count": len(hits),
"total_amount": sum(t["amount"] for t in hits),
"status": "open",
}
def is_duplicate(new_alert, open_alerts):
"""True when an open alert for the same customer and scenario shares a transaction."""
new_ids = set(new_alert["txn_ids"])
for old in open_alerts:
same_subject = (
old["customer_id"] == new_alert["customer_id"]
and old["scenario"] == new_alert["scenario"]
)
if same_subject and new_ids & set(old["txn_ids"]):
return True
return False
def deposit(n, amount, ts):
return {
"txn_id": f"T{n}",
"customer_id": "C1",
"type": "cash_deposit",
"amount": amount,
"timestamp": ts,
}
params = {"lookback_days": 7, "min_count": 3, "floor": 8000, "ceiling": 10000}
d1 = deposit(1, 9500, datetime(2026, 3, 2, 10, 0))
d2 = deposit(2, 9200, datetime(2026, 3, 3, 15, 30))
d3 = deposit(3, 9800, datetime(2026, 3, 5, 9, 15))
d4 = deposit(4, 9100, datetime(2026, 3, 6, 9, 0))
d5 = deposit(5, 9400, datetime(2026, 3, 18, 10, 0))
d6 = deposit(6, 9300, datetime(2026, 3, 19, 10, 0))
d7 = deposit(7, 9600, datetime(2026, 3, 20, 10, 0))
alert1 = make_alert("C1", "structuring_cash", [d1, d2, d3], params, "v3",
"run-2026-03-05", datetime(2026, 3, 5, 23, 0))
print(alert1["total_amount"])
print(alert1["txn_ids"])
# The next night's run sees d1..d4 in the window.
alert2 = make_alert("C1", "structuring_cash", [d1, d2, d3, d4], params, "v3",
"run-2026-03-06", datetime(2026, 3, 6, 23, 0))
print(is_duplicate(alert2, [alert1]))
# Two weeks later, new deposits with no shared transactions.
alert3 = make_alert("C1", "structuring_cash", [d5, d6, d7], params, "v3",
"run-2026-03-20", datetime(2026, 3, 20, 23, 0))
print(is_duplicate(alert3, [alert1]))Running it prints:
28500
['T1', 'T2', 'T3']
True
Falsealert2 is a duplicate because it shares T1 to T3 with alert1. alert3 is a new pattern, so it creates a new alert.
Choosing between suppress and append
When a new match overlaps an open alert, there are two common behaviors.
- Suppress. Discard the new match. This is simple, but the analyst never sees that the pattern grew from three deposits to four.
- Append. Add the new transaction IDs to the open alert and update the totals and window end. The analyst sees the growing pattern, but the record changes after review has started.
Appending needs rules of its own. If an analyst has already closed the alert, new evidence should usually open a new alert, not reopen the old one. If the alert is under review, appended evidence should be visible as new, so the analyst notices it. Whichever you pick, log the decision. Tuning later needs to know how many matches were suppressed, not only how many alerts exist.
Timing: batch and near-real-time creation
When the alert is created depends on how the rule is scheduled.
- Batch. The job runs on a schedule, such as nightly, and creates alerts after the run.
created_atis the job time, not the time of the triggering transaction. Reviewers see alerts the next morning, so store both the job time and the window end. - Near-real-time. The rule runs as each transaction arrives. The alert appears moments after the triggering transaction. Duplicates are more likely, because every new qualifying deposit re-evaluates the window. The overlap check is not optional in this mode.
In both modes, the alert should record the data it saw. Late-arriving transactions, such as a deposit posted a day after it happened, can enter a window that has already been evaluated. Decide whether a late arrival triggers a re-run for the affected window or waits for the next scheduled run, and document the choice.
Common errors
- No transaction IDs in the alert. Reviewers cannot trace the activity, and duplicate detection falls back on fragile comparisons of dates and amounts.
- Storing only the parameter set name. If "retail" thresholds are edited later, old alerts no longer explain themselves. Store the version or a snapshot of the values.
- Overwriting alerts on every run. This hides the history of what the system produced and makes it impossible to measure how often a scenario fires.
- Deduplicating by alert ID only. If the ID contains the run ID, as in the example above, every run produces a new ID. Duplicate detection must compare the content, here the shared transactions.
- Counting suppressed matches as nothing. They carry information about how noisy a scenario is.
What happens next
A newly created alert has status open and no analyst assigned. Two later steps act on it. Consolidation groups it with other alerts for the same customer into a case, and prioritization scores it so analysts work the riskiest items first. Both steps depend on the fields described above, especially the customer ID, scenario name, and evidence.
Exercise
A nightly job uses a seven-day lookback and min_count of 3. A customer makes three qualifying cash deposits on Monday, Tuesday, and Wednesday. The job has no cross-run duplicate check, and each run creates an alert when the count is at least 3. Roughly how many alerts does this customer get by the following Wednesday if no further deposits are made, and which field would you use to prevent this?
Show answer
The three deposits stay inside the seven-day window from Wednesday's run until the Monday deposit ages out. The Monday deposit leaves the window on the second Monday after it was made, so the count drops below 3 from that Monday night onward. Runs on Wednesday, Thursday, Friday, Saturday, Sunday, and the next Monday night still see all three deposits, which gives about six alerts for one pattern. The fix is to compare the new match's transaction IDs (txn_ids) with those of open alerts for the same customer and scenario, and suppress or append when they overlap.
Exercise
Why should an alert store a snapshot of the parameters used, and not just the name of the segment's parameter set?
Show answer
Parameter sets are edited during tuning. If the alert stores only the name, such as "retail", nobody can tell later which thresholds were in effect when it fired. A snapshot or version number lets reviewers and validators reproduce the alert and explain why it fired under the thresholds of that day.
Exercise
A batch alert has createdat of 2026-03-06 23:00 and windowend of 2026-03-05 09:15. Which date describes when the suspicious activity occurred, and which describes when the system detected it?
Show answer
The window start and end describe when the activity occurred, here ending on 2026-03-05. The created_at value describes when the system detected it, 2026-03-06 23:00. Reports should keep the two separate.