Skip to main content

AI Engineering Guide

AI engineering is the discipline that makes AI features dependable: the practices, tooling and tests that turn a model call into a product component.


Contents​


About This Guide​

A model call is easy to write and hard to trust. A prototype that answers ten demo questions well says little about how the feature will behave on the ten-thousandth user request, after a prompt edit, after the provider updates the model, or after the knowledge base changes. AI engineering closes that gap. It applies the habits of mature software engineering (version control, automated tests, staged releases, monitoring, incident response) to systems whose behavior is probabilistic and depends on data, context and third-party models.

This guide is organized around a five-stage loop. Each stage has its own chapter, and Chapters 7 and 8 show how to run the loop as a team and as an organization.

StageQuestion it answersCore practice
DesignWhat exactly are we building, and what may change independently?Prompts, context and model choice treated as versioned, tested code
EvaluateIs this change better, and is it safe to release?Evaluation sets and quality gates before every release
ShipHow does it reach users without taking risk with it?A gateway and serving layer, so teams can swap models without rewrites
ObserveWhat is it doing now, in production?Monitoring for quality, latency and cost
ImproveWhat do we fix next, and how do we know it worked?Failures fed back into designs, datasets and gates

Who This Guide Is For​

The guide is written for enginerring leaders, software engineers, AI/ML engineers, platform engineers, SREs, and technical product managers who build or operate features on top of foundation models. It assumes you are comfortable with CI/CD, service-oriented architectures and basic statistics. It does not assume deep knowledge of model training.

Using This Guide in a Large Engineering Organization​

Organizations that already run mature engineering systems do not need a parallel process for AI. The guide is designed to plug into what exists:

  • Every practice is expressed in terms of artifacts and checks that fit existing tooling: files in version control, tests in CI, flags in a configuration service, spans in a tracing system, SLOs in an on-call program.
  • Appendix B maps each concept to the terms established teams already use (launch criteria, dark launch, experiment guardrails, error budgets, blameless postmortem), and adds a second table that shows the integration point in your current systems.
  • Section 7.7 describes how to split ownership between a central platform team and product teams so that standards scale without becoming a bottleneck.
  • Appendix C lists example building blocks on several cloud platforms and in portable open-source form, because many organizations run internal equivalents.

How to Use It​

  • Read Chapter 1 to align on vocabulary and principles.
  • Read Chapters 2 to 6 in order if you are building a system, or jump to the stage where you feel the most pain.
  • Use Chapter 7 to set up the team, risk tiers and review process, and to plan adoption across many teams.
  • Work the exercises at the end of each chapter against a feature you own. They turn the guide into a team workshop.
  • Use Chapter 8 and the appendices as a working reference: reference architecture, readiness checklist, and a table that maps this guide’s terms to practices you may already run.

Conventions​

  • The guide is vendor-neutral. Where a concrete service helps, Appendix C maps concepts to several cloud platforms and portable open-source options as examples.
  • Code is illustrative Python and configuration. It shows the shape of a solution, not a library to copy.
  • Numbers in worked examples are illustrative and are labelled as such.
  • A running example, the Refund Policy Assistant, appears throughout. It answers questions about refund eligibility using the company’s policy documents.

Chapter 1. What AI Engineering Is​

In this chapter: the definition and scope of AI engineering; how it differs from traditional software engineering, MLOps and SRE; and the seven principles that the rest of the guide applies.

1.1 A Working Definition​

AI engineering is the practice of designing, evaluating, releasing, operating and improving software whose core behavior is produced by a model rather than written as explicit logic. The unit of work is the AI component: a bounded piece of functionality that combines a model, the instructions given to it, the context assembled for it, and the checks applied to its output.

The guide focuses on applications built on foundation models, such as large language models. The loop applies equally to classical machine learning models, with training pipelines replacing some of the prompt and context work.

1.2 Why It Is Different From Traditional Software​

AspectTraditional softwareAI feature
BehaviorDeterministic for a given inputProbabilistic; the same input can produce different outputs
SpecificationRequirements map to code pathsRequirements are statistical: a quality level over a distribution of inputs
TestingAssertions on exact outputsGraded outputs over datasets, with confidence intervals
Sources of regressionYour code changesYour code, prompts, context sources, retrieval index, model version, provider behavior and input drift
Failure modeErrors, crashes, wrong status codesFluent, plausible and wrong answers that raise no exception
Cost modelMostly fixed per requestVariable per request, driven by tokens and model choice
DependenciesLibraries and services you can pinHosted models that can change or be retired on the provider’s schedule

The most important consequence is that a green build proves very little. Code can be unchanged while the system degrades, because a provider changes model behavior, a source document becomes stale, or user inputs shift. Evaluation and monitoring must therefore be part of the engineering system, not an afterthought.

1.3 How It Relates to Neighboring Disciplines​

DisciplinePrimary focusOverlap with AI engineering
Software engineeringCorrect, maintainable codeVersioning, review, testing, release practices
MLOpsBuilding, deploying and monitoring models, including models trained in-houseData and training pipelines, evaluation, model registry, serving and drift monitoring
LLMOps or GenAIOpsOperating applications built on foundation modelsPrompt management, evaluation, gateways, cost control
SREReliability of production servicesSLOs, error budgets, incident response, capacity planning
Data engineeringPipelines and data qualityIngestion, indexing, freshness and lineage of context data
Security and trustProtecting systems and usersPrompt injection, data leakage, excessive agency, abuse

AI engineering is not a replacement for any of these. It is the integration layer that makes them work together for AI-powered features.

1.4 The AI Engineering Loop​

The AI Engineering Loop

The loop is continuous. A feature is never “finished”: models change, data changes, users change. The goal is to make each pass through the loop cheap, safe and evidence-based.

1.5 Seven Principles​

  1. Treat prompts, context assembly and model choice as code. They define behavior, so they are versioned, reviewed, tested and released like code.
  2. No change ships without evidence. Every change to a behavior-defining artifact passes an evaluation gate.
  3. Version what changes at different speeds independently. Prompts, models, retrieval indexes, tools, policies and datasets each have their own version and rollback path.
  4. Design for failure. A model is a probabilistic, rate-limited, remote dependency. Plan for timeouts, refusals, malformed output and outages.
  5. Make cost and latency quality dimensions. An answer that is correct but too slow or too expensive is a failed answer.
  6. Observe quality, not only availability. A healthy service that gives wrong answers is an incident.
  7. Keep a person accountable for every consequential decision. Autonomy is granted deliberately, in proportion to risk and evidence.

1.6 Chapter Summary​

  • AI engineering turns a model call into a dependable product component.
  • Behavior depends on more than your code, so tests and monitoring must cover the whole system.
  • The loop of Design, Evaluate, Ship, Observe and Improve, guided by seven principles, structures the rest of this guide.

Exercises

  1. List three changes that could degrade the Refund Policy Assistant without any code change. For each, name the signal that would reveal it.
  2. Map the five stages of the loop to the processes your organization already runs (launch review, experimentation, SLO review, postmortems). Where are the gaps?
  3. Choose an AI feature you own. Which of the seven principles does it violate today, and what would it cost to fix the most important violation?

Chapter 2. Design​

In this chapter: how to specify an AI feature, structure an AI component, version the artifacts that define its behavior, engineer its context, choose a model, and design for failure and safety.

2.1 Start With a Feature Specification​

Before writing a prompt, write down what “good” means. A specification for an AI feature is short, structured and testable.

feature: refund-policy-assistant
task: Answer questions about refund eligibility using current policy documents.
users: Support agents (phase 1); customers (phase 2)
risk_tier: 2
autonomy: suggest-only # a human reviews and sends every reply
success_criteria:
answer_correctness: ">= 0.90"
groundedness: ">= 0.95" # every claim traceable to a cited passage
p95_latency_seconds: "<= 6"
cost_per_answer_usd: "<= 0.03"
failure_taxonomy:
- wrong_policy_version
- unsupported_claim
- missed_exception
- unsafe_disclosure
- refusal_when_answerable
out_of_scope:
- legal advice
- executing payments

Four elements matter most:

  • Success criteria are statistical and numeric. They become your quality gates in Chapter 3.
  • Failure taxonomy names the ways the feature can go wrong. It shapes the evaluation set, the graders and the dashboards.
  • Risk tier determines how much evidence, review and oversight are required (Chapter 7).
  • Autonomy level states what the system may do without a human: suggest, act with approval, or act alone.

2.2 Anatomy of an AI Component​

An AI component has six parts. Keeping them separate makes each one testable and replaceable.

PartResponsibilityTypical form
Interface contractTyped input and output, error semanticsSchema, function signature
Prompt templateInstructions, role, format, examplesVersioned template file
Context assemblerGathers and orders the information the model seesRetrieval, memory, tool results, user data
Model bindingWhich model and which inference parametersConfig: provider and model identifier, version or deployment reference, temperature, token limits
ValidatorsCheck and repair the outputSchema validation, policy checks, groundedness checks
FallbackWhat happens when the above failsAlternate model, cached answer, human handoff
from dataclasses import dataclass

@dataclass(frozen=True)
class ComponentSpec:
name: str
prompt_version: str # e.g. "refund_answer@14"
model: str # pinned model identifier
temperature: float
max_output_tokens: int
output_schema: type # validated before anything downstream sees it

def run(spec: ComponentSpec, request) -> "Result":
context = assemble_context(request, budget_tokens=6000)
prompt = render(spec.prompt_version, request=request, context=context)
raw = gateway.invoke(spec.model, prompt,
temperature=spec.temperature,
max_tokens=spec.max_output_tokens)
return validate_or_fallback(raw, spec.output_schema, request)

Two design rules follow. First, the model is behind an interface, so it can be swapped without touching callers. Second, nothing downstream consumes raw model output. It passes through validation first, because model output is untrusted input. If a repair or regeneration step is used, validate the repaired output again before passing it downstream.

2.3 Version Everything That Defines Behavior​

Different artifacts change at different speeds and need different controls.

ArtifactChangesLives inRollback unit
Prompt templatesOftenRepository or prompt registryPrompt version
Model bindingOccasionallyConfigModel and parameter set
Retrieval index and corpusContinuouslyIndex store, with snapshotsIndex snapshot
Tool definitionsOccasionallyRepositoryTool version
Guardrail policiesOccasionallyPolicy repositoryPolicy pack version
Evaluation setsContinuouslyDataset storeDataset version
Thresholds and routing rulesOccasionallyConfigConfig version

Combine the versions that make up a deployable behavior into a release bundle. The bundle is the unit you evaluate, promote and roll back. Pin an immutable model version or deployment revision where the provider supports it. If the provider exposes only a mutable model name, record that limitation and run scheduled evaluations to detect changes in behavior.

bundle: refund-assistant@2026.11.3
prompt: refund_answer@14
model: provider-model-id@pinned-version
retrieval_index: policies-index@2026-11-08
guardrails: policy-pack@7
tools:
- crm.get_account@3
eval_set: refund-golden@9
config: thresholds@5

Every production request should record the bundle version, so any answer can be traced to the configuration that produced it. Where a provider does not expose an immutable model revision, record the model identifier and the provider metadata available at request time; do not imply that the model behavior is fully reproducible.

2.4 Repository Layout​

A layout that mirrors the component anatomy keeps reviews focused.

Repository Layout

2.5 Engineer the Context​

For most applications, the information placed in the model’s context matters as much as the model itself. Treat context assembly as an engineered pipeline with its own tests.

  • Prioritize. Order sources by value to the task (task instructions, retrieved evidence, conversation state, user profile) and cut from the bottom when the token budget is tight.
  • Budget. Set explicit token budgets per section. Unbounded context raises cost and latency and can degrade quality.
  • Retrieve deliberately. Choose chunking, embedding, filters and reranking based on measured retrieval quality (Chapter 3), not defaults. Re-check authorization at the retrieval boundary and preserve source identifiers so generated claims can be traced to their evidence.
  • Separate trusted from untrusted content. Instructions come from you. Retrieved documents, user messages and tool results are data and can contain instructions that try to hijack the model. Mark them clearly, and never grant authority to text just because it appears in context.
  • Enforce access control before retrieval. The model should only ever see content the requesting user is allowed to see.
  • Be explicit about memory. Decide what persists across turns or sessions, for how long, and how users can inspect or delete it.

2.6 Choose the Model With Evidence​

Select models by running your evaluation set, not by reading leaderboards alone.

CriterionWhat to check
QualityScore on your task, per slice, with confidence intervals
LatencyTime to first token and total time at realistic output lengths
CostCost per successful outcome, including retries and long prompts
Context windowFit for your largest realistic inputs
Output controlSupport for structured outputs and tool calling
Data handlingRetention, training use, residency, contractual terms
CapacityRate limits and quota options for your traffic
LifecycleVersion pinning, deprecation notices, retirement schedule

A practical procedure: shortlist three candidates, run the same evaluation set on each, plot quality against cost and latency, then pick a primary model and a fallback. Record the decision, the data behind it and the date, because you will revisit it when new models appear.

2.7 Design for Failure​

FailureDetectionResponse
Provider timeout or transient errorTimeout, retryable error codeRetry with jitter within the request budget, then fall back to a second model
Rate limit429 or quota signalQueue or shed low-priority traffic, then fall back
Malformed outputSchema validationOne repair attempt, then fall back
Unsupported claimGroundedness checkRemove the claim, regenerate, or hand off to a human
Guardrail triggerPolicy checkSafe refusal with a helpful message
Retrieval returns nothing relevantLow relevance scoresSay that no answer was found; do not guess
Downstream tool failureTool errorReport partial results; never invent tool outputs

Decide the degraded mode in advance. For a support assistant, it might be “show the policy search results without a generated summary.”

2.8 Build Safety Into the Design​

Threat model every AI component at design time. The recurring risks are:

  • Prompt injection, direct from users or indirect through retrieved documents and tool results.
  • Sensitive data disclosure through context, logs or generated text.
  • Improper output handling, where model output is passed to a browser, shell, database or another service without validation.
  • Excessive agency, where the model has more tools, permissions or autonomy than the task needs.

Controls that apply broadly: least-privilege tool access, allow-lists for tool arguments, output validation and encoding, redaction of personal data before it reaches the model or the logs, rate limits and abuse detection, and human approval for high-impact actions.

2.9 Chapter Summary​

  • Specify the feature with numeric success criteria, a failure taxonomy, a risk tier and an autonomy level.
  • Structure each AI component into six parts behind a typed interface.
  • Version prompts, models, indexes, tools, policies and datasets independently, and combine them into release bundles.
  • Engineer context as a pipeline, choose models with your own evidence, and design degraded modes and safety controls up front.

Exercises

  1. Write a feature specification in the format of Section 2.1 for an AI feature in your product: numeric success criteria, at least five failure types, a risk tier and an autonomy level.
  2. Sketch the six parts of the component for that feature. Which part currently lives inside a single prompt string?
  3. Write a release bundle manifest for it. Which artifacts can you not pin today, and what compensating control would you use?
  4. For each of the four risks in Section 2.8, name one control you would apply to your feature.

Chapter 3. Evaluate​

In this chapter: the evaluation pyramid, how to build and govern datasets, graders and metrics, statistical practice, quality gates, CI integration and online evaluation.

3.1 Evaluation Is the Specification and the Test Suite​

In AI engineering, the evaluation set plays two roles. It is the executable specification of behavior you expect, and it is the regression suite that protects that behavior. A team without a good evaluation set can change prompts, models or retrieval and have no reliable way to know whether it made things better or worse.

3.2 The Evaluation Pyramid​

Use several layers. Cheap, fast checks run often. Expensive, realistic checks run before release.

LayerWhat it checksRunsRelative costTypical size
Component checksFormat validity, schema, deterministic rules, tool-call argumentsEvery commitVery lowDozens of cases
Task evaluationQuality on the core task against a golden setEvery pull request (smoke subset), nightly (full)Low to medium100 to several hundred cases
End-to-end scenariosMulti-step flows including retrieval, tools and handoffsNightly and pre-releaseMediumTens of scenarios
Safety and red-teamInjection, leakage, policy violations, abusePre-release and on policy changeMediumHundreds of adversarial cases
Online evaluationReal traffic quality and outcomesContinuouslyVariesSampled traffic

3.3 Build the Dataset​

An evaluation dataset is a product. It needs a design, an owner and a version history.

Composition. Include four kinds of cases:

  1. Typical cases that reflect real traffic.
  2. Edge cases: unusual phrasing, long inputs, multiple languages, conflicting sources.
  3. Adversarial cases: injection attempts, requests for out-of-scope or sensitive content.
  4. Regression cases captured from past incidents and production failures.

Slices. Tag every case with slices such as customer segment, language, topic, risk level and difficulty. Averages hide failures, and per-slice results reveal them.

Record format. Keep cases in a plain, diffable format:

{
"id": "refund-0142",
"question": "Can an enterprise customer get a refund after 45 days?",
"expected": {"answer_summary": "No, except under the annual-plan exception", "must_cite": ["policy-4.2"]},
"slices": ["enterprise", "exception"],
"risk": "high",
"source": "support-ticket-2026-09"
}

Size. Start small and grow with evidence. Fifty to one hundred carefully curated cases are enough to begin exploratory evaluation and establish an initial regression suite; they are not automatically sufficient for high-confidence release decisions. Add cases from every incident and every disagreement between graders. Aim for several hundred cases for each critical slice before you rely on small differences.

Hygiene.

  • Keep a development set for tuning prompts and a separate test set for gates. If you tune against the test set, your gate stops measuring generalization.
  • Avoid contamination. Do not put gate cases in prompts, few-shot examples or fine-tuning data.
  • Review synthetic data. Generated cases are useful for coverage, but have humans check labels before they count.
  • Remove or protect personal data in datasets, and apply the same access control as production data.
  • Version the dataset and record the version in every evaluation report.

3.4 Graders and Metrics​

A grader turns an output into a score or decision. Use the cheapest grader that is reliable for the dimension you are measuring, and retain a human-review path for dimensions where automated grading is not sufficiently dependable.

DimensionExample metricsTypical grader
CorrectnessMatch to reference, rubric scoreDeterministic where possible; model-based or human otherwise
GroundednessShare of claims supported by cited passagesModel-based with human spot checks
Retrieval qualityRecall at k, precision at k, mean reciprocal rankDeterministic against labeled relevant documents
Citation accuracyCitations that actually support the claimDeterministic plus model-based
Format validitySchema pass rateDeterministic
Refusal behaviorCorrect refusals and unnecessary refusalsDeterministic labels plus model-based
SafetyViolation rate on adversarial setDeterministic rules plus model-based plus human review
LatencyTime to first token, total time at p50, p95, p99Measured
CostTokens and cost per requestMeasured
Tool useCorrect tool selected, valid arguments, task completedDeterministic

Model-based graders (often called LLM-as-judge) scale well but need care:

  • Write a rubric with anchored levels and prefer simple decisions (pass or fail, or a short ordinal scale) over fine-grained scores.
  • Use a different model for judging than for generating when possible, and pin the judge model and prompt versions.
  • Calibrate against humans. Have qualified reviewers label a representative sample, measure agreement with the grader, and revise the rubric until agreement is acceptable for your risk tier. Cohen’s kappa suits categorical judgments; choose a measure appropriate to the score type and account for class imbalance.
  • Control known biases, such as preferring longer answers or the first option shown, by randomizing order and testing for length effects.
  • Keep humans in the loop for ambiguous, high-risk and newly discovered failure types.

3.5 Statistical Practice​

Model outputs vary, and datasets are samples. Treat results as estimates with uncertainty.

  • Control variance. Set low temperature for evaluation where appropriate, and repeat runs when outputs vary. Report the spread. Low temperature can reduce variation, but it does not make a hosted model fully deterministic.
  • Report confidence intervals. Bootstrap or analytic intervals quantify sampling uncertainty; they do not, by themselves, prove that a difference is practically important or eliminate grader bias.
  • Compare paired. Evaluate the baseline and the candidate on the same cases and analyze the per-case differences.
  • Mind the sample size. Consider a pass rate near 0.90 measured on 200 independent cases. The normal-approximation 95 percent half-width is 1.96 × √(0.9 × 0.1 / 200) ≈ 0.042, about four percentage points, so a two-point improvement is hard to distinguish from noise. For paired comparisons, analyze the per-case differences with a paired interval or test. Treat this calculation as a rough guide, not a universal sample-size rule.
  • Look at slices. Check for regressions in important slices even when the overall number improves.

3.6 Quality Gates​

A quality gate is an automated, versioned decision rule that decides whether a change may proceed.

Gate typeExamplePurpose
Absolute thresholdCorrectness lower confidence bound at least 0.90Meet the success criteria
No regressionCandidate not worse than baseline by more than a set marginProtect existing behavior
Slice floorNo critical slice below 0.85Prevent hidden failures
Hard failZero observed safety violations on the critical adversarial setEnforce non-negotiable constraints; evidence about tested cases, not proof of zero risk
Budgetp95 latency and cost per request within limitsKeep the feature viable

The following sketch shows gates as ordinary tests, so they run in the same CI system as the rest of your code.

import random
import pytest

from evals.loader import load_cases
from evals.graders import grade_correctness, passes_safety
from app.component import answer

CASES = load_cases("evals/datasets/refund-golden@9.jsonl")

def lower_bound(scores, alpha=0.05, resamples=2000, seed=7):
"""Approximate one-sided bootstrap lower bound on the mean score."""
if not scores:
raise ValueError("At least one score is required")
if not 0 < alpha < 1 or resamples < 1:
raise ValueError("alpha and resamples must be positive and valid")

rng = random.Random(seed)
means = sorted(
sum(rng.choices(scores, k=len(scores))) / len(scores)
for _ in range(resamples)
)
index = max(0, min(resamples - 1, int(alpha * resamples)))
return means[index]

@pytest.fixture(scope="session")
def results():
return [(case, answer(case.question)) for case in CASES]

def test_correctness_gate(results):
scores = [grade_correctness(out, case.expected) for case, out in results]
assert lower_bound(scores) >= 0.90, "Correctness gate failed: do not release"

@pytest.mark.parametrize("slice_name", ["enterprise", "exception", "multilingual"])
def test_slice_floor(results, slice_name):
scores = [grade_correctness(out, c.expected)
for c, out in results if slice_name in c.slices]
assert scores, f"No cases for slice {slice_name}"
assert sum(scores) / len(scores) >= 0.85, f"Slice floor failed: {slice_name}"

def test_no_critical_safety_violations(results):
violations = [c.id for c, out in results
if c.risk == "high" and not passes_safety(out)]
assert not violations, f"Safety violations: {violations}"

Treat gate thresholds as versioned configuration with an owner. Loosening a threshold is a reviewed change, not a quiet edit.

3.7 Integrate Evaluation With CI and CD​

StageWhat runsTime budgetOutcome
Pull requestComponent checks plus a smoke subset of the golden setMinutesBlock merge on failure
NightlyFull golden set with repeats, slice reports, drift check on indexHoursOpen an issue on regression
Pre-releaseFull suite, safety red-team, load test, cost projectionHoursGate promotion of the release bundle
Post-releaseShadow or canary comparison, online metricsContinuousGate ramp-up; trigger rollback

Keep evaluation affordable: cache deterministic results, sample for fast loops, use cheaper judges for screening and reserve the strongest judge and human review for gates. Publish every evaluation report with the bundle version, dataset version, grader versions and run date.

3.8 Online Evaluation​

Offline sets cannot cover everything real users do. Add online evaluation:

  • Shadow mode runs the candidate on live traffic without showing its output, and compares it with the current system.
  • Controlled experiments (A/B tests) measure outcome metrics such as task success, escalation rate and user feedback. Define guardrail metrics (safety, latency, cost) that must not regress, and decide in advance when to stop.
  • Sampled review sends a stratified sample of production traces to model-based graders and human reviewers, which provides a continuous quality signal.
  • User feedback (ratings, edits, escalations) is informative but biased. Use it to find cases to review, not as the only quality metric.

3.9 Red-Teaming​

Maintain a structured adversarial set and extend it continuously. Cover direct and indirect prompt injection, attempts to extract system instructions or private data, tool misuse, jailbreak patterns, and harmful or off-policy requests relevant to your domain. Run the relevant adversarial suite before every release of a Tier 2 or Tier 3 feature, whenever guardrail policies change, and when a new attack pattern is published. Tier 1 features still need baseline safety checks proportionate to their use and exposure. A passing suite is evidence about the tested threat cases, not a guarantee that the system is secure against every attack.

3.10 Chapter Summary​

  • Evaluation sets are the specification and the regression suite.
  • Layer cheap and expensive evaluations, and run them at the right points in CI and CD.
  • Build datasets with typical, edge, adversarial and regression cases, tagged by slice, and keep development and test sets apart.
  • Calibrate model-based graders against humans, report uncertainty, and encode decisions as versioned quality gates.
  • Complement offline gates with shadow runs, experiments and sampled review in production.

Exercises

  1. Draft 20 golden cases for your feature, covering typical, edge, adversarial and regression cases, and tag each with at least one slice.
  2. A candidate raises the pass rate from 0.90 to 0.92 on 200 paired cases. What would you compute before accepting it? What else would you check?
  3. Design a calibration study for a model-based grader: who labels, how many cases, which agreement measure, and what threshold you would accept for a Tier 2 feature.
  4. Write the five gate types from Section 3.6 for your feature, with thresholds and owners.

Chapter 4. Ship​

In this chapter: release bundles, the AI gateway and serving layer, rollout and rollback, resilience, latency, caching, capacity and cost controls.

4.1 Release the Bundle, Not the Pieces​

Promote a release bundle (Section 2.3) through environments as one unit. Each promotion records the evaluation report that justified it. Because prompts, models, indexes and policies are versioned independently, you can often roll back one without the others, for example reverting to the previous prompt while keeping a new index.

4.2 The AI Gateway​

The gateway is the serving layer between your applications and models. Centralizing model access gives teams a consistent control point and can let them swap models without rewriting applications. It does not remove the need to evaluate provider-specific behavior or differences in model capabilities.

ResponsibilityWhat it does
Provider abstractionOne interface for multiple models and providers; model changes become configuration
Authentication and authorizationIdentify callers, enforce which models and tools each team may use
Routing and cascadingSend each request to the right model by task, cost, latency or complexity
Retries and fallbacksHandle timeouts and rate limits with a defined fallback chain
GuardrailsApply input and output policy checks consistently
CachingReuse results where safe (Section 4.6)
Quotas and rate limitsProtect shared capacity and budgets
Logging with redactionRecord traces without leaking sensitive data
Cost attributionTag every call by team, feature, tenant and bundle version

Keep the gateway thin and policy-driven. Business logic belongs in the AI component. The gateway owns cross-cutting concerns, while application-level authorization and domain rules remain enforced by the systems that own them.

4.3 Serving Topologies​

OptionStrengthsTrade-offs
Hosted model APIFast to adopt, no capacity managementLess control over versions, data handling and cost at scale
Managed model platformEnterprise controls, regional options, integrated guardrailsProvider-specific features can add lock-in
Self-hosted modelsControl over data, latency and cost at high volumeYou own capacity, scaling, upgrades and optimization

Many organizations use a mix. The gateway makes the mix manageable, because callers see one interface.

4.4 Rollout Strategy​

StageUser exposurePurposeExit criteria
Offline gateNoneProve the bundle meets thresholdsAll gates pass
ShadowNone (output hidden)Compare with current system on live trafficNo regression on quality, latency, cost
InternalEmployeesCatch usability and edge issuesReview of sampled traces
Canary1 to 5 percentDetect problems at small scaleGuardrail metrics stable
Ramp25, 50, then 100 percentScale with monitoringMetrics stable at each step
Hold-backSmall control groupKeep a baseline to measure long-term effectDefined review cadence

Use feature flags for control. Define rollback triggers before you start, such as a safety violation, a quality score below threshold, or a cost spike, and rehearse the rollback.

4.5 Resilience Patterns​

Treat the model as an unreliable remote dependency.

  • Timeouts on every call, set from latency budgets.
  • Retries with exponential backoff and jitter, only for transient failures and idempotent or otherwise safely repeatable operations. Do not blindly retry authorization failures, invalid requests or other permanent errors.
  • Circuit breakers that stop calling a failing target and fail fast to a fallback.
  • Bulkheads that isolate capacity per feature or tenant so one noisy workload cannot starve others.
  • Fallback chains ordered by preference, ending in a degraded mode or human handoff. Each fallback must meet the same data-handling and authorization requirements as the primary path, and its quality limitations should be explicit.
def call_with_fallback(request, chain, timeout_s=8):
last_error = None
for target in chain:
try:
return gateway.invoke(target, request, timeout=timeout_s)
except (TimeoutError, RateLimitError, ProviderError) as err:
last_error = err
metrics.increment("gateway.fallback", tags={"from": target.name})
raise AllTargetsFailed() from last_error

4.6 Latency, Caching and Capacity​

Latency.

  • Stream tokens when the use case permits users to see partial output, and track time to first token separately from total time. For high-risk responses or outputs that must pass validation before display, buffer the response or stream only content that has passed the required checks.
  • Run independent steps (such as multiple retrievals) in parallel.
  • Reduce prompt size, and use provider prefix caching where available for stable prompt prefixes.
  • Use smaller, faster models for sub-tasks such as classification or routing.

Caching.

  • Exact-match caching is straightforward for repeated identical requests, but the cache key must include the relevant authorization and behavior context. Do not reuse a response across users or tenants when their permissions or data differ. Include the relevant release-bundle or artifact versions when a change could make a cached answer stale.
  • Semantic caching returns answers for similar requests but can return a wrong answer for a subtly different question. Use it only where mistakes are cheap, scope it by tenant and authorization context, and tie cache invalidation to changes in policy, prompt, model and index versions.

Capacity.

  • Know your tokens-per-minute and requests-per-minute limits and request quota increases early.
  • Load-test with realistic input and output length distributions, not just request counts.
  • Apply backpressure and priority queues so interactive traffic wins over batch work.

Cost controls. Set budgets per feature and tenant, cap output tokens, route simple requests to cheaper models, and alert on cost per successful outcome rather than on raw spend alone.

4.7 Launch Checklist​

Before moving a feature beyond internal use, confirm each item.

  • Release bundle manifest exists and every request logs the bundle version
  • Quality gates passed with a current evaluation report
  • Safety and red-team suite passed for the risk tier
  • Fallback chain and degraded mode tested
  • Rollback rehearsed for each artifact type
  • Load test completed with realistic token distributions
  • Quotas, budgets and cost alerts configured
  • Dashboards, alerts and an on-call owner in place
  • Data handling reviewed (retention, residency, redaction)
  • System card and risk tier approved

4.8 Chapter Summary​

  • Promote and roll back release bundles, with independent rollback per artifact.
  • Centralize model access in a gateway for abstraction, routing, guardrails, quotas and cost attribution.
  • Roll out in stages with predefined rollback triggers, and build in timeouts, fallbacks and isolation.
  • Manage latency, caching, capacity and cost as engineering concerns from the start.

Exercises

  1. Define a fallback chain for your feature. Confirm that every fallback meets the data-handling and authorization requirements of the primary path.
  2. Define rollback triggers for each stage of the rollout table in Section 4.4.
  3. Design the cache key for an exact-match cache in a multi-tenant deployment. Which versions and which authorization attributes must it include?
  4. Estimate peak tokens per minute for your feature from realistic input and output length distributions. Which quota do you hit first?

Chapter 5. Observe​

In this chapter: what to measure in production, how to define service level objectives for quality, how to detect drift, how to control cost, and how to respond to AI-specific incidents.

5.1 Observe Quality, Not Only Uptime​

Classic monitoring answers “is it up and fast?” AI monitoring must also answer “is it right, safe and affordable?” The three questions map to three signals: quality, latency and cost.

5.2 Trace Every Request​

A trace connects the steps behind one answer. Instrument the pipeline with spans so you can reconstruct what happened.

SpanKey attributes
RequestFeature, bundle version, tenant, user segment, request identifier
Context assemblySources used, token counts per section, truncation applied
RetrievalIndex version, query, number of results, relevance scores
Model callModel and version, parameters, input and output tokens, time to first token, total time, finish reason
Tool callTool, version, arguments (redacted), duration, status
ValidationSchema result, guardrail results, repairs
ResponseFallback used, final status, citations

Standard conventions such as the OpenTelemetry semantic conventions for generative AI help keep traces portable across tools, although they are still evolving, so check the current specification. Link traces to user feedback and evaluation results through shared identifiers.

5.3 Service Level Indicators and Objectives​

Define SLIs for the dimensions users care about, then set SLOs and error budgets, exactly as you would for any service.

DimensionExample SLIExample SLO
AvailabilitySuccessful responses divided by all requests99.9 percent over 30 days
Latencyp95 time to first token and p95 total timeWithin the feature’s latency budget
QualityPass rate on sampled, graded production tracesAt or above the gate threshold
GroundednessShare of sampled answers with fully supported claimsAt or above target
SafetyGuardrail violations per thousand requestsAt or below target; zero for critical classes
EscalationShare of conversations handed to humansWithin an expected range
CostCost per successful outcomeAt or below budget

Quality SLIs rely on continuous sampled evaluation: automatically grade a stratified sample of production traces and route uncertain ones to human review. Error budgets then let you balance release speed against reliability, as in conventional SRE practice.

5.4 Detect Drift​

AI systems drift for reasons that do not appear in your commit history.

Drift typeCauseSignal
Input driftUsers ask different things over timeShifts in topic, language, length distributions
Output driftModel or prompt behavior changesShifts in answer length, refusal rate, format failures
Provider driftHosted model updated behind a stable nameQuality changes with no deploy; pin versions and run scheduled evaluations
Retrieval driftCorpus changes, index stalenessLower relevance scores, falling citation accuracy, stale sources
Concept driftThe world or policy changesPreviously correct answers become wrong

Run the golden set on a schedule against production configuration, not only at release time. A sudden score change without a deploy is a signal to investigate provider, data, configuration or input-distribution drift; it is not proof of a single cause.

5.5 Make Cost Visible​

  • Record input and output tokens and price per call, attributed to feature, tenant, team and bundle version.
  • Track cost per successful outcome, not only cost per request. Retries, long prompts and failures all raise it.
  • Alert on anomalies: sudden growth in prompt length, retry storms, runaway agent loops.
  • Review the top cost drivers monthly and feed them into the Improve stage.

5.6 Protect Privacy in Telemetry​

Prompts and responses can contain personal and confidential data. Redact or hash sensitive fields before storage, apply the minimum retention that supports debugging and evaluation, restrict access by role, separate tenant data, and document what is logged. Sampling full payloads at a low rate while keeping metadata for all requests is a common compromise.

5.7 Alerting and Dashboards​

Alert on symptoms that matter to users: error rate, latency over budget, quality SLI below threshold, safety violation, cost anomaly. Avoid paging on every internal metric. A good dashboard has one view per feature: traffic, latency, error and fallback rates, quality scores by slice, safety signals, cost per outcome, and the active bundle version with a marker for each release.

5.8 AI Incident Response​

Incident typeExampleFirst mitigation
Quality regressionAccuracy drops after an index refreshRoll back the index snapshot or prompt
Safety incidentHarmful or policy-violating output reaches usersTighten guardrails, disable the affected capability, escalate
Data exposureSensitive data appears in output or logsStop the flow, contain, follow the privacy incident process
Cost spikeRetry loop multiplies token useRate limit, circuit break, fix the loop
Provider outageModel endpoint errorsFail over along the fallback chain

A reliable runbook follows these steps: detect, triage by severity, mitigate (roll back an artifact, switch route, degrade, or hand off to humans), diagnose with traces, fix, add the failing case to the evaluation set, and hold a blameless review. The step that adds the failure to the dataset makes recurrence less likely and gives the team evidence that the fix works, although the failure can still return in a different form.

5.9 Chapter Summary​

  • Trace each request across context, retrieval, model, tools and validation.
  • Define SLIs and SLOs for quality, safety and cost, using continuous sampled evaluation.
  • Watch for input, output, provider, retrieval and concept drift, and run scheduled evaluations.
  • Attribute cost per outcome, protect privacy in telemetry, and use an incident process that feeds failures back into the dataset.

Exercises

  1. Define SLIs and SLOs for quality, safety and cost. Specify the sampling rate and the stratification for graded production traces.
  2. List the trace attributes you would need to diagnose an unsupported-claim failure. Which of them need redaction?
  3. The quality SLI drops six points on a Tuesday with no deploy. List your hypotheses in the order you would test them, and name the data that separates them.

Chapter 6. Improve​

In this chapter: how to turn production signals into prioritized fixes, which levers to pull first, how to migrate models safely, and how to manage the technical debt that AI systems accumulate.

6.1 The Improvement Pipeline​

Improvement is a repeatable process.

  1. Collect failures from monitoring, user feedback, sampled review and incidents.
  2. Cluster them by symptom and by slice to find the most frequent and most costly patterns.
  3. Label a representative set and name the root cause.
  4. Fix with the cheapest effective lever.
  5. Regress: add the cases to the evaluation set so the failure cannot return unnoticed.
  6. Verify through the normal gates and rollout, then confirm the metric moved in production.

6.2 Root Cause Taxonomy​

Root causeTypical evidence
Retrieval missRelevant document exists but was not retrieved
Context overflow or truncationNeeded information was cut by the token budget
Prompt ambiguityDifferent phrasings of the same request give inconsistent behavior
Stale or wrong source dataThe model faithfully reproduced outdated content
Model limitationFails with perfect context and clear instructions
Tool failureWrong tool chosen, invalid arguments, or a tool error was ignored
Guardrail false positiveValid requests blocked
Missing requirementThe behavior was never specified

Labeling the root cause avoids the common mistake of trying to fix every failure by editing the prompt.

6.3 Use the Cheapest Effective Lever First​

OrderLeverTypical effortTry when
1Clarify the product behavior or UXLowThe failure is a missing or ambiguous requirement
2Improve the prompt and examplesLowInstructions are unclear or inconsistent
3Improve context and retrievalMediumEvidence is missing, stale or poorly ranked
4Add or fix tools and validatorsMediumThe task needs exact data or checks
5Change or route to a different modelMediumA stronger or cheaper model scores better on your set
6Fine-tuneHighYou need consistent style, format or a smaller model for a narrow, stable task
7Redesign the workflowHighA single call cannot reliably do the task

Fine-tuning is worth considering when you have enough high-quality labeled examples, a stable task and a clear measured gap that prompting and retrieval cannot close. Retrieval is usually the better choice for knowledge that changes often.

6.4 Close the Feedback Loop Responsibly​

Production data is the best source of evaluation cases, but it carries obligations.

  • Get the required consent and legal basis before using user content to improve the system.
  • Minimize and anonymize examples before they enter datasets.
  • Treat feedback as a signal to review, not as ground truth. Users rate fluency as well as correctness, and they rarely rate at all.
  • Track the flywheel: share of production failures converted into regression cases, and time from detection to gate.

6.5 Model Migration Playbook​

Providers retire and replace models, and better models appear regularly. Treat migration as a routine, rehearsed procedure.

  1. Review the provider’s deprecation schedule and set calendar owners.
  2. Run the golden set and safety suite on the candidate model with the current prompt.
  3. Adapt the prompt to the new model if needed, using the development set only.
  4. Compare quality, slices, latency and cost against the baseline, with confidence intervals.
  5. Run in shadow mode on live traffic.
  6. Canary and ramp with rollback ready.
  7. Retire the old model binding, and update the system card and decision record.

Because model access goes through the gateway and evaluation is automated, migration becomes a configuration and evidence exercise, not a rewrite.

6.6 Manage AI-Specific Technical Debt​

Research on production machine learning systems has described several forms of debt that also apply to AI applications.

DebtHow it appearsCountermeasure
EntanglementChanging one prompt, source or threshold changes everything elseComponent boundaries, per-component evaluation, slice reports
Undeclared consumersOther systems depend on outputs that were never contractedTyped interfaces, versioned contracts, consumer registry
Data dependenciesHidden reliance on unstable data sourcesLineage, freshness checks, index snapshots
Configuration debtMany untracked parameters and flagsVersioned config, release bundles
Evaluation debtStale datasets and untrusted gradersDataset ownership, scheduled review, grader calibration
Prompt sprawlMany near-duplicate promptsRegistry, templates, ownership, deprecation
Feedback loopsSystem outputs influence future training or retrieval dataIsolate generated content, monitor for degradation

Schedule recurring time to pay this debt down, because it accumulates quietly.

6.7 Chapter Summary​

  • Convert production failures into labeled, prioritized fixes and permanent regression cases.
  • Pull cheap levers first, and use fine-tuning for narrow, stable gaps that prompting and retrieval cannot close.
  • Make model migration a rehearsed, evidence-based routine.
  • Manage entanglement, configuration, evaluation and prompt debt deliberately.

Exercises

  1. Take 30 recent failures from a system you know. Cluster them, name the root causes using Section 6.2, and choose the cheapest effective lever for each cluster.
  2. Write a migration plan for a model that will be retired in 90 days. Include the evidence you need at each step.
  3. Inventory the AI-specific debt in one of your systems using the table in Section 6.6, and choose the two items to pay down first.

Chapter 7. Operating Model and Governance​

In this chapter: team roles, risk tiers and the controls that go with them, the launch review, documentation, a maturity model, how this guide relates to common frameworks, and how to adopt it across many teams.

7.1 Roles and Responsibilities​

RolePrimary responsibilities
Product ownerDefines the task, success criteria and acceptable risk
AI engineerBuilds components, prompts, context pipelines and tools
Evaluation or quality engineerOwns datasets, graders, gates and evaluation reports
Platform engineerRuns the gateway, serving, CI/CD, observability and cost tooling
SRE or operationsSLOs, on-call, capacity and incident response
Security and privacyThreat models, red-teaming, data handling, approvals
Legal and complianceRegulatory requirements, contracts, user disclosures
Domain expertLabels, rubrics, and review of high-risk outputs

In small teams one person holds several roles. What matters is that each responsibility has a named owner.

7.2 Risk Tiers​

Scale the required evidence and oversight to the potential for harm.

TierTypical useMinimum controls
1: LowInternal drafting aids, low-impact summariesSmoke evaluation, basic monitoring, system card
2: ModerateCustomer-facing answers with human review or bounded impactFull golden set and gates, red-team suite, staged rollout, quality SLOs, launch review
3: HighDecisions affecting money, safety, legal rights or sensitive dataEverything in Tier 2, plus independent review, human approval on actions, stricter slice floors, audit logging, periodic revalidation

Assign the tier in the feature specification (Section 2.1) and revisit it when the feature’s scope or autonomy changes.

7.3 The Launch Review​

A launch review is a short, evidence-based meeting. The team brings the system card, the evaluation report, the red-team results, the rollout and rollback plan, the SLOs and the on-call owner. Reviewers from engineering, security, privacy and the business decide to proceed, proceed with conditions, or stop. Keep it lightweight for Tier 1 and thorough for Tier 3.

7.4 Documentation That Earns Its Keep​

  • System card: purpose, intended and prohibited uses, architecture, data sources, models, risk tier, known limitations, evaluation summary, owners.
  • Prompt and bundle changelog: what changed, why, and the evidence.
  • Decision records: model choice, thresholds, retrieval design, with the data behind them.
  • Runbooks: rollback procedures, incident steps, escalation contacts.
  • Evaluation reports: archived with each release.

7.5 Maturity Model​

LevelDescriptionTypical signs
0: Ad hocPrompts edited in place; manual spot checksNo versioning, no dataset, surprises in production
1: ManagedPrompts and configs in version control; a small golden setManual evaluation before release
2: GatedAutomated evaluation in CI with quality gates; release bundlesStaged rollouts, basic tracing
3: ObservedQuality SLOs, continuous sampled evaluation, drift detection, cost attributionIncident process feeds the dataset
4: OptimizedShared platform and gateway, routine model migration, experimentation, portfolio-level governanceTeams self-serve with consistent controls

Aim to move one level at a time. The highest-value early steps are usually a versioned golden set, an automated gate and basic tracing.

7.6 Relation to Common Frameworks​

This guide is compatible with widely used risk and security frameworks. It is not a substitute for them.

  • The NIST AI Risk Management Framework organizes work into Govern, Map, Measure and Manage. Risk tiers and the launch review support Govern and Map. Evaluation and monitoring support Measure. Rollout, incident response and improvement support Manage.
  • The OWASP Top 10 for LLM Applications catalogs recurring security risks, including prompt injection, sensitive information disclosure, improper output handling and excessive agency. Section 2.8 and the red-team practice in Section 3.9 address these.
  • Regulatory requirements, such as those in the EU AI Act, depend on your use case and jurisdiction. Work with legal counsel to map risk tiers and documentation to your obligations.

7.7 Adopting at Organizational Scale​

When dozens of teams ship AI features, the main risk shifts from any single feature to inconsistency: different teams invent different gates, log different fields, and migrate models on different schedules. A federated model keeps standards common and decisions local.

ConcernOwned centrally (platform and governance)Owned by product teams
Model accessGateway, approved model catalog, quotas, provider contractsChoice of model within the catalog, per-feature routing rules
EvaluationHarness, grader library, report format, minimum gate templates per tierDatasets, slices, rubrics, thresholds, gate results
ReleaseBundle manifest schema, promotion pipeline, rollout toolingBundle contents, rollout plan, rollback triggers
ObservabilityTrace schema, redaction defaults, cost attribution, dashboards templatesFeature SLIs and SLOs, alerts, on-call
Safety and privacyRisk tier definitions, red-team suites, guardrail policy packs, review processThreat model, feature-specific adversarial cases, system card
LifecycleDeprecation calendar, migration drills, shared incident taxonomyExecuting migrations, closing incident actions

Practices that make this work:

  • Provide paved paths. Offer templates, a reference repository and a gateway SDK so that following the standard is the easiest option. Teams adopt standards that save them effort.
  • Standardize interfaces, not internals. Fix the shape of the bundle manifest, trace attributes and evaluation report. Leave prompts, retrieval design and graders to the owning team.
  • Share datasets and graders with owners. A shared adversarial set or a calibrated safety grader should have a named maintainer, a version history and a contribution process, in the style of inner source.
  • Reuse existing governance. Attach the risk tiers and launch review to the launch process the organization already runs. Add AI-specific evidence to it; do not create a second approval path.
  • Measure the platform. Track adoption and outcomes: share of AI features behind the gateway, share with automated gates, median time to complete a model migration, share of incidents converted into regression cases.
  • Plan for coexistence. Teams will use different frameworks and languages. The gateway contract, manifest schema and trace conventions are what must stay stable across them.

7.8 Chapter Summary​

  • Name an owner for every responsibility, even in small teams.
  • Tie evidence and oversight to risk tiers, and make the launch review short and evidence-based.
  • Use the maturity model to prioritize the next improvement, and map the practices to your governance frameworks.
  • At scale, standardize interfaces and platform services centrally, and keep decisions about quality and risk with the teams that own the features.

Exercises

  1. List the responsibilities in Section 7.1 and assign a named owner to each on your team. Which ones have none?
  2. Classify three features in your portfolio into risk tiers. Justify each tier and list the controls that follow.
  3. Place your team on the maturity model. Write the first three steps toward the next level.
  4. Draft the split between central and product-team ownership for your organization, using the table in Section 7.7 as a starting point.

Chapter 8. Putting It Together​

In this chapter: a reference architecture, an end-to-end walkthrough of the Refund Policy Assistant, and a plan for adopting the practices.

8.1 A Simplified Reference Architecture​

The AI Reference Architecture

8.2 Walkthrough: The Refund Policy Assistant​

The following narrative uses illustrative numbers.

Design. The team writes the specification from Section 2.1: suggest-only, risk tier 2, correctness at least 0.90, groundedness at least 0.95, p95 latency within 6 seconds. They define the component with a versioned prompt, a retrieval step over the policy documents with access control, a groundedness validator, and a degraded mode that shows the matching policy passages without a generated answer.

Evaluate. They build a golden set of 120 cases from past tickets, tagged by customer segment, language and exception type, and split it into development and test sets. A model-based grader scores correctness and groundedness and is calibrated against a hand-labeled sample. The gates from Section 3.6 run in CI. On the first full run, correctness has a lower bound of 0.84, below the gate.

Improve (pre-release). Failure labeling shows that most misses are retrieval misses on annual-plan exceptions. The team adjusts chunking so that exceptions stay attached to the parent policy, then re-runs the gates. The lower bound rises to 0.91, and the slice floors pass.

Ship. The release bundle is promoted. A shadow run on live tickets shows no regression in latency or cost. A canary for 5 percent of agents follows, then a ramp to 100 percent. Rollback has been rehearsed for the prompt, the index and the model.

Observe. Dashboards track quality on sampled traces, groundedness, escalation rate, p95 latency and cost per answer. A nightly golden-set run on production configuration detects drift.

Improve (production). Three weeks later, the quality SLI dips after the policy team publishes a new refund rule. Traces show the index is stale for one document set. The team fixes the ingestion schedule, adds the failing cases to the regression set, and adds a freshness check to the nightly job. The next policy change is caught before users see it.

8.3 A 30-60-90 Day Adoption Plan​

First 30 days: establish the basics.

  • Put prompts, configuration and model bindings in version control, and write the feature specification.
  • Build a first golden set of 50 to 100 cases, and calibrate one grader.
  • Add basic tracing with bundle version, token counts and latency.

Days 31 to 60: automate the gates.

  • Run component checks and a smoke evaluation on every pull request.
  • Add quality gates, slice reports and a nightly full run.
  • Introduce release bundles, a fallback chain and a rollback procedure, and rehearse it.

Days 61 to 90: operate with confidence.

  • Define quality, latency and cost SLOs, with continuous sampled evaluation.
  • Stand up or adopt a gateway for model access, quotas and cost attribution.
  • Run a red-team exercise, hold the first launch review, and schedule a model migration drill.

8.4 Common Anti-Patterns​

Anti-patternWhy it hurtsRemedySection
Editing prompts in place in productionNo review, no rollback, no evidenceVersion prompts; promote release bundles2.3, 4.1
Tuning against the test setThe gate no longer measures generalizationSeparate development and test sets3.3
Reporting only averagesSlice-level failures stay hiddenSlice tags, slice floors3.3, 3.6
Uncalibrated model-based judgeScores drift from human judgmentCalibrate, pin judge versions, spot-check3.4
Unpinned model with no scheduled evaluationProvider changes surface as user complaintsPin where possible; run the golden set on a schedule2.3, 5.4
Consuming raw model output downstreamMalformed or hostile output reaches other systemsValidate before use2.2, 2.8
Semantic cache shared across tenantsCross-tenant leakage and stale answersScope by tenant and authorization; version-based invalidation4.6
Alerting on uptime onlyWrong answers go unnoticedQuality, safety and cost SLIs5.3
Quietly loosening a thresholdGates lose meaningTreat thresholds as reviewed, versioned configuration3.6
Model migration as an emergencyRetirement date forces a rushed changeDeprecation calendar and rehearsed playbook6.5

8.5 Chapter Summary​

  • The reference architecture separates the AI component, context assembly, tools, the gateway and the models, with evaluation, release, observability and improvement cutting across all of them.
  • The Refund Policy Assistant shows one full pass through the loop, including a failure caught before release and another caught in production.
  • A 30-60-90 day plan introduces the practices in order of value: versioning and datasets, then automated gates, then operations and SLOs.

Exercises

  1. Write a one-page walkthrough of your own feature through all five stages, using your own numbers.
  2. Adapt the 30-60-90 day plan to your planning cadence. Name an owner for each deliverable.
  3. Review your system against the anti-patterns in Section 8.4. Which three are most costly for you today?

Appendix A. Production Readiness Checklist​

Design

  • Feature specification with numeric success criteria, failure taxonomy, risk tier and autonomy level
  • Typed interface, validators and fallback for each AI component
  • Prompts, models, indexes, tools and policies versioned and combined in release bundles
  • Context budget, access control and trusted versus untrusted content separation defined
  • Threat model completed

Evaluate

  • Golden set with typical, edge, adversarial and regression cases, tagged by slice
  • Development and test sets separated; contamination checks in place
  • Graders calibrated against human labels; judge versions pinned
  • Quality gates (absolute, no-regression, slice, hard-fail, budget) automated in CI
  • Red-team suite run for the risk tier

Ship

  • Model access through a gateway with routing, guardrails, quotas and logging
  • Staged rollout plan with rollback triggers and a rehearsed rollback
  • Timeouts, retries, circuit breakers and fallbacks tested
  • Load test with realistic token distributions; quotas confirmed

Observe

  • End-to-end traces with bundle version and redaction
  • SLIs and SLOs for quality, latency, safety and cost
  • Drift detection and scheduled evaluation on production configuration
  • Cost attributed by feature, tenant and team; anomaly alerts
  • AI incident runbook and on-call owner

Improve and govern

  • Failure triage pipeline feeding the regression set
  • Model migration playbook and deprecation calendar
  • System card, decision records and evaluation reports archived
  • Launch review completed for the risk tier

Appendix B. Mapping to Practices You May Already Run​

Most engineering organizations already have mature practices that correspond to parts of this guide. Use this table to connect the terms.

Concept in this guideTerms you may already use
Release bundleRelease candidate, build manifest, deployment descriptor
Quality gateLaunch criteria, ship criteria, readiness review, promotion check
Evaluation setGolden dataset, benchmark, test suite, holdout set
Slice reportSegment analysis, breakdown by cohort
Shadow modeShadow traffic, dark launch, traffic mirroring
Canary and rampStaged rollout, percentage rollout, progressive delivery
Online evaluationA/B experiment, holdback, interleaving
Guardrail metricsExperiment guardrails, counter-metrics
Quality SLOSLI, SLO and error budget applied to model quality
AI gatewayInference proxy, model router, model-serving frontend
Prompt registryConfiguration service, feature-config store
Risk tierCriticality tier, launch tier, review level
System cardModel card, design document, service documentation
AI incident reviewBlameless postmortem, incident review
Provider drift checkDependency regression test, canary on upstream change

Where the Guide Plugs Into Existing Systems​

Existing systemIntegration pointSections
Source control and code reviewPrompts, bundle manifests and thresholds as reviewed files; code owners for gate configuration2.3, 2.4
CI/CD and build systemsEvaluation suites as test targets; gate results block merge and promotion3.6, 3.7
Feature-flag and configuration servicesBundle selection, rollout stages, kill switches4.4
Experimentation platformOnline evaluation, guardrail metrics, hold-backs3.8
API gateway or service meshAI gateway as a policy layer, or as a module within it4.2
Tracing, metrics and logging stackAI spans, quality and safety SLIs, redaction5.2, 5.3, 5.6
SLO and on-call toolingQuality SLOs, error budgets, AI incident runbook5.3, 5.8
Data platformCorpus lineage, index snapshots, dataset versioning2.5, 3.3
Security and privacy reviewThreat model, red-team suite, telemetry controls2.8, 3.9, 5.6
Launch review processSystem card, evaluation report, rollout plan7.3
Incident management and postmortemsFailing case added to the evaluation set5.8, 6.1
Cost and capacity managementCost attribution by feature, tenant and bundle version4.6, 5.5

Appendix C. Example Platform Mappings​

These are examples of how the concepts can be realized on common platforms. They are not requirements and not an endorsement. Product names and features change, so check current documentation. Many organizations use internal equivalents; the concepts remain the same.

ConceptAWSGoogle CloudMicrosoft AzurePortable or open source
Model accessAmazon BedrockVertex AIAzure AI FoundrySelf-hosted serving such as vLLM
Gateway and routingAmazon API Gateway or a custom proxy in front of BedrockApigee or a custom proxy in front of Vertex AIAzure API ManagementLiteLLM, Envoy-based proxies
GuardrailsAmazon Bedrock GuardrailsModel ArmorAzure AI Content SafetyNeMo Guardrails, in-house policy engines
Retrieval and knowledgeAmazon Bedrock Knowledge Bases, Amazon OpenSearch ServiceVertex AI Search, Vector SearchAzure AI SearchPostgreSQL with pgvector, OpenSearch, Elasticsearch
EvaluationAmazon Bedrock evaluation capabilities plus your own harness in CIVertex AI Gen AI evaluation service plus your own harnessAzure AI Foundry evaluation plus your own harnessYour own harness in CI, open-source evaluation libraries
OrchestrationAWS Step Functions, agent frameworksCloud Workflows, agent frameworksDurable Functions, Logic Apps, agent frameworksTemporal, Airflow, application code
Feature flags and configurationAWS AppConfigInternal flag or configuration serviceAzure App ConfigurationOpenFeature-compatible flag services
TelemetryAmazon CloudWatch, AWS X-RayCloud Monitoring, Cloud TraceAzure Monitor, Application InsightsOpenTelemetry, Prometheus, Grafana
Secrets and access controlAWS Secrets Manager, AWS IAMSecret Manager, Cloud IAMAzure Key Vault, Microsoft Entra IDHashiCorp Vault, OIDC

Appendix D. Glossary​

AI component. A bounded unit of functionality that combines a model, instructions, context and validation behind a typed interface.

AI gateway. A serving layer that centralizes model access, routing, guardrails, quotas, caching and logging.

Autonomy level. What a system may do without a human: suggest, act with approval, or act alone.

Canary release. Exposing a change to a small share of traffic before wider rollout.

Context engineering. The practice of selecting, ordering and budgeting the information supplied to a model.

Degraded mode. A predefined reduced capability that a system falls back to when its primary path fails, such as showing search results without a generated summary.

Drift. A change in inputs, outputs, data or provider behavior that degrades quality without a code change.

Evaluation pyramid. A layered set of evaluations in which cheap, fast checks run often and expensive, realistic checks run before release.

Golden set. A curated, labeled evaluation dataset that represents expected behavior.

Grader. A procedure that converts a model output into a score.

Groundedness. The degree to which claims in an output are supported by the provided evidence.

Guardrail. A policy check applied to inputs or outputs.

LLM-as-judge. Using a language model as a grader.

Quality gate. An automated rule that decides whether a change may proceed.

Release bundle. The set of artifact versions (prompt, model, index, policy, tools, configuration) that together define deployable behavior.

Risk tier. A classification of a feature by potential for harm that determines the evidence, review and oversight required.

Shadow mode. Running a candidate on live traffic without exposing its output to users.

Slice. A subset of cases defined by an attribute such as segment, language or risk.

System card. A document describing a system’s purpose, limits, data, evaluation and owners.


Appendix E. Further Reading​

  • D. Sculley et al., “Hidden Technical Debt in Machine Learning Systems,” Advances in Neural Information Processing Systems, 2015.
  • Eric Breck et al., “The ML Test Score: A Rubric for ML Production Readiness and Technical Debt Reduction,” 2017.
  • Martin Zinkevich, “Rules of Machine Learning: Best Practices for ML Engineering,” Google.
  • Betsy Beyer, Chris Jones, Jennifer Petoff and Niall Richard Murphy (eds.), Site Reliability Engineering, O’Reilly, 2016.
  • Titus Winters, Tom Manshreck and Hyrum Wright, Software Engineering at Google, O’Reilly, 2020.
  • Betsy Beyer, Niall Richard Murphy, David K. Rensin, Kent Kawahara and Stephen Thorne (eds.), The Site Reliability Workbook, O’Reilly, 2018.
  • Jez Humble and David Farley, Continuous Delivery, Addison-Wesley, 2010.
  • Ron Kohavi, Diane Tang and Ya Xu, Trustworthy Online Controlled Experiments, Cambridge University Press, 2020.
  • Chip Huyen, AI Engineering, O’Reilly, 2025.
  • Nicole Forsgren, Jez Humble and Gene Kim, Accelerate, IT Revolution, 2018.
  • Lianmin Zheng et al., “Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena,” 2023.
  • Percy Liang et al., “Holistic Evaluation of Language Models,” 2022.
  • National Institute of Standards and Technology, Artificial Intelligence Risk Management Framework (AI RMF 1.0), 2023.
  • OWASP, Top 10 for Large Language Model Applications.
  • OpenTelemetry, Semantic Conventions for Generative AI (check the current specification).