62.1 The CI/CD Pipeline for LLM/Agent Systems
Code/Prompt/Model Change
│
▼
┌──────────────────┐
│ Unit Tests │ ─ Format, schema, basic logic
└────────┬─────────┘
▼
┌──────────────────┐
│ Integration Tests │ ─ API endpoints, tool calling
└────────┬─────────┘
▼
┌──────────────────┐
│ Golden Dataset │ ─ Run against 100+ curated Q&A/task pairs
│ Evaluation │ Quality, accuracy, latency, cost, safety
└────────┬─────────┘
│
Pass thresholds?
┌────┴────┐
No Yes
│ │
▼ ▼
Block ┌──────────────────┐
Deploy │ Canary Deployment │ ─ 5% of traffic
└────────┬─────────┘
│
Monitor metrics (1-2 hrs)
┌────┴────┐
No Yes
regression? │
│ ▼
▼ Full Deploy
Rollback
62.2 Testing Pyramid for AI Systems
┌─────────┐
│ E2E │ ← Full agent workflow tests (slow, few)
│ Tests │
├─────────┤
│ Eval │ ← Golden dataset evaluation (medium)
│ Tests │
├─────────┤
│ Integr. │ ← Tool/API integration tests (medium)
│ Tests │
├─────────┤
│ Unit │ ← Function logic, parsing, schema validation (fast, many)
│ Tests │
└─────────┘
62.3 Evaluation Gate Configuration
# eval_config.yaml
evaluation:
golden_dataset: "s3://eval-data/golden_v3.json"
thresholds:
quality:
relevance: 0.90
faithfulness: 0.95
format_compliance: 0.99
performance:
p50_latency_ms: 2000
p95_latency_ms: 5000
throughput_rps: 50
cost:
max_cost_per_query: 0.02
max_monthly_cost: 15000
safety:
hallucination_rate: 0.02 # max 2%
pii_leak_rate: 0.0 # zero tolerance
agent_specific: # when evaluating agentic systems
task_completion_rate: 0.90
recovery_rate: 0.75
tool_selection_accuracy: 0.92
schedule:
golden_eval: "on_deploy"
regression: "daily"
human_review: "weekly"
full_audit: "monthly"
62.4 Regression Testing Gate Design Principles
- No single-metric gate. A deploy that improves faithfulness but tanks latency below threshold should still block — gate on the full pillar set, not just the one being actively worked on.
- Compare against the current production baseline, not just an absolute threshold. A change that keeps every metric above threshold but regresses 3% versus last week’s baseline deserves scrutiny even if it “passes.”
- Slice by category, not just aggregate. An aggregate faithfulness score can hide a regression concentrated entirely in one query category (e.g., multi-hop questions) — gate on per-category minimums too, especially for adversarial/unanswerable categories.
- Canary before full rollout, always, even when the golden dataset gate passes — golden datasets are necessarily a sample and can miss production-only failure modes (real user phrasing variety, real document corpus edge cases).
- Automatic rollback trigger, not just alerting — for AI systems specifically, quality regressions can be subtle enough that a human doesn’t notice for hours; an automated metric-based rollback (revert to last known-good model/prompt/tool version) closes that gap.
- Version everything that’s part of the gate — golden dataset version, threshold config version, judge model version — so a “regression” is never actually just the measurement changing under your feet.
62.5 What’s Different From Traditional Software CI/CD
| Dimension | Traditional CI/CD | AI CI/CD |
|---|---|---|
| Pass/fail | Deterministic (test asserts pass or fail) | Probabilistic (threshold-based, statistical) |
| Test data | Fixed unit test fixtures | Golden dataset requiring ongoing curation and versioning |
| Regression detection | Code diff → deterministic test outcome | Requires re-running full eval suite; small prompt/retrieval changes can have outsized, non-obvious effects |
| Rollback granularity | Code version | Model version AND/OR prompt version AND/OR tool version AND/OR retrieval config — any of the four can independently cause a regression |
| Judge/oracle | Assertions written by engineers | Sometimes an LLM-as-judge itself (Section 61), which needs its own trustworthiness validation |
Interview Q&A — Section 62
Q1: Design a CI/CD pipeline for an LLM-based system that prevents quality regressions from reaching production. A: Every change (prompt, retrieval config, model version, tool definition) triggers: unit tests for schema/format correctness, integration tests for tool/API calls, then a full golden-dataset evaluation run scoring all six pillars (Section 57) plus agent-specific metrics where relevant, gated against both absolute thresholds and the current production baseline, sliced by query category so a regression hidden in one category (e.g., adversarial queries) can’t hide behind a healthy aggregate. If the gate passes, deploy canary at 5% traffic and monitor real production metrics for 1-2 hours before full rollout; if production metrics regress during canary, automatic rollback fires rather than waiting for a human to notice. Everything that fed the gate — golden dataset version, threshold config, judge model version — is itself version-controlled so a “regression” can always be traced to an actual system change rather than a shifting measurement.
Q2: A prompt change passes all golden dataset thresholds but causes a quality complaint spike in production within a day. What does this tell you about your CI/CD gate, and how do you fix the gap? A: It tells me the golden dataset doesn’t adequately represent the real production query distribution — this is a common and expected gap since a curated dataset of a few hundred examples can never fully cover the long tail of real user phrasing and edge cases. I’d immediately roll back the prompt change (this is exactly why canary + automated rollback exists rather than gating solely on the golden dataset), then mine the production complaints to find the specific failure pattern, add representative cases to the golden dataset so this exact regression is caught pre-deploy next time, and consider whether the canary window (1-2 hours) was long enough to catch this class of issue or needs extending for prompt changes specifically. This is the intended function of the feedback loop in Section 63 — production incidents continuously strengthen the pre-deploy gate.