Drift monitoring
A calibration profile is only as valid as its exchangeability assumption. CLI’s drift monitors are anytime-valid e-processes: sequential tests that stay honest under continuous checking, so you can look at a monitor every hour for a year without inflating its false-alarm rate above the number you configured. The math is on E-values.
Creating a monitor
from cli_sdk import CLIClient
with CLIClient() as client:
monitor = client.calibration_profiles.monitors.create(
"support-routing-v3",
type="coverage",
target=0.88,
false_alarm_rate=0.05,
)
print(monitor.id, monitor.status) # mon_..., "active"
fingerprint = client.calibration_profiles.monitors.create(
"support-routing-v3",
type="fingerprint",
)
for m in client.calibration_profiles.monitors.list("support-routing-v3"):
print(m.id, m.type, m.target, m.false_alarm_rate, m.status)| Argument | Default | Meaning |
|---|---|---|
profile | required | The profile to watch. |
type | "coverage" | "coverage", "risk", or "fingerprint". |
target | required except for fingerprint | Coverage floor or risk ceiling the monitor tests, in . |
false_alarm_rate | 0.05 | in : the chance of ever alarming while the guarantee holds. The alarm threshold is . |
labelled_sample_rate | None | The fraction of traffic you plan to label; recorded with the monitor for your own bookkeeping. |
use_judge_pseudo_labels | False | Record judge-labelled outcomes as assisted points (see below). |
An invalid type, a missing target, or a false_alarm_rate outside
raises ConfigurationError before any request is sent. A monitor
whose type does not match the profile’s guarantee is refused with 422,
and a profile holds at most 20 monitors. Over HTTP, "on_alarm": "stale"
also marks the profile stale when the monitor alarms, so its answers fail
closed until it is recalibrated; the default, "alert_only", only raises
the alert.
What it watches
| Monitor type | Profiles | What it detects |
|---|---|---|
coverage | Set, Interval, Claim, Judge, Route | Realized coverage drifting below target. For a Claim, an outcome is covered when every retained claim is supported; for a Judge, when the verdict matches (or went to the human queue); for a Route with accuracy, when the served output is right; for a Route with cost_budget, when the request stayed within target_cents |
risk | Gate | Realized risk drifting above target: for risk and risk_high_probability gates, an approved and wrong decision is a loss; for fdr gates, the wrong fraction among approved decisions (escalated decisions are skipped) |
fingerprint | any | A request reaching the profile with a different backend fingerprint, or the provider serving a different model than the one seen at calibration |
A Belief profile carries a calibration statement, not a coverage or risk
bound, so only a fingerprint monitor applies to it.
Set a coverage monitor’s target at or below the lower end of the
profile’s realized_coverage_ci (0.88 for a profile whose interval is
). The monitor tests the coverage of the calibration you
actually deployed, which scatters around the nominal ; a
target set exactly at can eventually, and correctly, flag a
profile that landed slightly under it.
Feeding outcomes
A coverage or risk monitor learns from labelled production outcomes; the service never labels traffic itself. There are two ways to send labels.
Outcomes for answers you already served. When the true answer becomes known (the agent who finally handled the ticket, the reviewer’s verdict), send it with the request id of the answer. The service looks up the answer it served and makes no model call:
import os
import uuid
import httpx
API = os.environ.get("CLI_BASE_URL", "https://cci.gitdate.ink/api/v1").rstrip("/")
def send_outcomes(profile, outcomes):
response = httpx.post(f"{API}/calibration-profiles/{profile}/outcomes", json={"outcomes": outcomes},
headers={"Authorization": f"Bearer {os.environ['CLI_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4())},
timeout=60)
response.raise_for_status()
return response.json() # {"accepted": n, "rejected": [...], "monitors": [...]}
result = client.evaluate(context=ticket, backend=backend, queries={"department": DEPARTMENT})
store(ticket_id, result.request_id)
# ... days later, when the ticket is closed:
send_outcomes("support-routing-v3", [
{"request_id": request_id_for(ticket_id), "query_id": "department", "label": final_team},
])An outcome can instead carry a context and a label; the service then
answers that context with the current calibration (one model call) and
scores the result. Up to 1,000 outcomes per call; outcomes on heuristic
answers are skipped. Outcomes feed monitors only: they never change the
calibration.
Examples appended to the profile. Each human-labelled example you add
to a calibrated profile is first answered with the calibration as it
stood, and that outcome is fed to the monitors before the example is
folded into the calibration. Labelling a random sample of production
traffic and uploading it with add_examples therefore both monitors the
profile and grows it.
Either way, label a random sample: outcomes chosen because they look wrong, or only the cases a human happened to review, bias the monitor.
Why anytime-valid matters here
A classical significance test controls its false-alarm rate only at a
single, pre-committed sample size. Checking it repeatedly as data arrives
— the natural way to watch a production system — inflates the true
false-alarm rate well above the stated number (to 43% in the simulation on
E-values). E-process monitors avoid
this by construction: the probability that the monitor ever alarms
while the guarantee holds is at most false_alarm_rate, for any stopping
rule, including “check continuously and alert the instant the evidence
crosses the threshold”.
The service computes each outcome once, when it arrives, and keeps the monitor’s 0/1 stream; the e-value is rebuilt from that stream. Polling is therefore free, deterministic and never calls a model, however often you do it.
Responding to an alert
for alert in client.calibration_profiles.monitors.poll("support-routing-v3"):
if alert.type == "coverage" and alert.severity == "critical":
pause_auto_actioning(profile=alert.profile)
notify_oncall(alert.message, e_value=alert.e_value, n=alert.n)
elif alert.type == "fingerprint":
notify_oncall(alert.message, reason=alert.details.get("details", {}).get("reason"))poll(profile, monitor_id=None) yields the alerts raised since the last
poll, across every monitor on the profile (or one monitor when
monitor_id is given): each monitor keeps a read cursor on the service,
and a poll advances it. The async client returns a list. Over HTTP,
GET .../monitors/{id}/alerts?all=true returns every alert, and
?since=<ISO time or alert id> the alerts after that point, without
moving the cursor.
Alert field | Meaning |
|---|---|
type | "coverage", "risk", or "fingerprint" |
severity | "critical" for an e-process alarm, "warning" for a fingerprint change |
profile | The watched profile |
n | Outcomes observed when the alert fired (None for fingerprint alerts) |
e_value | The evidence; at or above 1 / false_alarm_rate when it fired |
target, false_alarm_rate | The monitor’s configuration |
detected_at, message | When, and a human-readable summary |
details | The other fields the service sent: the alert id, monitor_id, profile_version, and for fingerprint alerts details.reason (request_backend, backend_fingerprint or observed_model) |
An alarmed monitor’s status becomes triggered. When the profile is
recalibrated to a new version, its monitors become superseded: create
fresh ones for the new version. The monitor’s e-value trajectory is in the
dashboard under Observability > Monitors, and its raw outcome stream at
GET .../monitors/{id}/points. To page someone, add an alert rule on the
monitor_alarm metric with a webhook or Slack channel
(Observability: alerts).
A fingerprint alert typically fires before a coverage alert does: it
catches a backend change on the first request that shows it, or a
provider serving a different model as soon as the response metadata
says so, rather than waiting for enough mislabelled traffic to
accumulate statistical evidence. The coverage monitor is what catches a
change that does not show up in metadata; see the
silent model update guide.
Running a monitor locally
LocalMonitor runs the same e-process in your own process, with no
network access, for air-gapped deployments or for replaying logs:
from cli_sdk import LocalMonitor
monitor = LocalMonitor(type="coverage", target=0.88, false_alarm_rate=0.05,
profile="support-routing-v3")
for label, prediction_set in labelled_stream:
alert = monitor.update(label in prediction_set)
if alert:
page_oncall(alert)
breaktype is "coverage" (feed covered booleans) or "risk" (feed is_loss
booleans). update returns an Alert the first time the evidence crosses
1 / false_alarm_rate, and None otherwise. Start a new monitor for each
new profile version: a monitor that has watched a long in-spec period
needs longer to fire after a change (see
E-values: detection delay).
Label-free monitoring
When production labels are expensive, it is tempting to let a judge label
the stream. On the hosted service, use_judge_pseudo_labels=True records
outcomes whose source is "judge" as assisted points: they appear
in the monitor’s points and on its trajectory in the dashboard, so you can
see early what a judge thinks, but they never enter the e-process and
never raise an alarm on their own. Without the flag, judge-sourced
outcomes are ignored by the monitor.
The anytime-valid false-alarm guarantee rests on true labels, so the alarm does too. Treat a trend in the assisted points as a reason to label a fresh random sample, and let the true labels decide:
client.calibration_profiles.monitors.create(
"support-routing-v3",
type="coverage",
target=0.88,
false_alarm_rate=0.05,
use_judge_pseudo_labels=True,
)The prediction-powered machinery of label-efficient calibration is the right tool for estimating a rate from many judge labels and a few human ones; the estimate is large-sample, not anytime-valid.