Sub topic 13
Prototype and validate against the baseline
A decision scorecard gives you a hypothesis, not a result. It says an AI approach looks worth trying. This chapter covers how to test that claim cheaply, with the non-AI baseline as the opponent, before you commit to building and running the feature.
This chapter assumes you have read the earlier chapters on baselines, error cost, and evaluation metrics. You should be comfortable reading short Python snippets.
What a prototype is for
A prototype exists to answer one question: does the AI approach beat the baseline by enough to justify its extra cost and risk? It is not a demo or a first version of the product. Teams get into trouble when a prototype impresses people in a meeting and nobody ever measures it.
A good prototype is:
- Narrow. It covers one task, one input type, and one success metric.
- Throwaway. You can delete it without regret, so you don't defend it out of sunk cost.
- Measured. It runs on a fixed evaluation set and produces numbers you can compare with the baseline.
Write the test before you build
Decide what counts as success before you see any results. Otherwise you will pick the threshold that makes your prototype look good. Write down five things:
- Hypothesis. For example: "A language model classifies support tickets into billing or bug more accurately than our keyword rules."
- Baseline. The best non-AI approach you can build in a short time, not a deliberately weak one.
- Primary metric and threshold. For example: "At least 10 points higher accuracy, with no increase in the rate of high-severity errors."
- Guardrails. Metrics that must not get worse, such as latency, cost per request, or the error rate on a sensitive segment.
- Stop conditions. Results that end the experiment, such as "if the improvement interval includes zero after 200 examples, stop."
Build the evaluation set
The evaluation set decides whether the result means anything. Four rules cover most of the problems.
- Sample from real traffic. Invented examples are cleaner and easier than real ones. Pull from production logs or support history, with privacy rules applied.
- Include the hard and rare cases. If 5% of real inputs are ambiguous, make sure they appear in the set. Where a rare case is costly, oversample it and report it separately.
- Label carefully. Have two people label a subset and check how often they agree. If humans disagree on 30% of items, no model can score above that level on those items, and your metric has a ceiling you should know about.
- Keep it separate. Do not use the evaluation examples to tune prompts, rules, or training. If you do, the score measures how well you fitted those examples, not how the approach works on new ones. Hold out a second set for the final check.
A common question is how many examples you need. The size depends on how big the difference is that you want to detect. Small differences need hundreds or thousands of examples. A few dozen examples can only reveal large gaps. The next section shows how to check this.
Compare against the baseline
Score both approaches on the same examples, then ask whether the difference is bigger than chance. The code below computes the accuracy of each approach and a paired bootstrap interval for the difference. "Paired" means both approaches are scored on the same items, so the comparison uses each item's outcome for both. The bootstrap repeatedly resamples the set with replacement to see how much the difference varies.
The candidate function here is a stand-in for the call to your real model. It is a longer keyword list so the script runs without any API. In a real prototype, replace its body with the model call.
import random
def correct_flags(predict, examples):
return [1 if predict(text) == label else 0 for text, label in examples]
def paired_bootstrap(base, cand, n=2000, seed=0):
rng = random.Random(seed)
size = len(base)
diffs = []
for _ in range(n):
idx = [rng.randrange(size) for _ in range(size)]
diffs.append(sum(cand[i] - base[i] for i in idx) / size)
diffs.sort()
return diffs[int(0.025 * n)], diffs[int(0.975 * n)]
examples = [
("please refund my order", "billing"),
("the app crashes on launch", "bug"),
("my invoice amount is wrong", "billing"),
("I was charged twice this month", "billing"),
("screen goes blank after login", "bug"),
("cancel my subscription and send money back", "billing"),
("export button does nothing", "bug"),
("why did my card get billed again", "billing"),
("page freezes when I upload a photo", "bug"),
("I want my money back", "billing"),
]
def baseline(text):
if "refund" in text or "invoice" in text:
return "billing"
return "bug"
def candidate(text):
# Stand-in for a model call. Replace with your real model.
if any(word in text for word in ("refund", "invoice", "charged", "billed")):
return "billing"
return "bug"
base_flags = correct_flags(baseline, examples)
cand_flags = correct_flags(candidate, examples)
print("baseline accuracy: ", sum(base_flags) / len(base_flags))
print("candidate accuracy:", sum(cand_flags) / len(cand_flags))
low, high = paired_bootstrap(base_flags, cand_flags)
print(f"95% interval for the difference: [{low:.2f}, {high:.2f}]")The candidate scores 0.8 against the baseline's 0.6. With only ten examples, though, the lower end of the interval should sit at or near zero. That means the data cannot rule out "no real improvement." You would collect more examples before deciding.
The stand-in also teaches something. Adding four keywords raised accuracy by 20 points. If a longer rule list gets most of the gain, the better baseline is the rule list, and the AI option has to beat that version instead.
Look beyond the headline number
An average hides the cases that matter. After the comparison, check these before you accept the result.
- Error types. Two approaches with equal accuracy can fail differently. A rule fails predictably on inputs it has never seen. A model may fail on inputs that look ordinary, and it may sound confident when wrong. Read the actual errors, not only the counts.
- Segments. Break results down by input type, language, customer tier, or length. A model that wins overall may lose on the segment you care most about.
- Severity. Weight errors by the error-cost analysis you did earlier. Ten harmless mistakes can be better than one costly one.
- Variability. Run a probabilistic system more than once on the same inputs. If answers change between runs, report the spread and not a single score.
- Cost and latency. Measure the cost per request and the response time at realistic volume. Check them against the guardrails you set.
Move from offline test to live pilot
Offline scores tell you what happens on past data. A live pilot tells you what happens with real users. Increase exposure in stages, and stop at any stage where a gate fails.
| Stage | What happens | What it tells you | Risk to users |
|---|---|---|---|
| Offline evaluation | Run on the labeled set | Quality versus baseline | None |
| Shadow mode | Run on live traffic, hide the output | Real input mix, cost, latency | None |
| Assisted | Show suggestions to staff who decide | Usefulness, how often staff accept | Low |
| Limited rollout | Serve a small share of users, with fallback | Real outcomes, user reaction | Moderate |
| Controlled experiment | Randomly split users between baseline and AI | Causal effect on the outcome metric | Moderate |
Shadow mode is often the cheapest informative step. It shows you inputs your labeled set missed, because real traffic is almost always messier than a sample.
For a controlled experiment, measure the outcome from the problem definition, such as tickets resolved or time to answer, and not only model accuracy. A model can be more accurate and still not change what users do.
Common failure modes
- Moving the goalposts. The result misses the threshold, so someone argues the threshold was too strict. Fix the threshold in writing before testing.
- Leakage. Evaluation examples appear in prompts, training data, or tuning. Scores look excellent and production results disappoint.
- Demo bias. You test on the examples that impressed people. Use a random sample instead.
- Ignoring the fallback. The pilot has no plan for when the model is wrong, slow, or unavailable. Test the fallback path as part of the pilot, because users will meet it.
- Treating one run as the truth. One small, noisy comparison is a signal. Report intervals and sample sizes.
- Comparing the AI to nothing. Without a measured baseline, "it works" has no meaning. The baseline score is what gives the AI score its value.
Record the decision
End the experiment with a short written record: the hypothesis, the baseline, the results with intervals, the segments that behaved differently, measured cost and latency, and the decision. If the answer is "don't use AI yet," say what would change it, such as more labeled data or a cheaper model. A recorded "no" saves the next team from repeating the test, and it gives you something to revisit as conditions change.
Exercise
A prototype scores 82% accuracy against a keyword baseline's 78% on a 50-example evaluation set. The pre-agreed threshold was a 10-point improvement. A teammate says the result is close enough and wants to ship. Give two reasons to disagree and one next step.
Show answer
First, the gain is 4 points, below the 10-point threshold set beforehand, and changing the threshold afterward defeats the purpose of setting it. Second, with only 50 examples a 4-point difference is about two items and is well within random variation, so a bootstrap interval would almost certainly include zero. Next step: improve the baseline (for example, add keywords) and, if the AI option is still worth pursuing, collect a larger evaluation set, then compare again against the original threshold.
Exercise
Your model beats the baseline offline, but in shadow mode its cost per request is three times your guardrail. Which stage should you not move to next, and what are two options?
Show answer
Do not move to a limited rollout, because a guardrail has already failed. Options include trying a smaller or cheaper model, shortening inputs or caching repeated requests, using the model only for the hard cases and sending the rest to the baseline, or deciding the quality gain does not justify the cost and keeping the baseline.