Prompt & Context Engineering·Question 42 of 68Advanced

How would you A/B test a prompt change safely in production?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Staged rollout, with the A/B test as the final gate rather than the first test:

Stage 0 - offline eval. The new prompt must beat or match the incumbent on the regression suite (golden set + past failures). Never burn production traffic discovering what an offline eval would have caught.

Full worked answer

Staged rollout, with the A/B test as the final gate rather than the first test:

Stage 0 - offline eval. The new prompt must beat or match the incumbent on the regression suite (golden set + past failures). Never burn production traffic discovering what an offline eval would have caught.

Stage 1 - shadow mode. Run the new prompt on a sample of live traffic without serving its output; compare distributions (judge scores, output length, format-validity rate, refusal rate, tool-call patterns) against the served prompt on identical inputs. Catches distribution-shift surprises with zero user risk.

Stage 2 - canary A/B. Serve the variant to a small percentage with automatic rollback triggers on guardrail metrics (error/validity rates, latency, safety flags, thumbs-down rate), then ramp.

LLM-specific design points that interviewers probe:

  • Randomise by user, not by request. Multi-turn conversations must stay within one variant - mid-conversation prompt switches produce incoherent behaviour and contaminate both arms. User-level assignment also captures cross-session effects.
  • Metrics are the hard part. Online ground truth is scarce; explicit feedback is sparse (usually a small fraction of interactions) and biased toward the very happy and the very annoyed. Use a hierarchy: guardrails (cheap, automatic - validity, latency, cost per request, safety), proxies (retry/rephrase rate, task completion, escalation-to-human rate, conversation abandonment), and sampled LLM-judge scoring on live traffic for quality. Pre-register which metric decides and which merely guard.
  • Variance and power: LLM quality metrics are noisy and prompt effects are often small; compute required sample size up front - low-traffic products may need weeks per test, arguing for bigger, less-frequent prompt changes and heavier reliance on offline evals. Paired offline comparisons (same inputs through both prompts) are far more statistically efficient than between-user online splits, which is another reason stage 0 matters.
  • Hold everything else constant: pin model version and sampling parameters across arms - a provider model update mid-test silently confounds everything. Log prompt version, model snapshot, and params with every request or you can't debrief incidents.
  • Segment results (language, task type, tenant) - a neutral aggregate can hide a win in one segment and a serious regression in another.

Treat prompts as deployable artifacts: versioned, config-flagged (no code deploy to roll back), one-click revert.

What a good answer covers

  • The new prompt must beat or match the incumbent on the regression suite (golden set + past failures)
  • Never burn production traffic discovering what an offline eval would have caught
  • Run the new prompt on a sample of live traffic without serving its output; compare distributions (judge…
  • Catches distribution-shift surprises with zero user risk
  • Serve the variant to a small percentage with automatic rollback triggers on guardrail metrics…

Key terms: Stage 0 - offline eval · Stage 1 - shadow mode · Stage 2 - canary A/B · Metrics are the hard part · Variance and power · Hold everything else constant · Segment results

Interviewer follow-ups to expect

  1. Sparse explicit feedback - what proxy metrics have real signal, and how do you validate a proxy?

  2. How do you test a prompt change inside a multi-step agent where one turn's output feeds the next?

  3. The variant wins the A/B but loses offline - what do you do?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep