Evaluating AI systemsMiddleLesson 2247 min read

A/B tests and online metrics

Offline evals tell you what might happen. A/B tests with real users tell you what does happen. Learn guardrail metrics, sample size intuition and novelty effects.

Lesson in motion

In 60 seconds

A/B tests and online metrics

Offline evals tell you what might happen. A/B tests with real users tell you what does happen. Learn guardrail metrics, sample size intuition and novelty effects.

1/4
In simple words
A tea stall owner wants to know if a new recipe is better. He could ask two friends to taste it. Or, for a week, he could serve the old recipe to half his customers and the new one to the other half, and see which group comes back more. The second way is an A/B test.
Offline evaluation uses a fixed test set before release. Online evaluation measures what real users do after release. Both are needed. Offline evals are fast, safe and repeatable. Online metrics show the real effect: do users actually get their problem solved, stay, or complain?
Offline evalsOnline (A/B) tests
DataYour fixed test setReal users, real traffic
SpeedMinutes to hoursDays to weeks
RiskNo user sees a bad versionSome users see the new version
MeasuresCorrectness, format, safety on known casesBehaviour: resolution, retention, complaints, cost
Main weaknessMay not match real useSlow and noisy; needs enough users

How an A/B test works

  1. 1

    Pass offline evals first

    Never A/B test a version that fails your must-pass checks.
  2. 2

    Choose one main metric

    Decide in advance, for example "share of chats resolved without a human".
  3. 3

    Choose guardrail metrics

    Things that must not get worse: complaints, safety flags, latency, cost per chat.
  4. 4

    Split users randomly

    Each user is assigned by chance to A (current) or B (new), and stays in that group.
  5. 5

    Run for a fixed time

    Decide duration and sample size before starting. Do not stop early the moment B looks good.
  6. 6

    Decide

    Ship B only if the main metric improves and no guardrail gets worse.

Guardrail metrics

A new prompt might resolve more chats by being more willing to give answers, including wrong ones. A guardrail metric catches this: for example, the rate of users who come back with the same issue, safety reports, or refund requests. If a guardrail gets worse, stop and investigate, even if the main metric looks great.

Sample size intuition

Small differences need many users to detect. A common rule of thumb for comparing two groups, at the usual settings (about 80% chance of detecting a real effect, 5% false-alarm rate), is: users per group ≈ 16 × p × (1 − p) ÷ d², where p is the current rate and d is the smallest change you care about.
Python: rough users needed per grouppython
def users_per_group(p, d):
    """Rule of thumb: about 80% power, 5% significance, two groups."""
    return round(16 * p * (1 - p) / d ** 2)

print(users_per_group(0.20, 0.02))  # detect 20% -> 22%: 6400 per group
print(users_per_group(0.20, 0.05))  # detect 20% -> 25%: 1024 per group
Notice the pattern: to detect a change half as big, you need about four times as many users. If your product has few users, look for larger improvements, run longer, or rely more on careful offline evals and human review.
Note
This is only an intuition, not a full statistical plan. For important decisions, use a proper sample size calculator or ask someone with statistics training.

Traps to avoid

TrapWhat happensDefence
PeekingChecking results every day and stopping the moment B looks better finds "wins" that are just noise.Fix the duration and sample size in advance.
Novelty effectUsers try a new feature because it is new; usage drops later.Run long enough; look at the trend over time, and at returning users.
Change aversionUsers first dislike any change, even a good one.Same: run long enough to see behaviour settle.
Too many metricsLook at 30 metrics and a few will "improve" by chance.One main metric chosen in advance; treat the rest as clues.
Unequal groupsOne group gets more Hindi users, or more weekend traffic.Random assignment by user, and check the groups look similar.
Watch out
Tell users when they are talking to AI, follow your privacy policy for what you log, and do not A/B test changes that could cause real harm to some users (for example, removing a safety check). Offline safety evals come first.
Try this. Your bot resolves 30% of chats. You hope a new prompt raises it to 33%. Use the formula to estimate how many users you need per group. Is that realistic for a product with 500 chats a day?

Watch and read more

Lab

A one-page A/B test plan with metrics, guardrails and a sample size estimate.

~35 min

The problem

Scenario: a railway enquiry bot resolves about 25% of chats without a human. You have a new prompt that you hope raises this.

  1. Write the main metric exactly (what counts as "resolved"?).
  2. List three guardrail metrics and why each matters.
  3. Using the rule of thumb, compute the users per group needed to detect a rise to 27% and to 30%. Show your working.
  4. Given about 2,000 chats a day, estimate how many days each test would take. Is either practical?
  5. Write how long you will run the test to handle novelty effects, and your rule for stopping.

Practice lab

Edit the code and run it. Python runs in your browser — nothing is sent to our server.

Output

No output. Add print(...) to see values.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1Your A/B test shows the new prompt raised resolution, but complaints also rose slightly, though not by a statistically clear amount. What do you do?Reveal

Do not ship on autopilot. A guardrail moving the wrong way is a warning even if it is not clearly significant. Read a sample of the complaints and the resolved chats in group B. If the new prompt is closing chats with wrong answers, the "win" is false. You may need a longer test, a better resolution definition, or a fix before trying again.

Q2Why might an offline eval improvement disappear in an A/B test?Reveal

The test set may not match real traffic: real users use different languages, shorter questions and different topics. The improvement may be in cases that are rare in practice. Users may react to things the test set does not measure, like speed, length or tone. And the offline gain may have been noise on a small test set. The A/B test measures the real mix.

Please sign in to continue.

Questions people ask

If offline evals are good, why run an A/B test at all?

Because your test set is a guess about real use. Real users ask different things, react to tone and speed, and change their behaviour. An A/B test measures the actual outcome. Many teams find that offline wins shrink or even reverse online.

Should I randomise by message or by user?

Usually by user, so each person has one consistent experience. Randomising each message lets one person see both versions, which confuses them and mixes up the measurement.

What if I do not have enough users for an A/B test?

Then rely more on offline evals, careful human review of real conversations, and staged rollouts where you watch guardrail metrics closely. Be honest that you cannot detect small effects.

Can I use thumbs up and thumbs down as my main metric?

It is a useful signal, but few users click, and those who do may not be typical. Pair it with behaviour-based metrics, such as whether the problem was solved or the user came back with the same issue.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress