LLM Migration Testing: From Evaluation to Canary Rollout and Rollback
A practical guide for algorithm and platform teams evaluating candidate LLMs or replacing a production model. Learn how to freeze representative task sets, conduct blinded scoring, interpret confidence intervals, compare reasoning settings, and manage staged rollouts with measurable rollback criteria and reproducible evaluation scripts.
1. Define the Metrics First
This guide is for algorithm and platform teams evaluating text generation, code generation, structured output, and UI generation within business applications. It addresses two decisions: choosing among candidate models and determining whether a new version can replace the current production version.
Model training, security red teaming, and general-purpose leaderboards are outside its scope.
Before evaluation begins, agree on three metrics.
Quality Score
Score each sample on four dimensions, assigning 0, 1, or 2 points per dimension. Normalize the total to a value between 0 and 1:
Quality score = Sum of dimension scores / (2 × Number of dimensions)
For example, scores of 2, 2, 1, and 2 produce a total of 7 and a normalized quality score of:
7 / (2 × 4) = 0.875
Cost
Calculate the cost per task as:
Cost per task =Input tokens × Input token price+ Output tokens × Output token price
Read token counts from the API response’s usage field and obtain prices from the provider’s pricing page. State the currency and billing unit in the report, typically a price per million tokens. Cost per 1,000 tasks equals cost per task multiplied by 1,000.
For example, assume 1,200 input tokens, 400 output tokens, an input price of CNY 2 per million tokens, and an output price of CNY 8 per million tokens:
Cost per task =1,200 × 2 / 1,000,000+ 400 × 8 / 1,000,000= CNY 0.0056Cost per 1,000 tasks = CNY 5.6
Latency
Measure latency on the client, from sending the request to receiving the complete response, including network time.
Report p50 and p95 latency rather than substituting an average. Complete at least 100 successful calls per model before calculating percentiles.
2. Freeze the Task Set and Establish Data Governance
2.1 Task Categories and Sample Size
Common categories include:
- Code generation
- Structured output
- Long-document comprehension
- UI and graphics generation
- Instruction following with multiple constraints
Prepare approximately 100 samples per category.
The sample-size rationale comes from the confidence interval for a binomial proportion, used to estimate an individual model’s win rate. The interval is widest when the win rate, p, is close to 0.5, making this the conservative assumption.
The approximate half-width of a 95% confidence interval is:
1.96 × √(p(1 − p) / n)
Examples:
- n = 100, p = 0.5: approximately ±9.8 percentage points.
- n = 30, p = 0.5: approximately ±17.9 percentage points, sufficient only to distinguish large differences.
- n = 100, p = 0.3: approximately ±9.0 percentage points.
These figures describe the interval for an individual model’s win rate. The confidence interval for the mean quality-score difference between two models, discussed in Section 3.3, uses a different calculation. Do not interchange the two.
When the expected win rate is farther from 0.5, the interval narrows, allowing finer distinctions. If a category has fewer than 100 samples, document the smallest difference the evaluation can distinguish, or combine similar categories for analysis.
2.2 Stratified Sampling
Draw samples from production logs and stratify them by difficulty:
- Easy: 30%
- Medium: 40%
- Hard: 30%
Two annotators should independently classify difficulty based on the number of task steps, number of constraints, and historical failure rate. A third person resolves disagreements.
Follow these sampling rules:
- Fix the random seed and record it in the evaluation record.
- Preserve conversational wording, missing fields, and ambiguous requirements. These are common sources of production failures; testing only clean inputs overestimates reliability.
- Give every sample a reference standard, such as unit tests, a JSON Schema, a human-written reference answer, or rendering-check rules. Exclude samples without a reference standard.
Use the following task-set fields:
| Field | Meaning | Example |
|---|---|---|
sample_id |
Unique sample identifier | code-0012 |
category |
Task category | code generation |
difficulty |
Easy, medium, or hard | medium |
prompt |
Redacted input | Generate JSON from the following order description |
reference |
Reference type and relative path | unit_test:tests/cases/code_0012.py |
redacted |
Whether redaction is complete: true or false |
true |
seed |
Sampling seed | 20261124 |
The reference field contains a type followed by a relative path.
Check redaction flags with:
jq -c 'select(.redacted != true)' taskset/v1.jsonl
No output means every sample is marked true.
2.3 Version Freeze
Store the task set as JSONL in the code repository. Before each evaluation, calculate its SHA-256 hash and include that hash in the report.
Do not modify the task set during evaluation. If samples must be added or removed, create a new file and hash, then rerun the baseline. Do not directly compare reports produced from different task-set versions.
2.4 Data Governance
Complete three steps before business data enters the evaluation:
- Redaction: Replace phone numbers, government-issued identification numbers, email addresses, physical addresses, customer names, and similar fields with placeholders. Redaction scripts must have unit tests and undergo review by a second person.
- Authorization: Obtain written approval from the data owner specifying the purpose, retention period, and access scope.
- Isolation: Keep evaluation data out of training sets, prompt caches, and ordinary logs. Before calling an external model API, confirm that the service contract permits processing this type of data.
Record access to keys and evaluation data in a separate audit log, stored independently from evaluation reports.
3. Blinded Scoring and Migration Decisions
3.1 Blinded Evaluation Workflow
Knowing which model produced an output can bias reviewers. Use the following process:
- Run every sample three times on each model. Save all three outputs.
- Use the mean of the three quality scores as the primary metric. Also record the minimum score and score range. Flag a sample as unstable when its range is at least 0.3, and report the proportion of unstable samples separately. For hard pass/fail checks, such as parsing or execution, use a majority vote: at least two of the three runs must pass.
- Randomize left/right placement. For each sample, use
random.Random(seed + sample_index)to generate a Boolean determining whether model A appears on the left or right. Store each sample’s mapping in a key file. - Check the placement distribution. Model A should appear on the left in 45%–55% of samples. If it falls outside this range, change the seed, reassign positions, and record the new seed.
- Remove identifying metadata. Strip model names, version numbers, and timing information. Reviewers should see only the task description and output.
- Restore model identities after scoring using the key file, then calculate metrics.
Each scoring-table row represents one run of one model on one sample. Fields include sample_id, left/right position, the four dimension scores, a rendering-check score for UI tasks only, and reviewer ID. Both reviewers must use the same fields so their results are comparable.
The evaluation lead stores the mapping key in encrypted storage. Unlock it only after scoring is complete and the report has been archived. Retain the key for 180 days after report archival, then destroy it and record the destruction in the audit log.
Before formal scoring, reviewers should practice on 20 calibration samples. Their independently assigned scores must achieve a Cohen’s kappa above 0.6 before formal review begins.
During formal review, randomly select 10% of samples for a second reviewer to check. A third person resolves disagreements; record both the final decision and its rationale.
3.2 Scoring Dimensions
Assign 0, 1, or 2 points to each dimension.
| Dimension | Evaluation question | 0 points | 1 point | 2 points |
|---|---|---|---|---|
| Correctness | Does the result meet the requirements? | Factual or logical errors | Mostly correct, with minor issues | Fully correct |
| Completeness | Does it cover all constraints? | Multiple constraints omitted | One constraint omitted | All constraints covered |
| Usability | Does the code run, or can software parse the format? | Cannot run or fails parsing | Minor changes required | Ready to use |
| Presentation quality | Is the structure clear and free of redundancy? | Disorganized | Clear but redundant | Clear and concise |
For UI and graphics generation, replace correctness with rendering checks. Run these checks in a headless browser, such as Playwright or Puppeteer, and save screenshots and console logs.
Use these rendering scores:
- 0: Rendering fails, the page is blank, or the console contains an uncaught script exception.
- 1: The page renders, but one required key element—such as a heading, button, chart, or data table—is missing, or a key interaction does not work.
- 2: The page renders, all required elements are present, and key interactions work.
The rendering score contributes to the normalized quality score like every other dimension, without separate weighting.
3.3 Confidence Intervals and Migration Thresholds
For each category, calculate paired quality-score differences using the same samples for the old and new models:
d_i = Q_new,i − Q_old,i
Here, Q is the quality score averaged over three runs. A positive mean(d) indicates higher average quality for the new model; a negative value indicates lower average quality.
Calculate:
Mean difference = mean(d)Standard error:SE = s_d / √n95% confidence interval:mean(d) ± 1.96 × SE
Here, s_d is the sample standard deviation of the paired differences, and n is the number of samples.
The smallest distinguishable difference depends on s_d. If s_d is approximately 0.3 and n = 100, the interval half-width is:
1.96 × 0.3 / 10 = 0.059
This gives a resolution of approximately 0.06 quality-score units. At n = 30, the half-width is approximately 0.11.
Use the following decision rules, adjusting thresholds to business risk. The threshold of −0.02 is expressed on the normalized 0–1 quality scale: it sets an acceptable average quality decrease of no more than 0.02.
- Migrate: The confidence interval’s lower bound is at least −0.02, and cost and latency meet business constraints.
- Do not migrate: The upper bound is below −0.02. This provides statistical evidence that the new model’s average quality is more than 0.02 below the old model’s.
- Inconclusive: The interval crosses −0.02. Add samples or narrow the candidate set and reevaluate; do not migrate directly.
The report must include:
- Category name
- Sample count
mean(d)- Standard error
- 95% confidence interval
- Win rate, counting ties as 0.5, and its confidence interval
- Proportion of unstable samples
- Smallest distinguishable difference
- Decision
4. Compare Reasoning Effort Levels
Quality, cost, and latency can vary substantially across reasoning settings on the same model. Hold other variables constant so differences can be attributed to reasoning effort.
Test three levels:
- Low: Reasoning disabled or the reasoning budget minimized
- Medium
- High: Maximum reasoning budget
Parameter names vary by provider—for example, reasoning_effort or a thinking budget. Follow the relevant API documentation.
For a controlled comparison:
- Keep prompts, maximum output length, temperature, and task set identical.
- Cover every task category at every level using the same samples.
- Record quality score, cost per task, and p50 and p95 latency for each level.
Choose a baseline level before evaluation and record it in the report. Define the comparison as:
mean(d) = Comparison-level quality score − Baseline-level quality score
Apply the decision rules in Section 3.3. If a level’s confidence-interval lower bound is at least −0.02, its quality difference is within the acceptable range; choose the level with lower cost or latency.
If the high setting delivers a clear quality improvement but increases cost by more than 50%, document the quality gain relative to the additional cost and leave the decision to the business owner.
Report each level separately rather than combining different reasoning settings into one migration decision.
5. Canary Rollout, Rollback, and Evaluation Scripts
5.1 Rollout Stages
Increase traffic to the new version in stages:
5% → 20% → 50% → 100%
Advance only when all of the following conditions are met:
- The stage has been observed for at least 24 hours.
- The stage has handled at least 1,000 requests, or all task categories have been covered during the observation period.
- No rollback metric has been triggered.
Control traffic through a routing-layer switch rather than changing application code. Keep the old version running for at least seven days to support a rapid rollback.
5.2 Rollback Metrics and Stop Conditions
Calculate the following metrics in five-minute sampling windows.
For baseline-dependent thresholds, use the mean from matching business time periods over the seven days before migration. Document the baseline’s calculation window and sample size to keep comparisons consistent.
| Metric | Rollback threshold |
|---|---|
| Sampled quality score: randomly select 50 requests per window for manual or automated scoring | More than 0.03 below baseline |
| Structured-output parsing failure rate | More than 0.5 percentage points above baseline |
| API 5xx error rate | Above 1% |
| p95 latency | More than 20% above baseline |
| Average cost per task | More than 15% above baseline |
If any threshold is breached in two consecutive windows, roll back immediately. A breach in one window pauses further traffic increases while monitoring continues.
To roll back, switch routing to the old version, targeting completion within five minutes. Preserve incident logs and failed samples. The responsible owner must document the root cause within one business day and add failed samples to the next task-set version.
5.3 Evaluation Scripts
The scripts are located in the repository’s eval/ directory and require Python 3.10 or later.
Before running them:
- Check the Python version with
python3 --version; it must be 3.10 or later. - Install dependencies with
pip install -r eval/requirements.txt. Use the package versions pinned in that file; do not upgrade them individually. - Configure model credentials through environment variables or a secret-management service. Do not put credentials in code or command-line arguments. Refer to the repository README for variable names.
- Verify that
--effortvalues map directly to the reasoning parameters in the API documentation. Allowed values arelow,medium, andhigh.
After installing dependencies, run the scripts in this order.
Step 1: Freeze the Task Set and Calculate Its Hash
python eval/freeze_taskset.py --input data/raw_samples.jsonl --output taskset/v1.jsonl --seed 20261124
This produces taskset/v1.jsonl and taskset/v1.sha256. The script checks the redacted field and exits with an error if any sample has a value of false.
Step 2: Run the Models
python eval/run_models.py --taskset taskset/v1.jsonl --models model_old,model_new --runs 3 --effort low,medium,high --timeout 120 --out runs/2026-11-24/
Parameters:
--runs: Number of repeated runs per sample.--effort: Reasoning levels to evaluate. Specify one level if no reasoning-effort comparison is needed.--timeout: Timeout in seconds for each request.
The output includes each run’s raw response, usage field, and client-measured duration. Filenames contain the sample ID, model name, effort level, and run number.
Step 3: Generate the Blinded Review Package
python eval/make_blind.py --runs runs/2026-11-24/ --seed 20261124 --key keys/2026-11-24.enc --out blind/
This produces reviewer materials under blind/, with model names and timing information removed, plus an encrypted mapping-key file.
The script checks the left/right distribution automatically. If it falls outside 45%–55%, the script returns an error; change the seed and rerun it.
Step 4: Score and Restore Model Identities
python eval/score_report.py --blind-scores scores/ --key keys/2026-11-24.enc --taskset taskset/v1.jsonl --confidence 0.95 --report reports/2026-11-24.json
The report includes:
- Task-set hash
- Run seed
- Sample count by category
- Mean quality score
mean(d)- Standard error
- Confidence interval
- Win rate and its confidence interval
- Proportion of unstable samples
- p50 and p95 latency by effort level
- Cost per task and per 1,000 tasks
- Decision
Step 5: Handle Failures and Reruns
- A model call fails: Retry three times using exponential backoff. If it still fails, record it as a failed sample, exclude it from the scoring denominator, and report the failure rate. If the failure rate exceeds 5%, invalidate the evaluation, investigate API or network issues, and rerun the entire evaluation.
- The scoring script fails: Fix the issue and rerun only
score_report.py, using the saved raw responses and blinded scoring files. Do not call the models again; this preserves reproducibility. - The task-set hash differs from the report record: Stop immediately. Do not produce a migration conclusion.
5.4 Prelaunch Checklist
- The report contains the task-set hash, and the task set remained unchanged throughout evaluation.
- Every sample has
redacted: true; authorization documents and redaction-review records are archived. - Left/right placement falls within 45%–55%, and reviewer agreement exceeds 0.6.
- A second person has verified the quality-score formula and the direction of the migration thresholds.
- The confidence interval’s lower bound meets the migration threshold, and cost and latency meet business constraints.
- The responsible owner has approved the canary plan, rollback thresholds, and old-version retention period.
- Archive locations for the report, blinded review materials, and mapping key are recorded, and the key’s destruction date is scheduled.
