EXPERIMENTATION & A/B TESTING · INTERVIEW QUESTION
Explain A/B testing and multi-armed bandit approaches for comparing LLM versions or prompts.
🟡 intermediate · A/B Testing Fundamentals
Hint: A/B: fixed split. Bandit: adaptive allocation toward better variant.
Answer
- Fixed split (e.g., 50/50)
- Measure metrics: user satisfaction, task completion, error rates
- Need enough data for statistical significance
Interview reasoning
A/B Testing
Randomize users into groups, each gets a different model/prompt variant:
The normal-approximation sample size above is per arm for equal allocation and common variance; z denotes a standard-normal quantile.
Multi-Armed Bandit
Adaptive allocation can shift traffic toward better variants while exploring. The following softmax allocation is one possible policy, not the general bandit rule:
| A/B Testing | Bandit | |
|---|---|---|
| Allocation | Fixed | Adaptive |
| Reward regret | Does not adapt to observed rewards | Can reduce regret with suitable exploration |
| Inference | Standard designs with valid monitoring | Requires inference valid for adaptive allocation |
| Time to decision | Depends on effect and design | Depends on objective, exploration and reward delays |
| Best for | Final decisions | Ongoing optimization |
# Simple epsilon-greedy bandit
import numpy as np
def select_variant(rewards, epsilon=0.1):
if np.random.random() < epsilon:
return np.random.choice(len(rewards)) # explore
return np.argmax([np.mean(r) for r in rewards]) # exploitFor LLMs: A/B test prompt styles, model versions, or system prompts; consider bandits for ongoing reward optimization. Low regret does not guarantee fastest confident best-arm identification. Adaptive experiments can support rigorous inference with suitable estimators and stopping rules. Initialize each arm with observations before using the illustrative epsilon-greedy function.
Bandits adapt traffic to improve cumulative reward and learn action values, whereas a fixed experiment emphasizes a clean policy comparison. Contextual bandits condition choices on user/context features and need correct logged assignment probabilities. Delayed rewards, safety and nonstationarity affect both learning and later off-policy inference.
Worked example. A prompt bandit can favor better replies while retaining enough safe exploration to learn alternatives. Compare this with a stable user-randomized prompt test whose goal is an unbiased version comparison, particularly when CSAT arrives late.
This is the opening of a longer walkthrough. Read the full answer in the topic explorer, free.
Related questions
- What is a p-value? Common misconceptions?
- What is the difference between statistical significance and practical significance?
- What is CUPED and how does it reduce variance in A/B tests?
- How do you ensure reproducible experiments with LLMs?
- What is experiment tracking (MLflow, W&B) and why is it important for LLM projects?