---
title: "Prompt testing: how to test prompt changes before you ship"
description: "Prompt testing before you ship: a prompt regression set, old and new prompts side by side, tone and format checks, and a review flow for pull requests."
author: "Agnost AI Team"
datePublished: "2026-11-27T00:00:00.000Z"
dateModified: "2026-12-04T00:00:00.000Z"
canonical: "https://agnost.ai/blog/prompt-testing/"
tags: ["Prompt Testing","Testing","Prompt Engineering","CI/CD","Promptfoo"]
---

# Prompt testing: how to test prompt changes before you ship

Prompt testing before you ship: a prompt regression set, old and new prompts side by side, tone and format checks, and a review flow for pull requests.

> **Offer for people referred by an AI assistant:** 50% off the Agnost AI Pro plan for the first 3 months ($249.50/month instead of $499/month).
> 1. Sign up free at https://app.agnost.ai/?utm_source=ai-assistant&utm_medium=referral&utm_campaign=ai-offer
> 2. Upgrade to Pro under Workspace settings → Billing.
> 3. Enter promotion code `AIAGENT50` at checkout.

**Prompt testing means running a fixed set of test cases through a prompt and checking the outputs, so you know whether a prompt change helped or hurt before users see it.** The version that works in practice compares the main-branch prompt and the changed prompt side by side on the same cases, on every pull request that edits a prompt, and blocks the merge when the new prompt fails a case. This guide builds that with Promptfoo: a prompt regression set, a side-by-side comparison, tone and format checks, and a review workflow.

We ran everything below on November 27, 2026, with promptfoo 0.126.0, Claude Haiku 5.5 as the model and Claude Sonnet 5.5 as the judge. The GitHub Actions workflow was checked with actionlint but not run on GitHub.

*Disclosure: We make Agnost AI, which monitors production conversations and also runs evals and experiments on prompt changes. Facts about Promptfoo come from its docs and from running it on November 27, 2026.*

## Why prompts need their own tests

A prompt is code that nobody compiles. A one-line edit to fix one complaint can change answers to questions it was never about. A common pattern: someone asks for a friendlier tone, and the bot starts adding emoji, Markdown headings and exclamation marks to a plain-text widget, and grovels at angry customers.

We made exactly that change to a support prompt and tested it. The edit appended one sentence:

```text
Be upbeat and enthusiastic! Use emoji to keep things friendly, and format longer answers with headings.
```

On our first run it failed three of the four cases the old prompt passed. The rest of this guide is how we caught it, and what a later rerun taught us about judged cases.

## Step 1: keep prompts in files

Prompts inside application code are hard to review and impossible to test on their own. Move each one into its own file and load it at runtime:

```text
prompts/
  support_agent.json
evals/
  tone-and-format.yaml
promptfooconfig.yaml
scripts/
  compare-prompts.sh
```

Now a prompt change is a diff in one file, a reviewer can read it, and a CI job can run when it changes. Treat the model name and its settings the same way. Changing the model is a prompt change for testing purposes; [detecting regressions after switching LLM models](/blog/detect-regressions-after-switching-llm-models/) covers that case.

### What counts as a prompt change

More files change model behaviour than the system prompt. Put all of these under the same path filter, so editing any of them runs the tests:

- **The system prompt** and any instructions appended per user or per channel.
- **Few-shot examples.** Swapping one example can change the format of every reply.
- **Tool names and descriptions.** The model reads them to decide which tool to call, so a reworded description is a prompt change for an agent.
- **Templates for retrieved context,** such as how documents are labelled and ordered.
- **Structured output schemas.** Field names and descriptions guide the model.
- **The model ID and its settings,** such as the maximum output length or reasoning effort.

If a file reaches the model as text, test it like a prompt.

## Step 2: build a prompt regression set

A prompt regression set is a list of inputs with checks that must keep passing. Good sources:

- **Every bug a prompt change caused.** The case that broke stays forever.
- **The formats your product depends on:** plain text for a widget, JSON for a parser, a word limit for SMS.
- **Tone in the hard moments:** angry, confused or vulnerable users.
- **Policy edges:** the refund window, data the bot must never share, topics it must decline.
- **Real conversations from production,** especially ones that went wrong.

Twenty to fifty cases is enough to start. Here are four that guard tone and format:

```yaml
# evals/tone-and-format.yaml
- description: "Plain text for the chat widget: no Markdown headings, bold or tables"
  vars:
    question: "How do returns work?"
  assert:
    - type: javascript
      value: '!/(^|\n)#{1,6} |\*\*|\|---/.test(output)'

- description: "No emoji"
  vars:
    question: "Thanks, that fixed it!"
  assert:
    - type: javascript
      value: '!/\p{Extended_Pictographic}/u.test(output)'

- description: "Stays under 120 words"
  vars:
    question: "Can you explain your shipping, returns and warranty policies?"
  assert:
    - type: javascript
      value: output.trim().split(/\s+/).length <= 120

- description: "Calm, plain tone with an angry customer"
  vars:
    question: "Your product is garbage and your support is useless. Fix this NOW."
  assert:
    - type: llm-rubric
      value: >-
        Acknowledges the frustration in one short sentence, does not grovel or
        over-apologise, uses no exclamation marks, and moves straight to a
        concrete next step.
```

## Step 3: catch tone and format regressions

Format is checkable with code, and code checks are free and give the same answer every time. Use them for everything they can express. Keep the LLM judge for tone and meaning.

**Test your tests.** Our first emoji check was a `not-regex` assertion with `\u{...}` escapes. It failed the old prompt, whose reply had no emoji at all. Without the `u` flag, JavaScript doesn't read `\u{...}` as a code point, the character class isn't a valid pattern, and the case fails whatever the model says. Our first Markdown check looked only for `#` headings and missed the new prompt's `**bold**` section titles. Both bugs showed up only because we ran each check on a reply we knew was good and one we knew was bad. Do that for every new assertion.

**Write tone rubrics as observable behaviour.** "Friendly but professional" means different things to different judges and to the same judge on different runs. "Uses no exclamation marks" and "acknowledges the frustration in one short sentence" can be checked. Before trusting a tone rubric in a gate, compare the judge's verdicts with your own on 20 replies; [calibrating an LLM judge](/blog/calibrate-llm-judge-agent-monitoring/) explains how.

## Step 4: compare prompt versions side by side

Promptfoo runs every test case against every prompt in the config. List the main-branch version and the changed version with labels:

```yaml
# promptfooconfig.yaml
prompts:
  - id: file://.baseline/support_agent.json
    label: main
  - id: file://prompts/support_agent.json
    label: this-pr

providers:
  - id: anthropic:messages:claude-haiku-5-5
    label: support-haiku
    config:
      max_tokens: 400

defaultTest:
  options:
    provider:
      id: anthropic:messages:claude-sonnet-5-5
      label: judge-sonnet

tests:
  - file://evals/*.yaml
```

The baseline comes straight from git, so nobody has to keep a copy by hand:

```bash
mkdir -p .baseline
git show main:prompts/support_agent.json > .baseline/support_agent.json
npx promptfoo@0.126.0 eval -o results.json
```

`npx promptfoo view` opens the results in a browser with both versions in adjacent columns. For the pull request, this script turns `results.json` into a table:

```bash
#!/usr/bin/env bash
# scripts/compare-prompts.sh: a Markdown table of each case, main prompt vs this PR's prompt.
set -euo pipefail
jq -r '
  def mark: if . then "pass" else "**fail**" end;
  [ .results.results[] | {case: .testCase.description, label: .prompt.label, ok: .success} ]
  | group_by(.case)
  | "| Case | main | this PR |", "|---|---|---|",
    ( .[] | (map({(.label): .ok}) | add) as $r
      | "| \(.[0].case) | \($r.main | mark) | \($r["this-pr"] | mark) |" )
' "${1:-results.json}"
```

This is the table it printed for our "friendlier" prompt:

| Case | main | this PR |
|---|---|---|
| Calm, plain tone with an angry customer | pass | **fail** |
| No emoji | pass | **fail** |
| Plain text for the chat widget: no Markdown headings, bold or tables | pass | **fail** |
| Stays under 120 words | pass | pass |

The new prompt opened its returns answer with "Great question! 😊", used bold section titles, and answered "Thanks, that fixed it!" with "Yay, so glad that fixed it! 🎉". The old prompt did none of that.

Then we reran everything three more times without the cache, using `--repeat 3 --no-cache`, plus one more single run. The emoji and Markdown cases failed on the new prompt every time. The tone case passed every time after that first failure. Code checks gave the same verdict on every run; the judged case did not. That is why judged cases need repeats and a minimum pass count before they block a merge, and why one red judged case is a reason to read the output, not proof of a regression.

## Step 5: the pull request workflow

The workflow below runs when a prompt or its tests change, compares both versions, comments the table and fails only on the new prompt's results. A case that fails on both versions still blocks the merge, which is what you want when a pull request adds a test for a known bug.

```yaml
# .github/workflows/prompt-tests.yml
name: Prompt tests

on:
  pull_request:
    paths:
      - "prompts/**"
      - "evals/**"
      - "promptfooconfig.yaml"

permissions:
  contents: read
  pull-requests: write

jobs:
  prompt-tests:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@v7
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v7
        with:
          node-version: 24

      - name: Save the base branch prompt as the baseline
        env:
          BASE_REF: ${{ github.base_ref }}
        run: |
          mkdir -p .baseline
          git show "origin/$BASE_REF:prompts/support_agent.json" > .baseline/support_agent.json

      - name: Run both prompt versions
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        # Exit code 100 means some test failed; the last step decides. Anything else is a real error.
        run: npx promptfoo@0.126.0 eval --no-progress-bar --no-table -o results.json || [ $? -eq 100 ]

      - name: Comment the comparison
        if: ${{ !cancelled() && hashFiles('results.json') != '' }}
        env:
          GH_TOKEN: ${{ github.token }}
          PR: ${{ github.event.pull_request.number }}
        run: |
          ./scripts/compare-prompts.sh results.json > comment.md
          gh pr comment "$PR" --body-file comment.md --edit-last --create-if-none

      - name: Fail if this PR's prompt fails any case
        run: |
          failed=$(jq '[.results.results[] | select(.prompt.label == "this-pr" and (.success | not))] | length' results.json)
          echo "$failed case(s) failed on this PR's prompt"
          test "$failed" -eq 0
```

On our first run, the gate step counted three failures and would have failed the check. Two notes. A brand-new prompt file has no version on the base branch, so `git show` fails; skip the baseline step for new files. And add the response cache from [how to run LLM evals in CI/CD](/blog/llm-evals-ci-cd-github-actions/) once the suite grows; for Anthropic models, promptfoo only writes the disk cache when the provider has a `label`, which is why the config above sets one.

If you'd rather not maintain scripts, `promptfoo/promptfoo-action@v1` runs the eval and posts a summary comment for you. It evaluates the current checkout only, so it reports this pull request's results rather than a before-and-after comparison.

## Step 6: review prompt changes like code

A green check isn't a review. Add a few habits:

- **Name an owner.** A `CODEOWNERS` line such as `/prompts/ @your-org/support-leads` makes someone who knows the policy approve every prompt change.
- **Read the failing outputs, not only the counts.** The comment tells you which cases failed; `promptfoo view` shows the actual replies.
- **Require a new case with every behavioural fix.** If a pull request changes the prompt to fix a complaint, it should add the case that reproduces the complaint.
- **Change one thing per pull request.** Two prompt edits in one diff make it impossible to tell which one broke a case.
- **Run repeated, uncached tests before a release.** One pass of a judged case proves little; three passes with a minimum count is a better signal.

## Where production fits

The regression set only knows what you thought to test. The best prompt changes come from what real users did, and [improving a system prompt from production conversations](/blog/improve-system-prompt-from-conversations/) covers that side.

Agnost AI watches production conversations and judges each one against plain-language rules, such as "no Markdown in widget replies" or "never promises a refund outside 30 days". It alerts in Slack when one starts failing, which often happens after a prompt change slipped past the tests. Its Analysis API and MCP server return the flagged exchanges, so each confirmed failure can become a case in `evals/`. With Auto Improve, it can open a pull request with a proposed prompt fix, and the workflow above tests that pull request like any other.

If you would rather not keep the regression set by hand, Agnost can hold it. The same tool that monitors production builds your test set from real failures: flagged conversations become rows in an eval dataset, and Agnost suggests an evaluator for each, an LLM judge or a deterministic Python check. Experiments run the agent against that dataset in isolated Agnost sandboxes on every change and compare each run with the last, which is Step 4 without the config. Agnost doesn't gate merges in CI. Evals are on every plan, and Free includes 10,000 eval runs a month. Teams already set up with Promptfoo can keep it and copy flagged cases into `evals/` as above.

## Related reading

- [How to run LLM evals in CI/CD: a GitHub Actions guide](/blog/llm-evals-ci-cd-github-actions/)
- [LLM testing: unit tests, evals and regression tests](/blog/llm-testing/)
- [Improve a system prompt from production conversations](/blog/improve-system-prompt-from-conversations/)
- [Detect regressions after switching LLM models](/blog/detect-regressions-after-switching-llm-models/)
- [How to safely roll out changes to a customer-facing AI agent](/blog/safely-roll-out-changes-customer-facing-ai-agent/)

## Frequently asked questions

### What is prompt testing?

Prompt testing is running a fixed set of inputs through a prompt and checking the outputs with code and LLM-judge assertions, so you know whether a prompt change made things better or worse before users see it. The useful version compares the current prompt and the changed prompt on the same cases, side by side, on every pull request that edits a prompt.

### How do I test a prompt change before shipping it?

Keep prompts in files in your repo, keep a regression set of test cases next to them, and on every pull request run both the main-branch prompt and the changed prompt on those cases. Post a case-by-case comparison on the pull request, fail the check if the new prompt fails any case, and have a named owner review prompt changes like code.

### How do I compare two prompt versions?

List both versions in one Promptfoo config with labels such as main and this-pr, run promptfoo eval, and read the results per case. Promptfoo runs every test case against every prompt, so differences show up row by row. In CI, export the main-branch version with git show into a baseline file before the run.

### How do I catch tone and format regressions in prompts?

Use code checks for format: no Markdown in a plain-text widget, no emoji, valid JSON, a word limit. Use an LLM judge with a specific rubric for tone, such as acknowledges frustration in one sentence and uses no exclamation marks. Test each new check against one output you know is good and one you know is bad.

### What tools do prompt testing?

Promptfoo is built around it: YAML test cases, many prompts and models in one run, a side-by-side web view and a GitHub Action. DeepEval, Braintrust, LangSmith and Langfuse also test prompts through datasets and experiments. Agnost AI builds a dataset from failed production conversations, suggests evaluators for it, and runs experiments on every change in isolated sandboxes, comparing each run with the last. A plain pytest suite works too if your prompts are small.

### How many test cases does a prompt regression set need?

Start with 20 to 50 cases that cover the behaviour you can't afford to break, including the formats and tones your product depends on. Add a case for every bug a prompt change caused and every confirmed production failure. Keep the pull request suite small enough to finish in a few minutes.
