Evaluating LLM Changes With Immutable Golden Datasets & Regression Gates
Why 'eyeballing' prompt changes fails in production, and how to automate regression evaluation in CI/CD pipelines.
Core Takeaway
When updating system prompts or switching to smaller, cheaper LLMs, developers frequently test 2 or 3 sample prompts locally and assume the change is safe. In production, this causes subtle regressions: JSON schema validation errors, edge-case safety failures, and latency spikes. This note covers how to design immutable golden test datasets and automated CI gates.
Problem Statement & Context
Unlike traditional software where unit tests verify deterministic functions, LLMs produce non-deterministic completions with probabilistic variance. Modifying a system prompt to fix one formatting quirk often degrades performance on another unseen edge case. Without an automated regression pipeline, model updates carry high risk.
Architectural Concepts & Implementation
1. Curating Versioned Golden Datasets
A golden dataset is an immutable collection of curated inputs paired with strict validation criteria. Include three distinct input buckets: 1) Happy-path representative user queries; 2) Adversarial and edge-case queries (malformed JSON, injection attempts, extreme lengths); and 3) Historical production bugs.
{
"id": "tc_travel_budget_edge_04",
"version": "1.2.0",
"input": {
"destination": "Kyoto, Japan",
"days": 4,
"budget": "strict_budget_50_usd_per_day"
},
"expectedCriteria": {
"requiredJsonKeys": ["neighborhoods", "dailySchedules", "estimatedCostUsd"],
"costUpperLimit": 200,
"forbiddenWords": ["luxury", "five-star", "michelin-star"],
"maxLatencyMs": 3500,
"maxPromptTokens": 800
}
}2. Deterministic Checks vs. LLM-as-a-Judge
Evaluate candidate model outputs in a two-stage filter: first execute free, deterministic code checks (Zod / Pydantic schema validation, regex matching, numerical range checks). Only pass surviving candidates to an LLM-as-a-Judge for semantic tone and nuance evaluation. This keeps benchmark costs low and results reproducible.
export async function evaluateCandidateOutput(
output: string,
testCase: TestCase
): Promise<EvaluationResult> {
// Stage 1: Deterministic Schema Validation
let parsedJson: unknown;
try {
parsedJson = JSON.parse(output);
} catch {
return { passed: false, stage: 'schema', reason: 'Output is not valid JSON' };
}
const schemaValidation = MyOutputSchema.safeParse(parsedJson);
if (!schemaValidation.success) {
return {
passed: false,
stage: 'schema',
reason: schemaValidation.error.issues.map(i => i.message).join('; ')
};
}
// Stage 2: Business Rule Constraints
if (parsedJson.estimatedCostUsd > testCase.expectedCriteria.costUpperLimit) {
return { passed: false, stage: 'constraints', reason: 'Budget limit exceeded' };
}
return { passed: true, stage: 'complete' };
}3. Establishing Statistical CI Regression Gates
Because temperature causes slight variations across runs, single-test assertions can generate false failures. Run candidate benchmarks with temperature=0.0 for deterministic baseline tests, and enforce aggregate thresholds in CI (e.g., Schema Adherence must be 100%, Semantic Accuracy >= 95%, p95 Latency must not increase by > 15%).
Common Pitfalls & Trade-offs
- !Pitfall: Benchmarking against live dynamic third-party APIs. Always mock external tool calls (weather, search) during LLM evaluation runs so failures reflect model changes, not third-party downtime.
- !Pitfall: Contaminated evaluation data. Ensure test prompts reflect real end-user phrasing, not artificial prompts written by the engineer who wrote the prompt.
- !Trade-off: Evaluation execution time in CI. Running 200 test cases sequentially takes minutes. Use worker pools with concurrency limits to run evaluations in parallel within 30-45 seconds.
Production Verification Checklist
- Store golden datasets in version control immutably (bump version tag on changes).
- Run deterministic schema validation prior to running any LLM judges.
- Track latency and token expenditure as first-class regression dimensions.
- Mock all external tool integrations for reproducible evaluations.
- Block CI pull request merges automatically if schema adherence drops below 100%.