# How Do You A/B Test an LLM Feature?

> How to split real users between two versions of an LLM feature, pick the outcome that matters and roll out safely, explained for your AI interview.

**In short:** Split real users at random between the current version and the new one, measure what those users actually do, and ship the new version only if it wins without hurting cost or safety. Because LLM answers vary and take time to judge, run offline tests and a shadow run first.

AI and LLM interview question Q258, Evaluation and observability. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-ab-test-an-llm-feature

## Say it in 30 seconds

I'd split real users at random between today's version and the new one, and keep each user in one group. I'd measure a real outcome, like a task finished or a chat not passed to a person, and watch guardrails for cost and safety too. Before any user sees the new version, I'd run it offline and in a shadow run. I'd fix the length and the sample size up front, and not peek at the results every hour.

## Say it in 2 minutes

An A/B test shows two versions of a feature to different real users at the same time, then compares what those users do. With an LLM feature there are three extra problems. The same question can get a different answer each time. A good answer is hard to judge with one click. And a test can look like a win for a few days just by chance.

So I'd start before any user sees the change. I'd score the new prompt or model on a test set of past questions, then run it in shadow on copies of real requests, where its answers are hidden. Only then would a small share of real users get it, split by user ID so nobody flips between versions.

I'd pick one change per test, and one outcome that matters, like a finished task or a chat that didn't need a person. I'd also watch guardrails: cost per chat, speed, and wrong answers that matter. A new version that wins on the main number but breaks a guardrail doesn't ship.

Finally I'd decide the length and the sample size before starting, and I wouldn't stop early because one day looked good. Anthropic says A/B testing needs sufficient traffic, and that it takes days or weeks to reach significance. Those are the limits I'd tell the team up front.

## What is an A/B test, in plain words?

An A/B test shows two versions of a feature to different real users, then compares what those users do. Version A is what you have today. Version B is the change, such as a new prompt, a newer model or a different search setting. (LLM means large language model, the AI that writes the replies.)

Picture a bank testing a loan form. Half the applicants see the old layout, half see the new one, and the layout with more finished applications wins. An LLM feature needs more care, because the same question can get a different answer each time, and a good answer is hard to judge with one click.

A made-up case: a bank's support assistant gets a new prompt that makes it check the fee schedule before quoting a fee. The test asks whether customers finish their task more often, and whether fewer chats are handed to a human agent. Only then do you decide.

- **Control:** The current version, Version A. Everything is compared against it.
- **Variant:** The new version under test, Version B.
- **Sticky split:** Each user is put into one group and stays there for the whole test.
- **Shadow run:** The new version runs on copies of real requests with its actions switched off, such as refunds or emails, so it cannot act. Users only see the current answer.
- **Guardrail:** A number you must not hurt, like cost per chat or wrong payouts.

## How do you set up the test?

Five decisions come before any real user sees Version B.

1. **Change one thing:** Test one prompt, model or setting at a time. If three things change, you can't tell which one moved the number.
2. **Pick a real outcome:** Choose what users actually get, like a finished task or a chat that doesn't need a human. Anthropic describes A/B tests as measuring actual user outcomes, such as task completion.
3. **Split by user:** Put each user into one group at random, and keep them there. Splitting by request mixes both versions into one person's chat.
4. **Ramp up in stages:** Test offline first, then run a shadow run, then give a small share of users the change, then more. Microsoft's guide to safe rollouts uses the same middle steps, mirroring a share of traffic and then sending a small share. It says: "Mirror a percentage of live traffic to the green deployment to validate it." Its name for the new version is the green deployment.
5. **Decide the length first:** Work out how many users and how many days you need before you start. Anthropic is blunt: "Slow; days or weeks to reach significance and requires sufficient traffic." Significance means the gap is big enough that luck is unlikely to explain it.

*Diagram, How an A/B test runs: Each real user goes into one group at random. Both groups' outcomes land in the same log, tagged by version, and the team compares the two groups only at the end.*
1. Each user is put into one group, and stays there.
2. Group A's results go to the log, tagged with the user's outcome.
3. Group B's results go to the same log, tagged B.
4. A simple statistics check decides whether B really won, or got lucky.

*Diagram, Stages before a full rollout: The new version earns its way up in stages. Each stage gives a clearer answer, and a version that fails early never reaches real users.*
1. Only a version that passes the offline scores moves on.
2. Clean shadow results open the small live test.
3. A small live test that wins and keeps its guardrails goes to everyone.

## Which number do you compare, and why is it hard?

The obvious number is what users do: finished tasks, chats handed to a person, thumbs-down clicks, or people coming back. These matter, but they are slow and blurry. A thumbs-down can mean a wrong answer, or a user in a hurry who clicked by mistake.

- **Offline: A fixed test set.** Fast and cheap, and it can run on every change. But its questions may not look like real traffic.
- **Online: Real users.** Shows what people really do, and controls for other causes. Slow, and it needs real traffic.
- **Judge: A model grades the answers.** Scales to thousands of answers, but it needs calibrating against human grades for accuracy.

Worked example, with made-up numbers. An insurer's claims triage agent reads each new claim and sends it either to auto-approval or to a human adjuster. Version B adds a step that checks the policy clause first. Over two weeks, 20,000 claims are split at random, 10,000 each. Version B cuts wrongly routed claims from 12 in 100 to 9 in 100, but takes 4 seconds longer per claim and costs more in model fees (billed per token, the small pieces of text the model reads and writes). The team ships B only if the wrong-payout guardrail holds and the extra cost fits the budget.

Real results exist too. A 2026 paper on re-ranking (reordering search results with an LLM) for real estate search reports a production A/B test.

> "A/B testing validates significant changes once you have sufficient traffic" (Anthropic)
>
> "a statistically significant increase in production of +5.3% in click-through rate and +4.8% in scheduled visits" (Real estate search paper (arXiv, 2026))

## What goes wrong, and how do you avoid it?

A few mistakes come up again and again in these tests.

- **Peeking:** Checking every hour and stopping when B looks ahead. Early swings are noise, so decide the length first.
- **Switching mid-run:** Changing the split or the prompt while the test runs makes the two groups hard to compare.
- **Too little traffic:** A small gain can't be told apart from luck. Plan the sample size, or test a bigger change.
- **Mixed groups:** One user seeing both versions, or several users sharing one account, blurs the result. Split by user ID.
- **One number only:** B can win on finished tasks while cost or wrong answers get worse. Keep the guardrails in the decision.
- **Trusting the judge:** A model grader needs calibrating against human grades before you trust it. Check it on a sample.

Here it is in plain Python: a stable split by user ID, with made-up numbers. A hash of the user ID picks the group, so the same person always gets the same version, and nothing has to be stored.

```python
import hashlib

EXPERIMENT = "refund-prompt-v2"

def bucket(user_id):
    # The same user always gets the same version, so they never flip between the two.
    digest = hashlib.sha256(f"{EXPERIMENT}:{user_id}".encode()).hexdigest()
    return "B" if int(digest, 16) % 100 < 10 else "A"  # 10% of users get version B

users = [f"cust-{i}" for i in range(10000)]
counts = {"A": 0, "B": 0}
for user in users:
    counts[bucket(user)] += 1

print("users per version:", counts)
print("cust-42 group:", bucket("cust-42"))
```

Output:

```text
users per version: {'A': 8999, 'B': 1001}
cust-42 group: B
```

Two things to notice. The split is fixed by code, so a busy week can't flip a user's version. And the counts land close to the 10 percent target, which is what a fair split should do.

### How would you A/B test a hospital note summariser?

A wrong summary can hurt a patient, so you never start with patients. Begin with past notes that clinicians have already reviewed, and score the new prompt against their corrections.

Next, run the new version in shadow on copies of new notes. Clinicians then grade a random sample of both versions blind, without knowing which is which. Only after that does a small share of clinicians, not patients, see Version B in their work.

Set the guardrail with the clinical team before the test starts, for example no dropped medication change at all, whatever the win rate. A model grader can help with the bulk of the notes, but people check the sample.

> **Tip:** Name the guardrail you would never trade for a better win rate. Interviewers want to hear that a metric can't buy a safety loss.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A random split by user, kept fixed for the whole test.
- [ ] One change at a time, with a clear outcome.
- [ ] Guardrails for cost, speed and safety, not only the win metric.
- [ ] Enough users and days, decided before the test starts.
- [ ] Offline and shadow checks before any real user sees Version B.
- [ ] Honest limits: a test shows what happened. It may not show why.

**Common traps**

- Trap: "We run it for a day and pick the higher number." Better: One day is rarely enough to tell two versions apart. Decide the length and the sample size first.
- Trap: "The judge model scored B higher, so we ship it." Better: A model judge needs calibrating against human grades before you trust it.
- Trap: "Split by request, so both versions get tested." Better: A user who sees both versions gives mixed data. Split by user and keep them in one group.

## Can you spot the problem?

**Spot the problem:** A team runs an A/B test on a new prompt. Which step breaks the test?

A. Users are split at random by user ID, and each one stays in a single group.
B. The team checks the chart every hour and stops the test as soon as B looks ahead.
C. The team tracks finished tasks, cost per chat and wrong answers together.
D. New answers run in a shadow run on copies of last week's real questions first.

**Answer:** B. Checking every hour and stopping when B looks ahead is peeking. Random swings look like wins for a while. Fix the length and the sample size before the test starts.

**Quick check:** A new prompt raises finished tasks by 2 points (say 60% to 62%, made-up numbers), but cost per chat rises 30%. What is the right call?

A. Ship it, since finished tasks are the main goal
B. Ship it, since the finished-task gain is a clear win
C. Don't ship on that alone: weigh the cost against the gain, and check the guardrails
D. Keep the old version, since any cost rise is a failure

**Answer:** C. One number can win while another gets worse. Weigh the gain against the cost, and keep the guardrails in the decision.

## Can you answer these from memory?

**Flash cards**

- **What is an A/B test?** Two versions shown to different real users at once, then compared on what users do.
- **Why split by user?** One user, one version. A user who sees both versions blurs the result.
- **Why not stop when B looks ahead?** Early swings are noise. Peeking makes a lucky day look like a real win.
- **What is a shadow run?** The new version runs on copies of real requests, with actions off. Users only see the current answer.
- **Which metric counts?** A real outcome, like a finished task, plus guardrails for cost, speed and safety.
- **Offline or online?** Offline: a fixed test set, fast. Online: real users, slow but closer to reality.

## Likely follow-up questions

- Q247 Offline vs online evaluation? https://designervenkat.online/interview/ai/offline-vs-online-evaluation
- Q248 What is a golden dataset, and how do you build one? https://designervenkat.online/interview/ai/what-is-a-golden-dataset
- Q257 How do you regression-test prompts? https://designervenkat.online/interview/ai/how-to-regression-test-prompts
- Q259 Which production metrics matter for a chatbot? https://designervenkat.online/interview/ai/production-metrics-for-a-chatbot
- Q260 What is tracing for LLM apps? https://designervenkat.online/interview/ai/what-is-tracing-for-llm-apps
- Q262 "The model got worse after an upgrade." What do you do? https://designervenkat.online/interview/ai/the-model-got-worse-after-an-upgrade-what-do-you-do

## Learn it in depth

- [LLM Evaluations](https://designervenkat.online/learn/ai-engineering/llm-evaluations)
- [Evaluation Metrics](https://designervenkat.online/learn/ai-engineering/evaluation-metrics)
