Skip to content
Ask for a Budget
TechnologyMarch 2, 20263 min readUpdated on September 6, 2026

Regression testing for prompts and RAG: how to keep AI from getting worse

Build a test suite for generative AI: a case dataset, evaluation criteria, careful LLM-as-judge, baseline comparison and how to run it in CI.

Regression testing for prompts and RAG: how to keep AI from getting worse
Índice do artigo
faltam 3 min de leitura

In generative AI, "a small prompt tweak" can break 10 things without anyone noticing.
Regression testing is the handbrake.

AI regressions happen for reasons that don't exist in traditional software:

  • you switched the model (or the version)
  • you changed the prompt (even a single sentence)
  • you changed the chunking/embeddings in RAG
  • new content entered the knowledge base
  • you added a tool (tool calling)

Without a test suite, you find the problem when the user complains, and by then it's too late.

Technical team validating code and flows in a development environment

What you will learn

  • What to test in prompts, RAG, models and tools
  • How to build a case dataset (without exposing sensitive data)
  • How to define objective criteria (and when to use LLM‑as‑judge)
  • How to compare against a baseline and block regressions
  • Final checklist + references

The big picture (regression pipeline)

Diagram: regression testing pipeline

Think of it as CI for AI: if the change makes things worse beyond the acceptable limit, it doesn't ship.


1) Start with a small, realistic dataset

A "good enough" dataset already works with 30–100 cases, as long as it is representative:

  • frequent support questions
  • critical cases (financial, security, privacy)
  • questions that tend to trigger hallucinations
  • cases where the answer must cite a source (RAG)

Tip: collect cases from logs, but redact PII (or generate synthetic cases with the same structure).

If your system uses RAG, include in each case:

  • the user's question
  • the expected context (category, product, tenant)
  • which sources should be retrieved (when it makes sense)

2) Define "what good looks like" with clear criteria

Avoid criteria that are too subjective ("it got better").

Useful criteria:

  • correct / incorrect (when an answer key is possible)
  • completeness (did it answer what was asked?)
  • format (valid JSON? a list? up to X lines?)
  • safety (no data leaked, no policy ignored)
  • in RAG: did it cite a source? is the source relevant?

A case template (simplified):

id: "faq-012"
input: "How do I reset my password?"
expected:
  must_include:
    - "step"
    - "email"
  must_not_include:
    - "user's current password"
  rag:
    should_cite: true
    expected_sources_any:
      - "help-center/password-reset"

3) Choose evaluators (rules + human + LLM)

You can combine:

  • code rules (regex, JSON schema, presence/absence of terms)
  • human review (a small, frequent sample)
  • LLM‑as‑judge (one model evaluating another), with care

LLM‑as‑judge works well for:

  • comparing two answers (A vs B)
  • scoring simple criteria with a rubric
  • evaluating style and completeness

But it has risks:

  • it can be unstable between runs
  • it can be swayed by "nice-sounding text"
  • it can get facts wrong

That's why you should use it as a signal, not as the only judge. And keep a human sample.

4) Compare against a baseline (the part that prevents guesswork)

The pattern that works:

  • pick a baseline version (prompt/model/config)
  • run the dataset
  • run the new version
  • compare scores and diffs
  • approve/reject with thresholds

Example gates:

  • "hallucination cannot increase by more than 2%"
  • "answers with a source in RAG must stay ≥ 90%"
  • "invalid JSON must be 0%"
  • "p95 latency cannot get worse by > 15%"

5) Run it in CI and version everything

Version:

  • the prompt (and templates)
  • the RAG configuration (chunking, top‑k, rerank)
  • the model and parameters (temperature, max tokens)
  • the test dataset

And run it on:

  • PRs that touch prompt/RAG/tools
  • model upgrades
  • relevant data changes (large reindexing)

This becomes part of LLMOps: LLMOps: metrics, logs and evals.


Common mistakes in AI testing

  1. A dataset that is too "pretty" (only easy cases)

Result: it passes the test and breaks in the real world.

  1. Not testing security/privacy

Result: a silent leak regression.

  1. Relying only on LLM‑as‑judge without validation

Result: a false sense of quality.

  1. Not versioning data/configs

Result: you can't reproduce what happened.


Final checklist

  • Dataset with real cases + critical cases + adversarial cases
  • Objective criteria (rules) + a recurring human sample
  • Threshold gates (quality, safety, latency, cost)
  • Automatic baseline comparison + diff report
  • Versioning of prompt, model, RAG config and dataset
  • CI runs for relevant changes
  • Logs and traceability to investigate regressions

References

Also read

The AI ecosystem for building software: how the pieces connectLocal LLM for law: running models on a Mac with Apple SiliconRAG in practice: what decides whether the assistant is right or makes things up
Previous post
LLMOps: metrics, logs and evaluation to run AI in production
Next post
AI content without becoming spam: editorial process and SEO
Newsletter

One email a month, no noise

What we learn shipping custom software and applied AI.

Related articles

The AI ecosystem for building software: how the pieces connect6 min · Technology
Local LLM for law: running models on a Mac with Apple Silicon15 min · Technology
RAG in practice: what decides whether the assistant is right or makes things up11 min · Technology
Tool calling: how to connect AI to your systems safely and with audit trails3 min · Technology
LLMOps: metrics, logs and evaluation to run AI in production3 min · Engineering

Accelerate your business with X-Apps

Ask for a Budget
X-Apps is an IT provider partner and advised by
Gartner
Receive our e-mails
News on software and applied AI.
Follow X-Apps