Topic 4 of 5 · 5 min read
A/B testing prompt and model versions
Goal: Plan an A/B test for a prompt or model change with a sample size and guardrail metrics.
An A/B test randomly splits real users between two versions and compares an outcome metric, so differences can be blamed on the change and not on who showed up. It is the check that offline evals cannot replace, because only live users show whether a "better" answer helps them.
Check yourself · 1 of 3
Why randomize an A/B test of two prompts by user rather than by request?
Why it matters
An offline win means the new prompt scores higher on your dataset. Users may still do worse, because the dataset is not their traffic, the judge is not their opinion, or the answers are better in a way they do not value. The A/B test settles it.
How to plan one
- State the hypothesis and one primary metric before you start, for example "send-without-edit rate rises".
- Choose the randomization unit. Usually the user, not the request. If one user sees both versions in one conversation, the results contaminate each other. Keep a user in one arm for the whole test.
- Add guardrail metrics that must not get worse: cost per task, p95 latency, escalation rate, guardrail triggers. Decide the limits in advance.
- Compute the sample size. For a baseline rate of 60%, to detect a 3-point lift at 5% significance and 80% power, you need roughly 4,200 users per arm. A calculator such as Evan Miller's gives it; smaller effects need much more.
- Fix the duration to whole weeks to cover weekday patterns, and do not stop when the result first looks good.
- Check for sample ratio mismatch. A 50/50 split that shows 52/48 on tens of thousands of users signals a bug in assignment.
Before and after
Weak: Send the new prompt to 10% of traffic for two days,
stop when it looks better, compare thumbs-up rates.
Better: Randomize by user, 50/50. Primary: send-without-edit.
Guardrails: p95 latency, cost per task, escalation rate.
Run 2 full weeks or until ~4,200 users per arm.
What goes wrong
- Peeking. Checking daily and stopping at the first significant result inflates false positives.
- Novelty effects. A change can look good for the first days because it is new, then fade.
- Underpowered tests. With too few users, "no difference" only means you could not tell.
- Randomizing by request. The same user sees both versions and the metric blurs.
- Ignoring guardrails. A quality gain that doubles cost is a different decision.
Examples
Offline win, online loss
A new prompt scores 8 points higher on the offline set, because it gives fuller explanations. Online, the A/B test shows more users abandoning and p95 latency up 40%. Users wanted the short answer. The primary metric and a latency guardrail caught what the offline score could not.
Sample ratio mismatch
A test is planned 50/50 but logs show 61% in one arm. The cause is a cache that serves the old prompt to returning users. The results are discarded, the assignment is fixed and the test restarts.
Key points
- Randomize by user, and keep each user in one arm for the whole test, so versions do not contaminate each other.
- State one primary metric and the guardrail limits before the test starts.
- Compute the sample size from the baseline rate, the smallest lift worth detecting, power and significance.
- Do not stop at the first significant result; run the planned duration to avoid false positives and novelty effects.
- An offline win can lose online, because the dataset, the judge and real users differ.
Common mistakes
- Randomizing by request so one user sees both versions.
- Stopping the test the first time the result looks significant.
- Choosing the primary metric after seeing the results.
- Skipping guardrail metrics such as latency, cost and escalation.
Check yourself · 2 of 3
After three days, the new prompt shows a significant lift, but the plan was two weeks. What should you do?
Check yourself · 3 of 3
A new model raises task completion but also raises cost per task by 150%. Which part of the test plan would have flagged this?
Practice items, not counted towards your mastery.
Start here
- Langfuse: Evaluation overview (opens in a new tab)DocsFree
How online scores, user feedback and LLM-as-a-judge attach to production traces, next to offline datasets.
- Trustworthy Online Controlled Experiments (Kohavi, Tang, Xu) (opens in a new tab)BookPaid
The standard book on randomization units, guardrail metrics, sample size and novelty effects.
- OpenTelemetry semantic conventions for generative AI (opens in a new tab)StandardFree
Common attribute names for model calls, token usage and latency, so metrics line up across tools.
More for this topic
- A/B test sample size calculator (Evan Miller) (opens in a new tab)ToolFree
Compute users per arm from a baseline rate, the smallest effect worth detecting, power and significance.
- How Not To Run an A/B Test (opens in a new tab)ArticleFree
Why peeking at results and stopping early inflates false positives.