Sub topic 9
Combining signals into a trigger policy
This chapter assumes you know the four trigger families (schedule, performance, data drift, data volume). It also assumes you can read basic Python and have computed PSI for a feature. Here you will combine those signals into one decision function with explicit rules, so the pipeline retrains for a reason you can name.
Why single signals are not enough
Each signal fails in a different way when used alone.
- A schedule alone retrains when nothing changed, and misses a sudden shift between runs.
- A drift statistic alone fires on harmless shifts. With large samples, even a tiny difference gives a very small KS p-value.
- A performance metric alone is accurate but late, because labels often arrive days or weeks after predictions.
- A data volume threshold alone says nothing about whether the new data differs from the old.
A trigger policy is a small, deterministic function. It takes the current signals and returns a decision and a reason. Keeping it a plain function makes it unit-testable, and the logged reason tells you why a run started.
The ingredients of a policy
| Ingredient | Question it answers | Typical form |
|---|---|---|
| Maximum model age | Is this model too old to trust, even if nothing looks wrong? | A hard ceiling such as 30 days |
| Drift threshold | Have the inputs moved enough to matter? | Maximum PSI across features at or above 0.2 |
| Minimum new data | Is there enough fresh data to train something better? | A row count, such as 50,000 |
| Cooldown | Did we retrain too recently to learn anything new? | A minimum gap, such as 2 days |
| Performance floor | Has measured quality dropped? | A metric on labeled data below a limit |
The first four are in the code below. A performance floor follows the same pattern: add a recent_auc argument and a rule that returns True, "performance_drop". Compute it only on predictions whose labels have arrived. Because of label delay, it describes the past, so it usually backs up the drift rule instead of replacing it.
Rule order matters
The order of the checks is part of the policy. The version below checks in this order:
- Cooldown first. It blocks everything else. If the model was just retrained, a drift alarm is most likely the old model's data still flowing through the monitoring window.
- Maximum age second. It is a safety net that fires regardless of other signals.
- Drift with enough data third. Drift alone is not enough. A drift signal only triggers when there is also enough new data to train on.
- Default: do nothing.
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
@dataclass(frozen=True)
class TriggerConfig:
psi_threshold: float = 0.2
min_new_rows: int = 50_000
max_model_age: timedelta = timedelta(days=30)
cooldown: timedelta = timedelta(days=2)
def should_retrain(now, last_trained, max_feature_psi, new_rows, cfg):
"""Return (decision, reason) from schedule, drift, and volume signals."""
age = now - last_trained
if age < cfg.cooldown:
return False, "cooldown"
if age >= cfg.max_model_age:
return True, "max_model_age"
if max_feature_psi >= cfg.psi_threshold and new_rows >= cfg.min_new_rows:
return True, "drift_with_enough_data"
return False, "no_trigger"
now = datetime(2026, 11, 30, tzinfo=timezone.utc)
cfg = TriggerConfig()
scenarios = {
"drift, enough data": (timedelta(days=10), 0.31, 80_000),
"drift, too little data": (timedelta(days=10), 0.31, 10_000),
"quiet, mid-age": (timedelta(days=10), 0.05, 80_000),
"very old model": (timedelta(days=45), 0.00, 0),
"just retrained": (timedelta(days=1), 0.90, 100_000),
}
for name, (age, psi_value, rows) in scenarios.items():
print(name, "->", should_retrain(now, now - age, psi_value, rows, cfg))Running it prints:
drift, enough data -> (True, 'drift_with_enough_data')
drift, too little data -> (False, 'no_trigger')
quiet, mid-age -> (False, 'no_trigger')
very old model -> (True, 'max_model_age')
just retrained -> (False, 'cooldown')Two details are easy to miss. The config is a frozen dataclass, so thresholds cannot change mid-run and every decision can be reproduced from the logged config. The function receives now as an argument instead of calling datetime.now(), which lets tests pin time.
Choosing thresholds
Thresholds should come from evidence, not defaults.
- PSI. The common rule of thumb is that values under 0.1 are stable, 0.1 to 0.25 are moderate shifts, and above 0.25 are large. The 0.2 in the example is a starting point. Replay your history: compute PSI per week and check which values preceded real metric drops.
- Aggregating across features. The example takes the maximum PSI over all features. With many features, one noisy feature can fire the trigger. Alternatives are the maximum over the top features by importance, or a count of features above the threshold.
- Minimum rows. Pick the amount of data at which a retrained model is measurably different from the current one. Learning curves on your own data can give you this number.
- Maximum age. Set it from how fast your domain changes, and from how long you can tolerate an unnoticed failure of the other signals.
- Cooldown. It should be longer than the time needed to train, evaluate, and roll out, plus enough monitoring time to see the new model's behavior.
Failure modes
- Flapping. A PSI value hovering near 0.2 can cross the threshold repeatedly. The cooldown limits the damage. You can also require the threshold to be exceeded on two consecutive monitoring windows.
- Retraining loop. If the new model changes what data you collect, as with a recommender that shapes its own clicks, drift may reappear after every retrain. Cooldowns and a budget cap stop this loop. The longer-term fix is to investigate the feedback.
- Silent signals. If the monitoring job fails,
max_feature_psimay be missing or stale. Treat missing signals as an error and alert on them. Do not default them to zero, because that quietly disables the drift rule. - Drift that is a bug. A broken upstream join looks like drift. Data validation runs before training for this reason. Retraining on corrupt data makes the problem worse.
Where the policy runs
The policy is evaluated on a frequency of its own, such as daily after the monitoring job. This is separate from how often the model trains. If the result is True, the policy starts the pipeline through your orchestrator. It can also start the pipeline from a manual trigger, such as a workflow_dispatch event in CI, for cases where an engineer overrides the policy. Manual overrides should still respect the evaluation gate.
Exercise
A model was last trained 12 days ago. Today the maximum feature PSI is 0.27, but only 20,000 new rows have arrived, and the minimum is 50,000. Using the default TriggerConfig, what does shouldretrain return, and what single change to the inputs would make it return a retrain decision with the reason "driftwithenoughdata"?
Show answer
It returns (False, "notrigger"). The age is above the 2-day cooldown and below the 30-day maximum, and PSI is above 0.2, but 20,000 rows is below 50,000. Raising newrows to at least 50,000 (with PSI unchanged) makes it return (True, "driftwithenough_data").