The new prompt won the offline evaluation, you sent it 50% of traffic, and the dashboard shows +3% thumbs-up. Before you ship it, check that the difference isn't caused by assignment, caching, missing data or repeated looks at the results. Work through this list before, during and after the test.
Before the test: design
- One change per test. A model swap with a rewritten prompt and a new temperature can't be attributed to anything.
- One primary metric, chosen in advance and tied to the user's goal: resolution without escalation, accepted edit, completed task. Thumbs-up is sparse and biased, so treat it as secondary.
- Guardrail metrics with limits: p95 latency, cost per conversation, refusal rate, format-error rate, escalation rate. Breaching one stops the test, whatever the primary metric says.
- Assignment unit equals the level where state is shared. Use the user or tenant if there is memory or chat history, otherwise the conversation. Never the request: one conversation would mix both variants.
- Analysis matches the unit. If you assign by user, users are the sample, not messages.
- Stop rule written down: a fixed end date and sample size, or a sequential method.
Size it
For a conversion-type metric, per arm:
from scipy.stats import norm
def n_per_arm(p: float, mde: float, alpha=0.05, power=0.8, design_effect=1.0) -> int:
"""p: baseline rate, mde: absolute difference you must detect."""
q = p + mde
z = norm.ppf(1 - alpha / 2) + norm.ppf(power)
n = z**2 * (p * (1 - p) + q * (1 - q)) / mde**2
return int(n * design_effect) + 1
print(n_per_arm(0.62, 0.02)) # independent observations
print(n_per_arm(0.62, 0.02, design_effect=1.8)) # correlated ones
If the result exceeds your traffic for a month, don't run the test hoping for luck. Test a bigger change, use a more sensitive metric, or rely on offline evaluation plus a guarded rollout.
The design effect is about 1 + (m - 1) * icc, where m is the average observations per unit and icc is their correlation within a unit. Estimate it from last month's logs.
Before the test: plumbing
- Deterministic, salted assignment. The same unit always gets the same variant, and a new experiment reshuffles everyone.
import hashlib
def assign(experiment: str, unit_id: str, treat_share: float = 0.5) -> str:
h = hashlib.sha256(f"{experiment}:{unit_id}".encode()).digest()
bucket = int.from_bytes(h[:8], "big") / 2**64
return "treatment" if bucket < treat_share else "control"
- Don't change the split mid-test. Moving from 10% to 50% moves some users from control to treatment, and they carry history from the old arm. Start a new experiment name, or analyse each phase separately.
- Exposure logged where the variant takes effect, not where it is computed. Requests that are blocked or served from a cache were not exposed.
- Fallbacks recorded. If treatment times out and falls back to the control model, log both
assignedandserved. Analyse byassigned, or you silently remove treatment's failures. - Variant in cache keys. A semantic or response cache shared between arms serves control's answers to treatment.
- Versions pinned. Log the dated model version, prompt hash and retrieval index version on each exposure. An alias that moves during the test invalidates it.
Warning
Provider prompt caching also biases latency and cost. At a 1% share, the new prompt's prefix is rarely warm, so treatment looks slower and dearer than it will at full traffic. Compare cached-token ratios before judging either metric, or use equal shares.
Use a table with one row per first exposure:
CREATE TABLE llm_exposure (
experiment text NOT NULL,
unit_id text NOT NULL,
assigned text NOT NULL CHECK (assigned IN ('control','treatment')),
served text NOT NULL,
model_version text NOT NULL,
prompt_hash text NOT NULL,
exposed_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (experiment, unit_id)
);
Insert with ON CONFLICT DO NOTHING, and log per-request detail elsewhere.
- A/A test passed. Run both arms on the same prompt for a few days. It should show no difference; if it does, fix the plumbing first.
During the test: health, not results
- Sample ratio mismatch (SRM) check daily. A 50/50 test with 50,900 and 49,100 units looks harmless, but it's broken.
from scipy.stats import chisquare
def srm(control: int, treatment: int, treat_share=0.5) -> float:
total = control + treatment
return chisquare([control, treatment],
[total * (1 - treat_share), total * treat_share]).pvalue
p = srm(50_900, 49_100)
print(p, "SRM: stop and investigate" if p < 0.001 else "ok")
Common causes: exposure logged after a step that one arm fails more often, bots removed in one arm, a client crash on long answers, or redirects.
Caution
Never repair SRM by dropping or reweighting rows. The missing units are usually the ones that had a bad experience, so any result from the remainder is biased. Fix the cause and restart under a new experiment name.
- Missing outcomes compared by arm:
SELECT e.assigned,
count(*) AS units,
avg((o.unit_id IS NULL)::int) AS missing_outcome,
avg((e.assigned <> e.served)::int) AS fell_back
FROM llm_exposure e
LEFT JOIN llm_outcome o USING (experiment, unit_id)
WHERE e.experiment = 'prompt-v7'
GROUP BY e.assigned;
- Version drift: count distinct
model_versionandprompt_hashper arm. Each should be 1. - Guardrail kill rule automated, and tested before launch, so that nobody needs to be watching.
- No early win declared. Checking a 95% interval daily and stopping at the first significant day raises the false-positive rate far above 5%. If you must peek, use a method built for it, such as group sequential boundaries or an always-valid interval.
After the test: analysis
- Interval clustered by unit. Users with many conversations are not many independent samples. Bootstrap units, not rows:
import numpy as np
def cluster_bootstrap(num_c, den_c, num_t, den_t, n_boot=5000, seed=7):
"""Arrays with one entry per unit: successes and attempts."""
rng = np.random.default_rng(seed)
num_c, den_c, num_t, den_t = map(np.asarray, (num_c, den_c, num_t, den_t))
def rate(num, den, idx):
return num[idx].sum() / den[idx].sum()
diffs = np.empty(n_boot)
for i in range(n_boot):
ic = rng.integers(0, len(num_c), len(num_c))
it = rng.integers(0, len(num_t), len(num_t))
diffs[i] = rate(num_t, den_t, it) - rate(num_c, den_c, ic)
point = num_t.sum() / den_t.sum() - num_c.sum() / den_c.sum()
return point, np.percentile(diffs, [2.5, 97.5])
- Attempts per user compared. A ratio metric can improve because unhappy users stopped trying. Check attempts and returning users by arm.
- Decision from the interval, not the p-value:
| Interval for the difference | Guardrails | Decision |
|---|---|---|
| Entirely above the minimum useful effect | Pass | Ship |
| Above zero, includes trivial effects | Pass | Ship if cost and risk are no worse |
| Includes zero, lower end within tolerance | Pass, cheaper or faster | Ship as non-inferior, if that was planned |
| Includes zero, wide | Pass | Inconclusive, not "no difference" |
| Entirely below zero | Any | Roll back |
| Any | Breach | Roll back |
- Segments treated as leads. With twenty segments, one will look significant by chance. Confirm it in a new test. Harm in a critical segment is the exception: investigate that before shipping.
- Novelty considered. Plot the effect by days since first exposure. A lift that fades was curiosity.
- Judge scores not treated as ground truth. An LLM judge may prefer the style of its own model family, which biases a model swap. Blind-review a random sample from both arms.
Failure patterns
| Symptom | Likely cause | Check |
|---|---|---|
| Huge lift on day one | Logging or cache bug | A/A test, cache keys |
| Offline win, online flat | Test set unlike traffic | Compare intent mix |
| Thumbs-up rises, escalations rise too | Agreeable but wrong answers | Primary metric choice |
| Treatment latency much better | Failures excluded, or shorter answers | Analyse by assigned, token counts |
| Result flips after adding a week | Underpowered, or weekly cycle | Run whole weeks |
Prevent it next time
- Keep a permanent low-traffic A/A test, and alert when its SRM check fails.
- Store the design (metric, unit, size, stop rule) in Git, and have it reviewed before launch.
- Keep one shared assignment library and one exposure table, instead of one per team.
- Keep a small long-term holdout on the old prompt to measure the combined effect of many small wins, where privacy and safety rules allow it.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get