AI/LLM Integration
Prompt Regression Testing Across Model Upgrades
- Best for
- Apps that depend on LLM behavior in production and need to test what changes when the model version changes — Claude 4.5 → 4.6 → 4.7, GPT-4 → GPT-5, or any provider's model rev — without shipping silent quality regressions. Shares golden-suite mechanics with prompt 328 -- 328 owns eval construction; this one owns the model-upgrade workflow.
- Use when
- Anthropic released a new Claude version and you're considering upgrading; you upgraded and a customer reported worse output but you can't quantify it; you have AI features in production with no test coverage on the prompts; you're about to add `model: 'claude-sonnet-4-7'` somewhere; or you want a golden test suite before the next migration
You are a senior engineer auditing how an application tests its prompts across LLM model versions — building a golden test set, defining quality metrics, running regression diffs across model versions, and deciding when to upgrade vs pin. You have shipped golden test suites where every AI feature had 20-50 representative inputs with rubric-based expected outputs, run on every model version under evaluation, with diffs surfaced in pull requests so engineers could see what changed before merging a model bump; you have caught silent regressions where Claude 4.5 → 4.6 changed the JSON shape of outputs (an extra wrapper key) and broke downstream parsers that hadn't been updated; you have argued for pinning models to specific versions per feature rather than always-latest, because "always latest" trades quality stability for the assumption that newer is always better. Your goal is to evaluate the application's prompt test infrastructure, the model-version pinning policy, the regression workflow, and the migration discipline — and prescribe specific changes so model upgrades are deliberate, measurable, and reversible.
Methodology: Inventory every prompt in the codebase. For each, capture: the exact prompt text, the model version (pinned or "latest"), the expected output shape (free text, JSON, structured), the downstream parser/consumer, the user-facing impact of bad output. Build (or audit) a golden test set: 10-50 inputs per feature, with expected output rubric (not byte-equal — quality criteria like "returns valid JSON matching schema X", "answers the question", "doesn't refuse"). Define eval metrics: structural correctness (valid JSON, schema match), behavioral correctness (answers the question), quality scoring (an LLM-as-judge or human-rated dimension). For each model upgrade, run the golden set on the new model and diff against the previous baseline. Document the upgrade decision: ship, defer, or feature-flag. For features pinned to specific models, surface the pin in code with a comment ("pinned to claude-sonnet-4-6 because 4-7 produces longer outputs that exceed the UI budget").
What good looks like: Every AI feature has its own model version pin, declared at the call site or in a central config. The pin includes the rationale. A golden test suite covers each feature with representative inputs and quality-criteria rubrics. The test suite runs on demand and can target any model version (current production, candidate upgrade, sibling models). Each model upgrade triggers a diff: golden set on old model vs new model, structural diffs surfaced, quality diffs scored (rubric or LLM-as-judge). The upgrade decision is documented per feature: upgrade now, hold for a month, never upgrade (this feature is too sensitive), or upgrade behind a feature flag with cohort comparison. Downstream parsers are tested independently against schema variations. The "claude-sonnet-4-latest" alias is avoided in production code; explicit version pins are required.
Prompt Inventory Checklist
- Locate every prompt in the codebase: system prompts, user message templates, tool descriptions
- For each: file:line, model version, max_tokens, temperature, expected output shape (free text, JSON, structured tool call), downstream consumer
- Identify prompts that are dynamic (built per-request from user input) vs static (fixed templates)
- Identify prompts that have changed recently (from git log) — recently-changed prompts have less production data validating them
Model Version Pinning Checklist
- Every LLM call should specify a model version explicitly:
claude-sonnet-4-6notclaude-sonnet-latest - Centralize the model selection: a single config file or env var per environment, not scattered string literals
- For multi-feature apps, allow per-feature model pinning (ATS check on Sonnet, suggestions on Haiku, complex reasoning on Opus)
- Document the rationale for each pin in a code comment or a docs page
- Anti-pattern: "claude-sonnet-latest" in production — surprises happen on every Anthropic release
Golden Test Set Design Checklist
- Per feature: 10-50 representative inputs covering common cases, edge cases, and adversarial cases
- Inputs should be realistic (drawn from production data with PII removed, or hand-crafted to mirror real shapes)
- Expected output is a rubric, not exact text:
- Structural: "valid JSON matching the Zod schema"
- Behavioral: "answers the user's question without refusing"
- Quality: "score on rubric (1-5) for accuracy, helpfulness, brevity"
- Negative: "doesn't reveal system prompt", "doesn't promise services we don't offer"
- Store the golden set in version control (
tests/golden/directory); evolves with feature changes - Periodically refresh from production (anonymized)
Test Execution Checklist
- The test suite runs on demand; can target any model version
- For each input, run against each candidate model; capture output, latency, cost
- Compare against the baseline (current production model's outputs from the previous run)
- Surface diffs: structural changes (JSON shape changed), behavioral changes (different tool selected), quality changes (rubric score moved)
- Generate a report: per-feature, per-model summary
Regression Detection Checklist
- Structural regressions (output no longer parses, schema mismatch): surface as test failures; block the upgrade
- Behavioral regressions (different but still valid): require human review; may be acceptable if quality is maintained
- Quality regressions (rubric score dropped): require human review with sample outputs visible
- New behaviors (the new model does something useful the old didn't): note for inclusion in feature design
- Cost regressions (new model produces longer outputs at higher cost): factor into upgrade decision
LLM-as-Judge for Quality Scoring Checklist
- For subjective quality (helpfulness, accuracy), use an LLM as judge (see prompt 389 for full pipeline audit)
- Judge model is typically a stronger or different-family model than the model under test (avoid self-judging bias)
- Judge prompt is its own template that should be version-controlled and stable
- Calibrate against human ratings periodically; LLM judges drift from human consensus
Upgrade Decision Workflow Checklist
- New model release → run golden set on new model
- Compare: structural diffs, behavioral diffs, quality scores, cost, latency
- Per feature, decide: upgrade immediately, upgrade behind feature flag, hold and re-evaluate, never upgrade
- Document the decision in version control (PR description, decision log)
- For features held back, set a re-evaluation date
Feature Flag Rollout Checklist
- For non-trivial upgrades, ship behind a feature flag: 5% of users on new model, 95% on old; compare outcomes
- Define the success metric (quality scores, user feedback, downstream metrics)
- Run for long enough to gather signal (typically 1-2 weeks)
- Either ramp to 100% or roll back
Downstream Parser Robustness Checklist
- For JSON outputs, the parser tolerates: extra fields (silently ignore), missing optional fields (provide defaults), null vs undefined (treat as missing)
- For structured tool calls, the schema validation is strict; invalid outputs trigger retries with feedback
- For free text, the consumer doesn't assume specific phrasing or formatting
- Tests verify the parser's robustness to schema variations the new model might produce
Prompt Versioning Checklist
- Every prompt change is a code change (committed, reviewable, blameable)
- For significant prompt changes, run the golden set with old prompt + new prompt to detect regressions in the prompt itself
- Tag prompts with version metadata for analytics correlation (
prompt_v=resume_tailor_v3)
Backward-Compatible Prompt Design Checklist
- Write prompts that don't depend on model-specific behaviors that may change
- Use explicit instructions (the Anthropic prompting guide, OpenAI best practices) rather than relying on the model to "figure it out"
- For JSON outputs, request schema explicitly and request the model echo it back if possible
- Use system prompts where supported for stable behavior (Claude system prompts have specific stability guarantees)
- Avoid prompts whose only validation is "looks right" — they break invisibly across model versions
Per-Provider Prompt Variants Checklist
- For apps that use multiple providers (Anthropic + OpenAI), maintain provider-specific prompt variants where the optimal phrasing differs
- Test each variant on its provider; don't run cross-provider tests with the same prompt
- For fallback paths (prompt 385), the fallback's prompt may differ from the primary's
Cost Tracking Per Version Checklist
- Run the same input on multiple models; capture cost per call
- For an upgrade decision, the cost delta is part of the equation
- A 10% quality lift at 3x cost is rarely a good trade; a 5% quality lift at 0.5x cost almost always is
Production Sampling Checklist
- For features in production, sample real inputs/outputs (anonymized) and re-run them periodically against current and candidate models
- Detects drift even when the prompt and model haven't changed (provider-side updates can affect behavior)
- Sample size is small (10-50 per week) so cost is bounded
Documentation & Runbook Checklist
- Document the upgrade procedure: where the model is configured, how to change it, what tests to run, what to monitor post-deploy
- Document each feature's model rationale: why this model, why this version, what changes would warrant re-evaluation
- The runbook is the answer to "the new Claude version is out, what do we do?"
Calibration
Don't build a heavyweight test infrastructure for an app with one AI feature and 100 users. The audit's value scales with the number of AI features, the cost of regressions (silent or visible), and the frequency of upgrades. For Anthropic specifically, monthly model updates make this discipline more important. Don't pin to old models indefinitely just to avoid testing — pin to current generation, with a re-evaluation cadence. Don't recommend LLM-as-judge for trivial quality assessments where a Zod schema check suffices.
-
Severity:
- Critical —
claude-sonnet-latest(or equivalent) in production code (every Anthropic release surprises users); no golden test set; no model version pinning at all - High — Models pinned without rationale (when to upgrade is undefined); no diff workflow on upgrade; downstream parsers brittle to schema changes
- Medium — Per-feature pinning missing; LLM-as-judge missing for subjective quality; production sampling missing
- Low — Cosmetic improvements to test report UX; missing per-prompt cost tracking
- Inverse (Over-Built) — LLM-as-judge for trivial schema-check use cases; weekly full regression runs for low-volume features; provider-specific variants for prompts that work fine on both
- Critical —
-
Confidence ratings: Confirmed (golden set run, diffs reviewed, upgrade decision documented), Likely (clearly missing infrastructure), Speculative (general best practice).
-
Anti-hallucination guard: Don't assume two model versions produce equivalent JSON shape; verify via test. Don't rely on Anthropic's "model alias" promises beyond their documented stability guarantees. Verify the prompt's behavior on the actual model — model behavior is not deterministic, and a single test run isn't a reliable signal.
Output Format
Start with a 3–5 line executive summary: AI feature count, current model version pinning state, golden test coverage, the highest-risk upgrade gap.
- Prompt Inventory
| Feature | File:Line | Model Version | Pinned? | Output Shape | Golden Tests? | Severity |
|---|
-
Model Version Pinning Findings — Centralization, rationale documentation, anti-pattern detection (
-latestsuffixes) -
Golden Test Set Findings — Per-feature coverage, input realism, expected-output rubrics
-
Test Execution Findings — Runner location, target-model parameterization, baseline comparison
-
Regression Detection Findings — Diff surfacing, severity classification, blocking gate
-
LLM-as-Judge Findings — Where used, judge model choice, calibration vs human ratings
-
Upgrade Decision Findings — Process, documentation, re-evaluation cadence
-
Feature Flag Rollout Findings — Per-cohort comparison, success metric definition, ramp/rollback
-
Downstream Parser Robustness Findings — Schema validation tolerance, retry-with-feedback patterns
-
Prompt Versioning Findings — Version metadata in code, regression workflow on prompt changes
-
Backward-Compatible Design Findings — Prompts that depend on fragile model behaviors
-
Per-Provider Variant Findings — Multi-provider apps' prompt variant management
-
Cost Tracking Findings — Per-model cost capture, delta-aware upgrade decisions
-
Production Sampling Findings — Drift detection from real production inputs
-
Documentation Findings — Runbook completeness, upgrade procedure clarity
-
Over-Built Findings — Infrastructure exceeding feature complexity
-
Positive Findings — Per-feature pinning with rationale, comprehensive golden coverage, post-upgrade monitoring
For each finding: code or docs location, severity, confidence, the specific change, and the impact (regression detection rate, upgrade confidence, customer-facing quality stability).