Experiment Plan for an LLM-Powered Inline Rewrite Feature
Statistics & ExperimentsModel answerLast updated
Plan a controlled experiment for an inline AI rewrite feature: choose metrics and guardrails, pick the randomization unit, size the test, and guard against bias.
Scenario
You work on a document-editing product with an AI writing assistant. A new capability will highlight passages of text and offer reworded alternatives that the user can accept with one click. Product leadership wants evidence that it makes people more engaged, and the proposed engagement measure is characters edited per session.
Each suggestion comes from a call to a large language model and adds roughly 100 ms of delay whenever one is triggered. The product has about 1 million daily active users.
Your task
Describe how you would run a controlled experiment to decide whether to launch. Cover these four areas:
- Hypothesis and metrics. State the hypothesis. Choose a primary metric, supporting secondary metrics, and guardrail metrics that would catch harmful side effects. Say whether the proposed engagement measure is trustworthy.
- Randomization. Choose the unit of assignment (user, session, request, or something coarser) and justify it. Explain how you would deal with interference between users.
- Sample size and duration. List what drives the required sample size, show how you would estimate it, and explain how you would choose the test length.
- Bias and validity threats. Name the main ways the result could be misleading (selection, novelty, instrumentation, and so on) and how you would reduce each.
Be ready for follow-ups such as: what if engagement rises but retention falls, or what if a bug put a non-random group of users into one arm?
Hints
Hint 1
Ask whether the feature can raise the primary metric without delivering any value. Consider what a single click on an accepted rewrite does to a character count.
Hint 2
Think about who actually sees the feature. If most sessions never trigger a suggestion, the effect is diluted. Consider logging when a suggestion would have fired in the control arm too.
Hint 3
In shared documents, one user's accepted rewrite shows up in another user's document. Ask which unit of randomization keeps arms from contaminating each other.
Hint 4
For sample size, write the formula and identify which inputs are business decisions (minimum detectable effect) and which are data properties (variance, heavy tails). Then ask what, other than sample count, should set the duration.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing
Treat this as a ship/no-ship decision that weighs engagement, latency, quality, and LLM cost. Before any power calculation, challenge the proposed metric.
1. Hypothesis and metrics
Hypothesis. Users with the rewrite feature get more productive writing done, while retention, perceived speed, reliability, and cost stay within acceptable limits.
The proposed metric is flawed. Characters edited can be inflated by the feature itself: one click can change hundreds of characters, and a poor suggestion that the user reverts adds even more edits. The number can rise with zero value created. Fixes:
- Split it into user-typed characters and suggestion-accepted characters, and report both.
- Count net changes after undos.
- Aggregate per user over the experiment window (for example per user per week) rather than per session. Sessions are correlated within a user, so a per-session ratio understates variance if analyzed naively. If you keep it, use the delta method or cluster-robust errors.
Primary metric. Net characters of retained text per user per week, or a value-oriented alternative such as documents completed or exported per user.
Secondary metrics (they explain the mechanism).
- Suggestion trigger rate, acceptance rate, undo-after-accept rate.
- Sessions per user, time to complete a document.
Guardrails.
- Latency: p50/p95/p99 time-to-suggestion and input lag. The 100 ms penalty matters most in the tail.
- Reliability: LLM timeout and error rates, client crashes.
- Retention: D7 and D28 return rate, churn or downgrade rate.
- Cost: LLM spend per active user.
- Quality: feature-disable rate, negative feedback, support tickets.
Optional third arm. Add a "latency only" arm that injects a 100 ms delay without suggestions. Versus control it isolates the cost of slowness; versus treatment it isolates the benefit of the suggestions.
2. Randomization
Unit: the user account.
- Session- or request-level assignment gives users an inconsistent product, and learning carries over between arms, so control sessions are contaminated.
- Assign server-side with
hash(user_id, experiment_salt) mod 100, so one person on several devices stays in one arm. Cookies or device IDs would split them. - Logged-out traffic cannot be tracked reliably; exclude it or analyze it separately.
Interference. In shared documents, a treated user's accepted rewrites appear for control collaborators, which inflates control and shrinks the measured effect. Options:
- Randomize by workspace or team cluster, accepting higher variance and using cluster-robust standard errors.
- Keep user-level assignment and run a sensitivity analysis on single-author documents.
Triggered analysis. Many users never reach a state where a suggestion fires. Log the counterfactual trigger in control (the moment a suggestion would have shown) and analyze triggered users. This removes dilution and raises sensitivity.
3. Sample size and duration
For a two-sample mean comparison with equal allocation:
n per arm = 2 (z(1-α/2) + z(1-β))² σ² / δ² ≈ 16 σ² / δ² at α = 0.05 and 80% power.
Inputs.
- MDE (δ): the smallest lift that justifies the LLM cost and latency. This is a business decision.
- Variance (σ²): edit counts are heavy-tailed. Winsorize at the 99th percentile and apply CUPED using pre-period editing volume, which often cuts variance 30-50%.
- Allocation split, number of arms, and multiple-comparison correction.
Worked example. With a coefficient of variation of 2 and a 1% relative MDE: n ≈ 16 × 4 / 0.01² = 640,000 users per arm. With 1M DAU and several million weekly uniques, a 50/50 split gets there within about a week, and CUPED or triggered analysis lowers the need further.
Duration is not just sample count.
- Run at least two full weeks to cover weekday/weekend cycles and let novelty fade.
- Retention guardrails need longer, roughly four or more weeks for D28.
- Fix the horizon in advance. If early looks are required, use sequential testing (mSPRT or alpha spending).
4. Bias and validity
| Threat | Mitigation |
|---|---|
| Novelty effect | Plot the effect by days since first exposure; favor new users; keep a long-term holdout (about 5% for 2-3 months). |
| Primacy / change aversion | Same exposure-day view; the effect may grow instead of decay. |
| Sample ratio mismatch | Daily chi-square test on arm counts; treat a mismatch as invalidating until explained. |
| Instrumentation error | Treatment edits may log through a different code path. Use a single event pipeline and run an A/A test first. |
| Selection bias | Assign before any user action; for triggered subsets use counterfactual triggers in both arms. |
| Peeking / p-hacking | Pre-register metrics, decision rule, and horizon; apply Benjamini-Hochberg to secondary metrics. |
| Outliers / bots | Apply one predefined filter equally to both arms. |
Ramp safely: 1% → 5% → 50%, with automated kill switches on latency and error guardrails.
Follow-ups
Engagement up, retention down. Do not ship. Retention is closer to long-term value. Diagnose: is engagement driven by fixing bad suggestions (high undo rate)? Is latency causing churn (compare with the latency-only arm)? Is the effect concentrated in one segment? Then iterate (fewer, higher-confidence suggestions, opt-in triggering) and retest with retention as the primary metric.
A bug placed non-random users (for example power users) in control. Assignment is no longer independent of user type, so the affected data is not a valid randomized comparison. Identify the affected window and users from logs, check SRM and pre-period covariate balance (prior activity, tenure, platform) on the unaffected data, and analyze that clean subset or rerun. Regression adjustment on pre-period covariates can reduce residual imbalance but does not fully repair a broken assignment.
Common mistakes
- Accepting "characters edited" at face value.
- Randomizing by session or device.
- Computing variance per session when users were the randomized unit.
- Stopping after three days because the sample size was reached, which locks in novelty.
- Ignoring the tail latency and LLM cost when deciding.