A one-line prompt edit is a deploy, so run a canary
Formatting changes alone have shifted accuracy by about 5%; a feature flag, a control group and a 5-20-50-100% schedule help catch failures before clients do.
In brief
- A prompt or model that works in staging can still degrade the experience in production, so every change needs a flag and a control group.
- Log variation and prompt_version when the LLM is called. Log them at page load and the canary numbers will be wrong.
- A small canary can miss the rare questions that trip up the model, so promote each stage only once it has enough samples, however good the dashboard looks.
Small changes to prompt formatting have shifted accuracy by about 5%, according to an analysis on the tianpan.co blog. LaunchDarkly gives a similar warning: after a minor prompt edit or a model swap, a system can run well in staging and still degrade the user experience in production.
Take a hypothetical client that asks you to make its support chatbot “more polite.” You add a few greetings, turn the bullets into a numbered list, and everything looks fine in staging. Two days later, the customer care team reports that the bot is getting the refund policy wrong.
Turning bullets into numbers is therefore a deploy too. This guide walks through building the whole process yourself: a feature flag that splits traffic between the old and new prompts, logging to compare the two groups, a function that decides on rollback, and a schedule that climbs through 5-20-50-100%.
The code is illustrative Python, simplified and tied to no vendor’s SDK. In a real project, swap in whatever flag tool the client already uses.
A canary is a comparison
The Google SRE Workbook defines canarying as a partial and time-limited deployment of a change to a service, together with an evaluation of that change. The part that receives the change is the canary; the rest is the control. Without a control group to set it against, you are only running a trial.
What you need: Python 3, an existing function that calls an LLM (call_llm here), a queryable place to write logs, and two clearly named prompt versions, such as v1.3 and v2.0.
Step 1: Bundle prompt and model into a variation
Avoid editing the prompt string directly in code. Declare each configuration as a named variation, so that rolling back means changing a selection instead of redeploying.
FLAG = {
"name": "support_bot_prompt_v2",
"enabled": True, # emergency off switch
"rollout_percent": 5,
"internal_users": {"qa@client.example"},
}
VARIATIONS = {
"control": {"model": "current-model", "prompt_version": "v1.3"},
"canary": {"model": "current-model", "prompt_version": "v2.0"},
}
In this example the two variations differ only in the prompt. If you want to change the model, do it under a separate flag. When prompt and model change together, you cannot tell which one caused the result.
Step 2: Split users consistently, internal users first
Flagsmith describes its process for LLM features this way: first turn the feature on in production for internal users only, then open it to 5% of users, then 50% for an A/B test, and finally 100%. The code below follows that order.
import hashlib
def bucket(user_id: str, flag_name: str) -> int:
h = hashlib.sha256(f"{flag_name}:{user_id}".encode()).hexdigest()
return int(h[:8], 16) % 100
def pick_variation(user_id: str, email: str) -> str:
if not FLAG["enabled"]:
return "control"
if email in FLAG["internal_users"]:
return "canary"
if bucket(user_id, FLAG["name"]) < FLAG["rollout_percent"]:
return "canary"
return "control"
Check: run the function on 10,000 fake user_ids and count how many land in the canary; the result should be around 500. Calling it again with the same user_id must always return the same variation. Otherwise one person could get an answer from the old prompt on one turn and the new prompt on the next, adding noise to your data.
Step 3: Log at the right moment
FeatBit advises recording the variation when the LLM actually runs, rather than when the page loads. It also recommends logging promptVersion alongside it, so that if someone quietly edits the prompt midway, the change does not contaminate the canary results.
import time
def answer(user_id, email, question):
variation = pick_variation(user_id, email)
cfg = VARIATIONS[variation]
started = time.time()
reply = call_llm(cfg["model"], load_prompt(cfg["prompt_version"]), question)
log_event({
"user_id": user_id,
"flag": FLAG["name"],
"variation": variation,
"prompt_version": cfg["prompt_version"],
"model": cfg["model"],
"latency_ms": int((time.time() - started) * 1000),
})
return reply
call_llm, load_prompt and log_event are functions you already have. Check: every log line must carry all four fields: variation, prompt_version, model and latency. If one is missing, you cannot compare the two groups reliably. In a real project, also log the question type (for example refund) so the next step can count samples by type.
Step 4: Track few metrics, set thresholds first
Google SRE advises choosing only a few of the most important metrics to evaluate a canary, perhaps no more than a dozen. For a customer support chatbot, you could start with error rate, latency, the share of users who have to be handed to a human agent, and a quality score on a sample of conversations.
The function below returns one of three decisions: roll back, wait, or promote. Guardrails are checked first, because a clear failure should stop the rollout at once. To be promoted, the canary must also have enough samples, both in total and for the rare question type.
MIN_TOTAL = 500 # minimum total conversations in the canary
MIN_REFUND = 20 # minimum number of refund questions
def decide(canary: dict, control: dict) -> str:
if canary["error_rate"] > control["error_rate"] * 1.5:
return "rollback"
if canary["p95_latency_ms"] > control["p95_latency_ms"] * 1.3:
return "rollback"
if canary["handoff_rate"] > control["handoff_rate"] + 0.03:
return "rollback"
if canary["quality_score"] < control["quality_score"] - 0.05:
return "rollback"
if canary["n_total"] < MIN_TOTAL or canary["n_refund"] < MIN_REFUND:
return "wait"
return "promote"
Every threshold above is only an example. Agree on the real ones with the client before turning the canary on, rather than setting them once the numbers are in. Commercial tools take the same approach: LaunchDarkly’s guarded rollouts for AI Configs let you attach guardrail metrics and automatically roll back to the previous variation.
Step 5: How long should each stage run?
Why start at 5% rather than 1%? The tianpan.co article argues that for LLM features, a 1% canary may never reach the tail of the input distribution, the rare cases where the model’s answers get worse.
The author also notes that an LLM canary may need to run for hours or even days to collect enough labeled or proxy-labeled data.
Return to the chatbot with the refund problem. Say the client’s system handles 2,000 conversations a day, and refund questions make up 2% of traffic. At 5%, the canary receives 100 conversations a day, of which only about 2 concern refunds.
With MIN_REFUND = 20, the 5% stage needs about 10 days before decide() can return “promote”. At 1%, the figure is 0.4 questions a day, which shows you almost nothing.
Set the length of each stage by the number of samples you need, then, rather than by hours. If 10 days is too long, raise that with the client at the outset.
| Stage | Who gets the canary | Condition for promotion (suggested) |
|---|---|---|
| Internal | The client’s QA team | No serious errors left on manual reading |
| 5% | A small share of real users | Enough samples of the rare question types, no guardrail breached |
| 20% | A wider group, clearer comparison data | Quality metrics no worse than control |
| 50% | A/B test, two groups of nearly equal size | Client signs off on the results |
| 100% | All users | Keep the flag a while longer so you can roll back |
Flagsmith lists only the 5%, 50% and 100% stages. The 20% stage in the table is an added buffer that gives you clearer comparison data before the A/B test at 50%.
Step 6: Rehearse the off switch
Flagsmith writes that as soon as it sees a problem, it can turn the flag off immediately. In the code above, setting FLAG["enabled"] = False sends every user back to control. Try this once in staging with the client’s engineers, and record how many seconds the change takes to apply.
Three common mistakes
The first is changing prompt and model under the same flag, so that when results are poor you do not know which to revert. The second is logging only the canary group, leaving no control data when it is time to compare.
The third is jumping from 5% to 50% after a single afternoon because the dashboard looks fine, when the rare questions have yet to appear even once. The “wait” branch in decide() exists to prevent this.
How this skill shows up on the job
A request such as “tweak the prompt so the bot is more polite” is the kind of change this process is built for. Before taking it on, have answers ready to two questions: how do you turn it off if it goes wrong, and how long does that take?
When reading job descriptions, look for terms such as progressive delivery, feature flag, A/B testing or LLM evaluation. On your CV, go further than “used LaunchDarkly.” Be specific: you separated prompt_version in the logs, set guardrail thresholds and minimum sample sizes, took a change to 100% through four stages, and had a kill switch that took effect in a stated number of seconds.
The next time a client asks you to change the model, answer with a staged rollout schedule before you report that the change is done.
Was this article useful?
Thanks for the feedback!
5 sources
- Chapter 16 - Canarying Releases (Google SRE Workbook)
- Progressive Delivery for Building LLM-Powered Features
- Guarded Rollouts for AI Configs · 2025-07-24
- Why Gradual Rollouts Don't Work for AI Features (And What to Do Instead) · 2026-04-15
- LLM Guardrails With Feature Flags: Route, Compare, and Roll Back Safely · 2026-06-13