How to build reliable evaluation pipelines for AI systems

Shipping an AI feature without a structured evaluation process is like deploying code with no tests — except the failures are harder to reproduce, harder to explain, and often invisible until a user surfaces them.
The core argument of this guide is simple: a reliable AI evaluation pipeline is not a single tool or a single metric. It's a repeatable process that connects your test data, your scoring logic, your review workflows, and your production experiment results into one continuous loop. Each layer depends on the one before it, and skipping any of them creates gaps that show up as production surprises.
This guide is for engineers, PMs, and data teams who are building or improving evaluation for AI systems — whether that's a RAG pipeline, an agent, or a multi-turn chatbot. Here's what you'll learn:
- How to build a representative evaluation dataset before you write a single metric
- How to define layered metrics that separately track latency, output quality, and safety
- How to use LLM-as-a-judge to scale scoring without losing interpretability
- How to build human review workflows and regression detection into the pipeline loop
- How to feed production experiment data back into your offline evaluation dataset
The guide follows that order deliberately. Each section builds on the previous one, so by the end you'll have a complete picture of how the parts fit together — not just a checklist of best practices to apply in isolation.
Start with a representative evaluation dataset before writing a single metric
Most teams building an AI evaluation pipeline reach for metrics first. It feels like the right starting point — metrics are concrete, they're technical, and they give the impression of rigor.
But a sophisticated scoring system applied to a poorly scoped dataset doesn't produce rigorous results. It produces confident, wrong answers. The dataset is the foundation everything else depends on, and AWS makes this sequencing explicit: gather your evaluation dataset before you define your metrics, not in parallel with it.
As Maxim AI puts it plainly: "Without high-quality evaluation data, teams cannot reliably assess whether their agents are improving or regressing with each iteration." That's not a tooling problem. It's a data problem, and no amount of clever metric design fixes it.
Representative means matching production distribution, including the cases you'd rather not test
"Representative" is easy to say and hard to operationalize. In practice, it means the distribution of inputs in your dataset should mirror the distribution of inputs your system will actually encounter in production — including the rare, high-stakes cases that don't show up in average traffic but matter enormously when they do.
AWS frames this as a requirement for "diverse samples" that reflect the "actual real-world use case." For a customer support system, that means your dataset can't consist only of routine queries. It needs escalation scenarios, ambiguous requests, and cases where the user is frustrated or provides incomplete context.
For a code review assistant, it needs both well-formed and malformed inputs, edge cases in language syntax, and examples where the correct answer is "this code is fine" — not just cases where something needs fixing.
The practical implication: before you write a single evaluation case, map the input space your system operates in. What are the common cases? What are the complex ones? What are the edge cases that would cause real harm if handled incorrectly? Your dataset needs coverage across all three categories.
Ground truth generation — why expert labels beat synthetic assumptions
The most common shortcut teams take is using model-generated outputs as ground truth — either from the same model being evaluated or a closely related one. This is a structural problem. You cannot reliably evaluate a model against a reference that was produced by the same class of system you're trying to assess. The errors correlate.
AWS is direct on this point: evaluation datasets should "ideally contain ground truth values generated by experts". The qualifier "ideally" is intentional — expert annotation is expensive and doesn't scale infinitely — but the underlying principle holds.
Expert-generated labels establish a reference point that is independent of the model's own tendencies and failure modes. Synthetic ground truth, by contrast, tends to reflect whatever biases and gaps the generating model already has.
For teams with limited annotation budgets, a practical middle path is to use expert labels for the highest-stakes cases and edge cases, while reserving synthetic generation for volume coverage of routine scenarios where the stakes of a labeling error are lower.
Iterative enrichment with failure cases
Dataset construction is not a one-time task. It's a lifecycle. The initial dataset gets you started; the enrichment process is what makes your AI evaluation pipeline durable over time.
Maxim AI describes this as "continuous improvement workflows" built on a combination of production traces, synthetic generation, and human-in-the-loop review. The practical cycle looks like this: run your evaluations, identify the cases where the model fails or produces unexpected outputs, add those cases to the dataset, and re-run. Each iteration makes the dataset harder to game and more representative of real failure modes.
Production logs are particularly valuable here. Actual user interactions surface failure patterns that no amount of upfront scenario planning anticipates. This is also where warehouse-native architectures become relevant — teams that store production experiment data in their own data warehouse can query that data directly to identify candidates for dataset enrichment, without routing raw user interactions through a third-party pipeline. We'll return to this feedback loop in the final section, but the architecture decision you make now determines whether that loop is possible later.
How dataset scope determines what metrics are even measurable
This is the section's central argument made concrete: your dataset is a hard constraint on your metric scope. If your dataset contains no adversarial inputs, you cannot measure robustness. If it contains no multi-turn conversations, you cannot measure coherence across turns. If every example has a single correct answer, you cannot measure how the model handles genuine ambiguity.
Teams that skip careful dataset construction and jump to metric selection often discover this constraint the hard way — they define a metric, attempt to compute it, and find that their dataset doesn't contain the evidence needed to make the metric meaningful. The metric becomes a formality rather than a signal.
On dataset size: Maxim AI cites research recommending at least 30 evaluation cases per agent, covering normal operations, complex scenarios, and edge cases. This is a floor for agent evaluation specifically, not a universal rule — AWS explicitly acknowledges that the right size depends on the application, and no published research provides equivalent benchmarks for RAG pipelines or general chatbot evaluation.
What matters more than hitting a specific number is ensuring your dataset covers the full range of scenarios your system will encounter, with enough examples in each category to detect meaningful differences in model behavior across versions.
Define layered metrics that cover latency, quality, and safety dimensions
The most common failure mode in AI evaluation pipeline design isn't bad tooling or insufficient compute — it's collapsing a multi-dimensional problem into a single score. A composite quality number feels satisfying to report, but it hides the specific failure modes that actually matter: a model that's fast but hallucinates, or faithful but dangerously biased, or accurate on single-turn queries but degraded across a multi-turn conversation. A deliberate metrics architecture forces each of those failure modes to surface at the layer where it belongs.
The LLM evaluation space has produced more than 50 research-backed metrics across system types and evaluation dimensions. The practical challenge isn't finding metrics — it's selecting the right ones for your system type and organizing them into a taxonomy that makes your pipeline actionable rather than decorative.
As a general principle, if your metrics are tracking the wrong things, you'll have garbage in and garbage out regardless of how sophisticated your scoring infrastructure becomes.
Latency is the one dimension where standard instrumentation applies directly
Latency is the one dimension where standard software engineering instrumentation applies directly to LLM systems without requiring model-level judgment. Time-to-first-token, end-to-end response time, and p95 latency are observable at the infrastructure layer and require no rubric design.
The key discipline here is tracking latency alongside quality metrics rather than in isolation. Optimizing for speed at the expense of output integrity is a real failure mode — a model configuration that cuts response time by 40% while degrading faithfulness by a comparable margin is a net regression, not an improvement. Latency metrics set the floor; quality and safety metrics determine whether you've actually stayed above it.
RAG quality failures cluster around five measurable dimensions
This is where the taxonomy gets substantive. For RAG systems specifically, the canonical output quality metrics cluster around five dimensions: Faithfulness, Answer Relevancy, Contextual Precision, Contextual Recall, and Contextual Relevancy.
Each measures a distinct failure mode — Faithfulness catches generation that contradicts the retrieved context; Contextual Precision and Recall evaluate whether the retrieval layer is surfacing the right material in the first place.
Traditional n-gram overlap metrics like BLEU and ROUGE are still in use as baselines, but they measure content similarity rather than semantic meaning. Relying on them as primary quality signals for LLM outputs is a well-documented mistake — they can't distinguish between a response that's factually correct and one that uses similar vocabulary while getting the substance wrong.
Beyond the RAG metric cluster, three metrics stand out as particularly strong predictors of real-world reliability: faithfulness, pass at k (which measures whether a model can reliably produce a correct answer across multiple attempts), and prompt sensitivity (how much output varies with small changes to the input prompt). If a model's outputs shift dramatically with minor prompt variations, that instability is a quality signal that accuracy alone won't surface.
Safety metrics fail silently when folded into quality scoring
Safety metrics operate at the foundational model layer and include Hallucination, Toxicity, and Bias as the primary dimensions. The reason these deserve their own layer — rather than being folded into quality scoring — is that they require different evaluation methods and have different consequences when they fail silently.
The stakes are particularly high for agent systems. Research from Kili Technology found that single-run accuracy masks reliability drops of up to 75% in sustained agent operation. That's not a marginal degradation — it means a system that appears to pass evaluation can fail catastrophically under real workload conditions.
Prompt sensitivity belongs in this layer as well: a model that produces wildly different outputs in response to semantically equivalent prompts is exhibiting a reliability failure that's also a safety concern in high-stakes applications. Red teaming, as a complement to automated safety scoring, is the mechanism for stress-testing these dimensions against adversarial inputs that standard test sets don't cover.
Choosing the right scoring method per metric
Not all metrics can or should be scored the same way. The design decision is matching scoring method to metric type. Latency metrics are instrumented automatically at the infrastructure layer — no judgment required. Output quality metrics like Faithfulness and Contextual Relevancy require semantic understanding, which is why LLM-as-a-judge with structured rubrics (using frameworks like G-Eval) is the most reliable scoring method for this layer.
Safety metrics warrant LLM-judge scoring combined with human spot-checks, particularly for Bias and Toxicity where the failure modes are high-consequence and context-dependent.
The practitioner insight that anchors this design decision is that most LLM outputs aren't binary — they exist on a spectrum of partial correctness, partial faithfulness, partial safety. A pass/fail threshold on a single score can't represent that spectrum. Graduated, rubric-based scoring at each layer is what makes the evaluation signal interpretable enough to act on.
RAG, agent, and chatbot systems each require a distinct metric configuration
The three primary system types — RAG pipelines, agents, and chatbots — each require a distinct metric configuration, not a generic quality score applied uniformly.
For RAG systems, metrics are needed at both the retrieval layer (Contextual Precision, Contextual Recall) and the generation layer (Faithfulness, Answer Relevancy). Evaluating only the generated output without measuring retrieval quality means you can't diagnose whether a faithfulness failure is a generation problem or a retrieval problem.
The architecture is entirely different for agent systems. Action-layer metrics — Tool Correctness, Task Completion — measure whether the agent is doing the right things. Reasoning-layer metrics — Plan Quality, Plan Adherence, Step Efficiency, Argument Correctness — measure whether the agent is thinking about the problem correctly. These two layers can fail independently, which is why they need to be evaluated separately.
Where chatbot systems diverge from both is in the multi-turn structure. Turn Faithfulness, Turn Relevancy, and Turn Contextual Precision apply the same quality dimensions as RAG but across conversation turns — because a model that's coherent on turn one may drift significantly by turn five, and single-turn metrics won't catch that degradation.
The practical constraint on all of this is that more metrics isn't always better. A focused set of metrics that directly maps to your system's failure modes will produce more actionable signal than an exhaustive taxonomy that no one has bandwidth to review. The discipline is in the selection, not the enumeration.
LLM-as-a-judge resolves the scaling problem human review creates in AI evaluation pipelines
Human review is the gold standard for evaluating AI outputs, but it doesn't scale. And as established in the metrics section, the automated alternatives that do scale — BLEU, ROUGE, n-gram overlap — can't evaluate semantic correctness.
LLM-as-a-judge resolves this tension by applying human-like semantic judgment programmatically — at CI/CD speed, across every output, with per-case reasoning you can inspect and act on.
The empirical case for this approach is strong: LLM judges agree with human reviewers approximately 85% of the time, which is actually higher than the rate at which two humans agree with each other on the same evaluation tasks. That single data point reframes the conversation. The question isn't whether LLM-as-a-judge is good enough to replace human review in bulk — it's how to configure it so it stays calibrated.
The mechanism is straightforward; the configuration is where most teams go wrong
The mechanism is straightforward. A judge model receives a structured prompt containing four elements: an evaluation rubric defining the quality criteria, the original user input, the model output being evaluated, and optionally a reference answer to score against. It returns a structured score plus a natural-language explanation of its reasoning — not just a number.
That reasoning component is what separates LLM-as-a-judge from opaque heuristics. When a test case fails, you can read why the judge flagged it, which makes the score actionable rather than just a signal to investigate further.
Use LLM-as-a-judge when outputs are open-ended, subjective, or require semantic understanding — helpfulness, factual alignment, tone, completeness. Use deterministic checks for binary or rule-based outputs where a regex or exact match is sufficient. The two approaches are complementary, not competing.
Configuring judges for different output types
The highest-leverage configuration decision is criteria definition. Vague rubrics produce inconsistent scores; precise rubrics that define what "correct" or "grounded" actually means for your specific system produce reliable ones.
Beyond the rubric, you need to choose a score type. Numeric scores (e.g., helpfulness on a 0–1 scale) work for continuous judgments. Categorical labels (e.g., correct, partially_correct, incorrect) are better when you need explicit classification. Boolean outputs (e.g., does this response violate policy?) suit binary decisions. Each maps to a different downstream workflow — numeric scores aggregate into distributions, categoricals feed regression detection, booleans trigger hard blocks.
You also need to choose a judge mode. A referenceless judge scores an output without a ground truth — useful when correct answers are genuinely open-ended. A reference-based judge scores against a known correct answer, which tightens the evaluation considerably when ground truth exists. Pairwise comparison judges evaluate two outputs head-to-head and select the better one, which is useful for prompt iteration but introduces ordering considerations that need to be managed carefully.
Chain-of-thought and reference-based scoring are the two highest-leverage accuracy improvements
A naive LLM-as-a-judge prompt — just asking the model to rate a response — produces unreliable results. Several techniques meaningfully improve accuracy. Chain-of-thought prompting asks the judge to reason through its evaluation before committing to a score, which reduces arbitrary variation. Few-shot prompting provides labeled examples that anchor the judge's interpretation of your rubric. Reference-based scoring, where applicable, gives the judge a concrete target to compare against rather than relying entirely on its priors.
For structured scoring tasks, G-Eval uses chain-of-thought reasoning as a formal scoring method rather than an informal prompt addition. For complex criteria that involve multiple sub-dimensions — say, evaluating both the accuracy and the tone of a multi-turn response — you can decompose the evaluation into a sequence of sub-scores, each judged independently, then combined into a final result.
This staged approach (sometimes called DAG-based evaluation) prevents a failure on one dimension from distorting the score on another, which is particularly useful when outputs have several independent quality requirements.
Known failure modes and calibration requirements
LLM judges are not plug-and-play. As Confident AI puts it directly: "The wrong scoring method, the wrong prompt, the wrong rubric, and your eval scores end up just as flaky as the model you're testing." The failure modes are specific and addressable, but only if you anticipate them.
Position bias is the most documented issue in pairwise comparisons — judges tend to favor whichever output appears first or second in a consistent pattern. The mitigation is straightforward: run each comparison twice with positions swapped and reconcile disagreements. Prompt sensitivity is subtler; small changes to rubric wording can shift score distributions in ways that aren't visible until you validate against a human-labeled calibration set.
That calibration step is non-negotiable before deploying a judge in CI/CD. Run your judge against a set of cases where you have human ground truth labels, measure agreement, and iterate on the rubric until agreement reaches an acceptable threshold for your use case.
A judge that hasn't been validated against human labels is a liability, not an asset — it will give you confidence in scores that may not reflect reality. Once calibrated, even well-performing judges will surface edge cases that require human review, which is exactly what the review workflow layer of the pipeline is designed to handle.
Build human review workflows and regression detection into the evaluation pipeline loop
Automated scoring gives you numbers. Review workflows give you decisions. The distinction matters more than most teams realize until they've spent months building a metric architecture, only to discover they have no structured process for acting on what those metrics surface.
According to research cited by Kili Technology, most AI teams spend roughly 90% of their effort on model architecture, training data, and hyperparameter tuning — and about 10% on evaluation. The failure rates that follow from that imbalance are not subtle: more than 80% of AI projects fail, at roughly twice the rate of non-AI IT projects, with bad data foundations and evaluation gaps consistently identified as the root cause.
The teams that avoid this outcome don't just have better metrics. They treat human review and regression detection as first-class engineering concerns, not afterthoughts bolted on after the pipeline is already running.
Surfacing failing test cases to domain experts
When an automated score flags a failing case, the score itself rarely tells a domain expert what they need to know: whether the failure is consequential, whether it reflects a systematic problem, or whether the rubric that produced the score is even calibrated correctly. This is why the hybrid evaluation model — benchmarks combined with LLM-as-a-judge and structured human expert review — consistently produces more reliable signal than any single layer alone.
The practical implication is that your AI evaluation pipeline needs a routing mechanism, not just a dashboard. Flagged outputs need to reach the people with subject-matter knowledge to adjudicate them, and those people need enough context — the input, the expected output, the score, and the scoring rationale — to make a meaningful judgment.
Kili Technology's research is direct on this point: evaluation quality is fundamentally a data quality problem, and calibrated annotators working from behaviorally anchored rubrics are what determine signal reliability. Automated scoring can scale the first pass; expert review is what makes the signal trustworthy.
Tracking regressions across model and prompt changes
The most insidious regressions in AI systems are the ones that look like improvements. A prompt change that tightens tone might simultaneously break accuracy on a specific input class. A model update that improves average performance might degrade reliability on the edge cases your users care about most. As Braintrust notes, these failures happen specifically because teams deploy changes without measuring their impact on output quality across the full evaluation set.
Catching regressions requires a stable baseline to compare against, which means dataset versioning is a prerequisite — not an optional enhancement. Label Studio frames this as a question every team should be able to answer at any point in their evaluation history: "Did the model change, or did the benchmark change?" Without explicit versioning, that question becomes unanswerable, and long-term performance trends become noise.
The operational pattern that works is maintaining two evaluation sets in parallel: a stable core set used consistently for trend tracking, and a rotating set that incorporates newer data and emerging failure modes. Automated evaluation runs should trigger on every model or prompt change, comparing results against the versioned baseline so regressions are visible immediately rather than discovered in production.
Keeping evaluation datasets synchronized with the codebase
Evaluation datasets drift out of sync with production systems when they are treated as static artifacts. The test cases that covered your system six months ago may not cover the inputs your users are actually sending today.
Label Studio's guidance is that dataset changes should be done intentionally and tracked explicitly — following a versioning discipline similar to code, tied to specific model or prompt changes, with documented rationale for what was added, removed, or modified.
This discipline is what allows a team to reconstruct the evaluation history of a system and understand whether a performance change reflects genuine improvement or a shift in what the benchmark is measuring.
Enabling cross-functional collaboration without engineering bottlenecks
A review workflow that requires an engineer to add every new test case, adjust every scoring threshold, or route every flagged output will eventually stop functioning as a continuous process and collapse into a periodic engineering task. Product managers, QA teams, and domain experts need to participate in the evaluation loop without filing tickets to do it.
This is where tooling architecture matters. Platforms designed around role-based access and transparent workflows — warehouse-native experimentation platforms, for instance — reduce the collaboration friction that causes review workflows to atrophy.
The broader principle applies regardless of tooling choice: if non-engineers can't update test sets, review flagged outputs, or inspect evaluation results without engineering involvement, the feedback loop will be slower than the pace of model changes, and the pipeline will consistently lag behind the system it's supposed to evaluate.
Close the loop by feeding production experiment data back into your AI evaluation pipeline
Every section of a mature AI evaluation pipeline — the dataset, the metrics, the judges, the review workflows — ultimately feeds a pre-deployment gate. That gate is necessary, but it is not sufficient.
The teams that discover this the hard way are the ones who ship a model with strong offline scores and then watch user satisfaction metrics flatline. The architectural step that prevents this is a production feedback loop: connecting live experiment results back to the evaluation dataset so that each offline test cycle is informed by what actually happened in the real world.
Why offline evaluation alone creates a prediction gap
The dataset construction principles in the first section of this guide address the failure modes you can anticipate. They don't address the ones you can't. Static evaluation datasets, no matter how carefully constructed, cannot update themselves when your user population shifts or when the model's behavior changes in ways that interact with real usage patterns in unexpected ways.
Label Studio's research on evaluation dataset management makes this structural problem explicit: metric changes can reflect changes in the data rather than genuine improvements or regressions in the model. When your offline dataset drifts from production reality, your scores drift with it — and you lose the ability to distinguish between a model getting better and a test set getting stale.
Braintrust frames the cost of this gap as "production surprises" — the incidents that happen after deployment that a well-constructed offline eval should have caught but didn't. The shift to CI/CD-integrated evals reduces the frequency of surprises by running evaluations continuously, but even automated pre-deployment checks are still pre-deployment. They can only validate against what the eval dataset already contains. Production data closes the remaining gap.
Connecting A/B experiment results to offline metric validation
The validation loop works like this: you run an offline evaluation, deploy the winning variant through a controlled experiment, measure user-facing outcomes, and then check whether the offline metrics that predicted the win actually correlated with what happened in production. If they didn't, the metrics need recalibration — not the model.
This is where experimentation infrastructure becomes a direct input to the evaluation program, not just a deployment mechanism. GrowthBook tracks the cumulative impact of experiments across time, which matters because individual AI model changes often have modest per-experiment effects that only become meaningful in aggregate.
Tracking North Star metrics across an entire sequence of model iterations lets teams validate whether offline improvements are compounding into real business outcomes or canceling each other out.
Landon Smith, Head of Post-Training at Character.AI, describes this orientation directly: "We can compare different modeling techniques from the perspective of our users — guiding our research in the direction that best serves our product." That framing — user perspective as the validation layer — is exactly what offline eval datasets cannot provide on their own.
Warehouse-native experimentation for AI systems
The data architecture of your experimentation platform matters more for AI evaluation pipelines than it does for traditional feature experiments. AI model evaluation requires customized metrics — engagement depth, task completion, model cost per session, downstream conversion — that don't map cleanly to a vendor's predefined event schema.
If your experiment analysis runs against data that has been routed through a third-party pipeline, two problems follow: you're limited to whatever metrics that vendor's pipeline supports, and your raw user interaction data is leaving your infrastructure. For AI teams specifically, that second problem is concrete — user interaction data that flows through external servers could potentially be used to train external models, which is a model contamination risk, not an abstract compliance concern.
Warehouse-native experimentation resolves this by running analysis directly against data that already lives in your warehouse — Snowflake, BigQuery, Redshift, Postgres — using SQL-defined metrics that you control. GrowthBook operates this way: production event data never leaves your infrastructure, metrics can be defined or added retroactively, and any calculation can be reproduced and audited.
Using production traffic to enrich the evaluation dataset
The feedback loop closes here. Production experiments surface the inputs where your model underperformed on user-facing metrics — the cases that weren't in your original evaluation dataset because you didn't know they existed. Those cases are the highest-value additions to the next offline test cycle, because they represent real failure modes rather than anticipated ones.
Label Studio describes maintaining a "rotating set that reflects newer data or emerging risks" alongside a stable core evaluation set. The rotating set is implicitly populated from production observations. GrowthBook's experiment history and results tracking captures which experiments worked and which didn't, so that production experiment history informs future dataset construction and metric prioritization rather than being lost between release cycles.
The warehouse-native architecture is what makes this practical rather than aspirational: because production data stays in your warehouse and metrics are defined in SQL, constructing an evaluation dataset from production query results is a query, not a data pipeline project. The eval program becomes self-reinforcing — each deployment cycle generates the evidence that improves the next one.
The five components only produce reliable signal when connected in the right sequence
A reliable AI evaluation pipeline is not a single tool or a single decision — it's five components that only work when they're connected in the right sequence. The dataset constrains what metrics are measurable. The metrics determine what the judge needs to score. The judge's output feeds the review workflow. The review workflow closes the loop back to the dataset. Skip a layer, and the gap shows up as a production surprise you didn't see coming.
Sequence the five components in the right order to avoid rework
The most expensive mistake teams make is building in the wrong order — standing up a judge before the rubric is calibrated, or defining metrics before the dataset covers the failure modes those metrics are supposed to detect.
Start with the dataset. Map your input space, get expert labels on the high-stakes cases, and only then define the metrics that your dataset can actually support. Everything downstream — scoring, review, production feedback — is more stable when the foundation is right.
The data architecture decision matters more than the tooling brand
A small team evaluating a single RAG pipeline doesn't need the same infrastructure as a team running agents across multiple product surfaces. What every team does need, regardless of size, is a data architecture that keeps production experiment data accessible — not locked in a vendor pipeline.
If your experiment results live in your own warehouse, enriching your evaluation dataset from production queries is a SQL problem. If they don't, it becomes a data engineering project every time you want to close the loop. That architectural decision is worth making deliberately early, not revisiting after the pipeline is already running.
Treat evaluation as a living system, not a one-time checklist
The evaluation dataset you build today will drift from production reality within months. The judge rubric that's calibrated now will need adjustment after the next major model update. Regression detection only works if someone is actually reviewing the diffs.
None of this is a reason to delay — it's a reason to build the pipeline with iteration in mind from the start, not treat the first version as the final one.
If this guide helps you avoid even one production incident that a structured eval process would have caught, it's done its job.
What to do next
Your starting point determines your first move. If you don't have an evaluation dataset yet, stop and build one before touching metrics or tooling — map your input space, identify your highest-stakes edge cases, and get expert labels on those first.
If you have a dataset but no structured metrics, audit it against the layered framework in this guide: does it contain enough adversarial inputs to measure safety? Enough multi-turn examples to measure coherence? Fill the gaps before adding scoring infrastructure.
For teams that have metrics but no production feedback loop, the immediate question is whether your experiment data lives somewhere you can query it directly — if it does, your next step is writing the query that surfaces underperforming cases from your last deployment cycle and adding them to your eval set. That single action turns your AI evaluation pipeline from a pre-deployment gate into a self-improving system.
Related insights
- AI Evals vs. A/B Testing: Why You Need Both to Ship GenAI
- A/B testing in the age of AI: evolution or revolution?
Related Articles
A magazine's home page shows two recent issues. The design team wants subscribers to try a shelf with four. All four covers are public, and changing editions while the page is open should update the shelf immediately. That gives you a small React feature with a useful acceptance test. Click from guest to subscriber and back, and count the covers each time.
We'll put the display limit in a typed local flag, evaluate it inside a React component, and leave the choice of edition with the app. The example runs in a client-rendered React app without a GrowthBook account, an SDK key, or a request for flag rules. For the wider workflow, free feature flags for coding agents explains what to ask an agent to implement and how to review the result.
Define what one flag controls
Start with an existing React and TypeScript app, or create a Vite React project for the example. Install both GrowthBook packages so the definitions and the hooks resolve against compatible SDK versions.
Create src/flags.ts. Here the feature value is a number, which lets the component use the same rendering code for either edition. A future change from four covers to three is one edit to the rule.
A guest falls through to the default of two. A subscriber matches the rule and gets four. This rule applies to every subscriber, so the ID has no effect on the result here. If you later roll the shelf out to a percentage of subscribers, you already have an identity to use for repeatable assignment.
The type registration release note explains the version requirement for LocalFeatures. The registration connects the definition, the attributes, and the value returned by the hook. For the TypeScript mechanics, see Jeremy Dorn's Register pattern walkthrough.
Put the current reader above the shelf
Replace src/App.tsx with the component below. The edition switch is a local fixture so anyone reviewing the change can reproduce both states. In an existing app, take those two values from the active reader in your session layer.
The provider receives an instance initialized with the current reader and the checked-in rules. React can render the correct shelf on the first pass for that reader. If the app is still loading a session, decide what should occupy the shelf in the meantime. For this public list a two-cover guest view is reasonable. On a page where a switch would interrupt the reader, wait for the session before mounting the shelf.
Give your agent the React setup
Use the local flags guide to ask for a typed definition, a provider with the current reader, and a test that changes the edition.
Open the Agent GuideThe useMemo dependencies include the ID and the edition. If a reader subscribes while signed in, their ID can stay the same while their edition changes. Depending only on the ID would leave the old SDK instance in place. Passing a fresh object as the dependency on every render would create unnecessary instances. The example uses the two primitive values the rule setup actually needs.
Read the numeric flag where React renders the list
Create src/IssueShelf.tsx. Keep one stable ID per issue and let the component use the resolved value to select how many items to render.
Keep the hook at the top of the component, inside the provider's subtree. The React SDK supplies the flag value through that provider. Calling a hook inside a click handler or inside the list loop would break the Rules of Hooks. Use the returned number in ordinary render logic.
There are two places you can see the number two in this implementation. The definition's defaultValue is what an ordinary guest gets through evaluation. The 2 passed to the hook is a fallback for a value the SDK can't supply. Giving them the same value makes the basic shelf a sensible fallback, but checking only the guest case would let a broken provider arrangement or missing definition go unnoticed. The subscriber case proves that the component actually received the rule.
The list keys identify magazine issues. Keep those keys independent of the flag. Switching from two covers to four should preserve the identity of the first two rows. There's also no need to remount the whole app with an edition-specific key. React preserves state according to component position and keys. For example, a search input outside the shelf shouldn't lose its text because someone subscribed.
Check the transition in both directions
Use the template's build script to type-check and bundle the app. Once that passes, start the dev server and open the local address it prints.
On first load, the page says guest and lists November and October. Click Switch edition. The same page should say subscriber and add September and August. Click again. The list should return to the original two issues, in order. This last check catches code that appends more results on upgrade and never removes them on downgrade.
For a compile-time check, temporarily replace the numeric fallback with the string "2". Run the build again and inspect the error on the hook call. Then restore 2 and rebuild. If the string compiles, check that src/flags.ts belongs to the same TypeScript project as the component and that the package manager resolved compatible core and React versions.
Look for the core package used by your app and by the wrapper. If the app has several incompatible installations, align the versions before diagnosing the JSX. A team using an existing build script should also confirm it actually runs the TypeScript checker.
Hand off a React change someone can review
Give your coding agent the one-shot local feature flags guide and a short description of the observable behavior. For this shelf, the request can be as specific as the test.
The shelf controls how many public titles to display. If your actual feature unlocks paid articles, enforce access when the server serves an article. A client-rendered flag only decides what to show in that browser. Whenever a change to the display limit can wait for a deployment, the small local file keeps the decision reviewable alongside the component. When an editor needs to change it between issues without an engineering release, compare the free GrowthBook options for managing flag rules.
Manage the shelf in GrowthBook
Start a GrowthBook workspace when your magazine team is ready to manage shelf rules between deployments.
Get Started with GrowthBookTwo customers download the same weekly report. One has agreed to preview a new CSV column. The other feeds the old two-column format into an importer. Both requests can land on the same Node.js process, and each needs the right file even if the other request arrives while the report is loading.
This tutorial builds that endpoint with one checked-in feature flag. The process loads the rules once. Each request supplies its own workspace attributes and receives its own evaluation. You can run the whole example on your machine without an account, a client key, or a flag server. The free feature flags for coding agents walkthrough introduces the local approach. Here we'll give the agent a server-specific test to pass.
Set up a small TypeScript service
Use Node.js 22 or newer for this example. In an empty directory, create an npm project that uses ES modules, install the core SDK, and add the TypeScript tools.
Create tsconfig.json at the project root. The sample runs TypeScript directly with tsx and checks types in a separate step. Type checking with tsx explains why the two commands serve different purposes.
The following files all live next to that configuration. The server imports ./flags.js even though the source file is flags.ts. That spelling follows TypeScript's Node.js module resolution for ESM and works with this runner.
Define the report contract in one flag
Create flags.ts. The public format has two columns. The sample preview workspace gets one additional column. The only targeting attribute the rule needs today is reportPreview. Carry the workspace ID too, so two people downloading a report on behalf of the same workspace can share an assignment if you introduce a percentage rollout later.
The SDK type registration update covers this rule syntax and the 2.2.0 minimum. If you misspell reportPreview in a condition or use a string where the boolean flag expects a value, TypeScript can point at the definition. The Register pattern also makes the same feature name available in other modules without threading a generic type through each handler.
Before you add the endpoint, decide what belongs to the process and what belongs to the request. The feature definitions are identical for both customers. Their identity and preview enrollment can differ. If a handler changes an attribute on a single shared user instance before awaiting a database query, another handler could replace that attribute before the first handler resumes.
Give your agent a server-side task
Use the one-shot guide to add checked-in rules. Ask your agent to keep workspace attributes local to each request and demonstrate both CSV formats.
Open the Local Flags GuideCreate a scope when the request arrives
Create server.ts. The Node.js SDK provides GrowthBookClient for the process and createScopedInstance for the current request. The two fixture paths below stand in for two authenticated workspaces. The server binds to the loopback address so you can exercise it locally.
The HTTP handler looks up a workspace, creates its scope, and holds that scope across an asynchronous operation. The short promise-based timer gives a second request time to arrive. In a real export, that's where the database or storage read would happen. Keep the stable client at module scope and the scoped instance inside the handler. If a formatter needs the decision, pass it the boolean or the scoped instance.
In production, resolve the workspace and its access rights from the authenticated session before reading the report. The two selectable paths here are fixtures for public sample data. A caller's choice of a header, query string, or workspace slug can't establish permission to read another customer's report. The endpoint also prevents shared response caching. If you cache real exports, the cache needs to distinguish the workspace and the report format, along with any other inputs that change the response.
Test two requests that overlap
In the first terminal, type-check the service and start it. A successful type check exits quietly. The next command prints the loopback address and keeps the server running.
Save the following as verify.mjs. In a second terminal, run node verify.mjs. Node's built-in fetch calls the local server. Strict assertions compare the full header and data row, including where each row ends.
You should see the single success line. Testing just the preview workspace proves that the code can add a column. Testing both responses catches the more expensive mistake of silently changing an existing customer's export. Keeping the old format assertion around is especially valuable when the downstream importer belongs to someone outside your team.
To check the compile-time boundary, temporarily change gb.isOn("includeUniqueReaders") to gb.isOn("includeUniqueReader") and rerun npx tsc --noEmit. The diagnostic should identify the misspelled key. Restore it before running the server again. A coding agent can include the before-and-after type check and the two CSV headers in its pull request.
Decide when to expand the report
When one preview customer is ready, leave everyone else on the default. If the next step is to enroll a fraction of workspaces, choose an attribute that matches the promise you're making. Hashing a workspace ID lets colleagues downloading the same report share a format. Hashing each user's ID could give two analysts in the same company different column sets. The one-shot guide shows how to express a percentage and hash attribute in a local rule.
A new rule in flags.ts reaches a process through your deployment. During a rolling deploy, the same workspace might hit old and new processes. If customers need a durable choice of export schema, keep supporting the agreed format in the API itself. When the operational requirement is to change targeting between deploys, you can keep the scoped evaluation in the handler and change how the process receives its rules. The free GrowthBook offerings overview covers Cloud Starter and self-hosting for teams that want to manage those rules.
Manage report targeting in Cloud
Create a GrowthBook workspace when the team supporting exports needs to expand the preview independently of a server release.
Get Started with GrowthBookYour conference agenda has a new “Show room” button. Reviewers should see it on the first page load. Everyone else should get the existing agenda. If a Server Component renders the old agenda and a browser hook independently decides to show the new button, the first HTML and the browser can disagree.
In the Next.js App Router, the server can make this decision once and pass a boolean to the interactive component. We'll define the flag in the repo, select the preview audience with a local test cookie, and verify the actual HTML for both visitors. Clicking the button will still work after hydration. You can follow along without a GrowthBook account or client key. If you're assigning this work to an agent, the free feature flags for coding agents walkthrough gives the background.
Keep the flag definitions on the server
Use a TypeScript App Router project, or create a small one with create-next-app. These paths assume the project has an app directory at its root. If yours uses src/app, put both app and lib under src so the relative imports still match.
Keep the starter's root layout. Create lib/agenda-flags.ts with the following code. The SDK type registration update explains how LocalFeatures checks the flag and its rule against the registered types. This setup requires version 2.2.0 or later.
The module can reuse the client and rules across requests handled by the same process. It only holds the current visitor's audience inside the function call. Two requests can therefore use the same flag file and get different results. The Node.js SDK documents the scoped client used under the App Router here.
This particular rule has no percentage and needs no visitor ID. The two audiences are sufficient. If the team later asks for a rollout to 10% of attendees, add a stable attendee or registration ID and choose which of those units should stay together. Jeremy Dorn's Register pattern article explains how a change to an attribute type reaches the call sites that construct it.
Read the cookie for this request
Create app/agenda/page.tsx. The static heading can render for everyone. The request-specific content sits behind a Suspense boundary, so the fallback can show a neutral loading message until the server has the cookie.
The App Router's cookies function reads the incoming request asynchronously. Read it inside the visitor-specific component. Keeping that read out of shared cached code lets the surrounding page reuse common content without treating one visitor's decision as another's. This placement also accommodates App Router projects using Cache Components.
Give your agent the Next.js setup
Use the local flags guide with a concrete request to evaluate one flag on the server and return the same decision to the browser.
Open the Local Flags GuideThe cookie in this demo is a convenient way to preview a public UI treatment. Anyone with that cookie can see the room label. To target paying attendees or private sessions, obtain the audience from the verified session on the server and authorize the underlying data separately.
Pass one decision to the interactive component
Create app/agenda/Agenda.tsx. It's a Client Component because a visitor can open and close the room details. Its initial branch comes directly from the boolean supplied by the page.
The client boundary takes a serializable prop. The component receives true or false. The SDK instance, targeting rules, and cookie handling stay in the server module. You don't need a React provider for this component because its only browser-side choice is whether the visitor has clicked the button.
Follow one page load through server rendering and hydration. For a preview visitor, the server can send a section with a “Show room” button. React's first client render gets the same showRoom value and starts with open set to false. Hydration attaches the click handler. Opening the room detail then updates component state and doesn't require another flag evaluation.
Verify the HTML and the click separately
Build the production app and start it on port 3100.
In a second terminal, save this as verify-agenda.mjs in the project root and run node verify-agenda.mjs. The test makes two requests to the same route and looks for a marker on the rendered section. A marker in the HTML helps catch an implementation that only adds the intended layout after JavaScript runs.
Now open http://localhost:3100/agenda in a fresh browser profile. You should see the session title without a room button. In that local page's browser console, set the demo cookie and reload.
Click Show room and look for Room 204. Click Hide room and the room should disappear. This second check proves the component became interactive. If the server response test passes but the click fails, inspect the browser console for a hydration error before changing the flag rules.
Remove the fixture and reload once more. The button should disappear and the agenda title should remain.
The reload is deliberate. Editing the cookie in an already open document doesn't rerun its Server Component. In your app, use the normal session-change flow to request a fresh server render when a visitor signs in, signs out, or leaves a preview group.
Choose where the next flag should be evaluated
For a decision needed in the initial HTML, give the agent an observable requirement. Ask it to show the two HTTP responses, then click the interactive control in the preview. The first check catches an incorrect layout. The second catches correct HTML that never becomes interactive.
If a later feature depends on an action entirely within the browser, evaluate whether its flag belongs in the client tree. The one-shot local flags guide covers both placements. This agenda only needs one server decision. Updating its checked-in rule takes a deployment. Keep that tradeoff in view if the event organizer needs to pause a preview while attendees are already arriving. For that case, compare GrowthBook’s free options for changing flags between deploys.
Manage the agenda rollout in Cloud
Create a GrowthBook workspace when the organizer needs to adjust a preview audience while your Next.js app is serving attendees.
Get Started with GrowthBookReady to ship faster?
No credit card required. Start with feature flags, experimentation, and product analytics—free.



