← All posts

Tutorial

Does Your Prompt Change Break Anything? Regression Gates

Add a prompt regression gate to CI: run a small eval on every pull request, comment the pass rate versus main, and fail the check when it drops too far.

24 min read

Copy this article

Clipboard access is unavailable. Select the Markdown and copy it, then paste it into your chat.

A prompt regression gate is a CI check that re-runs a small eval set whenever a pull request touches a prompt, compares the pass rate with the main branch, and fails the check if the drop is bigger than a threshold you chose in advance. The prompt lives in a file, the eval cases live in a file, and a workflow posts the result as a pull request comment so the reviewer sees the numbers before they read the diff.

This tutorial builds that gate end to end with a prompt file, 20 labelled cases, a runner, a compare script, a comment script and a workflow. The model is a deterministic stub we wrote, so every number below comes from the stub and real model results will differ. We couldn’t run GitHub Actions here either: the workflow was parsed as YAML and its scripts were tested locally, but the workflow itself was not run.

Quick answer

Keep each prompt in a file with a labelled eval set beside it, and run the base prompt and the pull request prompt through the same runner, three times each. Compare ranges, not single numbers. Fail the check only when the mean drops by more than your threshold and the head’s best run is below the base’s worst run. Post the table as one comment that updates on each push.

Give the job contents: read and pull-requests: write only, keep API keys in repository secrets, and never hand secrets to code from forks. Cap cost with a call budget, a job timeout and a concurrency group.

Original diagram of the prompt regression gate. 1, a pull request changes a file under prompts/. 2, the workflow runs the same cases and the same runner on both prompts. The base prompt is evaluated on the base branch for 3 runs and the head prompt on the pull request for 3 runs. 3, the compare step fails only if the mean drops by more than the threshold and the head’s best run is below the base’s worst run. The result goes to 4, one comment whose table updates on each push, and 5, the check result, which passes or fails with exit code 1. An example from the post using a stub model: base 85, 95 and 90 percent, head 70 percent three times, a mean change of minus 20 points with non-overlapping ranges, so the check fails.

Why prompt changes need a gate

A prompt edit looks harmless. Someone tidies a sentence or removes a rule that seemed redundant, and the diff is a few lines of English that a reviewer can’t judge by reading.

Code has a standard answer: tests run on every pull request. Prompts deserve the same, with a small set of cases you already know the answers to, run automatically, with the result placed where the review happens.

Two things make prompts different. Model output varies from run to run, so one pass rate is a noisy number. And running the eval can cost money and needs a credential, so the workflow must be careful about who can trigger it.

The demo project and its files

Download the prompt regression gate demo and extract it into a new folder. You need Python 3.10 or newer and nothing else, because the scripts use only the standard library.

prompts/ticket_triage.txt
evals/cases.jsonl
scripts/run_eval.py
scripts/compare.py
scripts/post_comment.py
.github/workflows/prompt-eval.yml
examples/ticket_triage_regress.txt
examples/ticket_triage_harmless.txt
README.md

The toy task labels a customer message as account, billing, bug or other, which makes an exact match scorer enough. The two files under examples/ are edited prompts we use to prove the gate works: one makes things worse, one doesn’t.

Keep the prompt in a file and write the cases

The prompt is a plain text file, so a change shows up in a pull request like any other:

You are a support triage assistant. Read one customer message and label it.
Keyword rules (the label with the most matching keywords wins):
- account: password, login, locked out, email address
- billing: refund, invoice, charge, payment
- bug: crash, error, broken, freezes
- other: anything else
Answer with the label only.

Each eval case is one line of JSON with an id, the input and the expected answer:

{"id": "c01", "message": "I was charged twice, please refund me", "expected": "billing"}
{"id": "c03", "message": "I forgot my password and I'm locked out", "expected": "account"}
{"id": "c09", "message": "The page freezes after login", "expected": "bug"}

The demo set has 20 cases. A few, like c09, match keywords from two labels, which gives the stub something like the borderline behaviour a real model shows. Decide each expected answer before you see what the model says, and keep some borderline cases, because that’s where prompt edits tend to bite.

For choosing and growing a set, see how to build a 30 case eval set and run it three times. Each case here is worth 5 points of pass rate, which matters for the threshold below.

Run the eval three times with a stub model

The runner reads a prompt file and a cases file, calls the model once per case per run, and writes pass rates to JSON. The only model call is one marked function:

# SWAP POINT: replace the body of call_model() with a real model call.
# Keep the signature. It must return the model's text answer as a string.
# Read any API key from an environment variable (a repo secret in CI),
# never from a file in the repository.
def call_model(prompt: str, message: str, case_id: str, run: int) -> str:
    return stub_model(prompt, message, case_id, run)

The stub is not a language model. It reads the keyword rules inside the prompt, counts matches per label and answers with the winner. If the prompt no longer says “label only”, it answers in a chatty format that fails the exact match. Ties are broken by a hash of the case id and run number, so they resolve differently between runs, which is our stand in for sampling noise.

We ran the base prompt three times:

python3 scripts/run_eval.py --prompt prompts/ticket_triage.txt --cases evals/cases.jsonl --runs 3 --out base.json
prompts/ticket_triage.txt run 1: 17/20 = 85.0%
prompts/ticket_triage.txt run 2: 19/20 = 95.0%
prompts/ticket_triage.txt run 3: 18/20 = 90.0%

Same prompt, same cases, and the pass rate moved across a 10 point range. That’s why the next section exists.

Choose a threshold that noise won’t trip

If one pull request run scored 85% and the main branch scored 95%, a naive “fail on a 5 point drop” rule would fail a change that changed nothing. A flaky gate trains people to re-run until it’s green.

The demo requires two conditions before it fails:

  1. The head’s mean pass rate is lower than the base mean by more than the threshold (5 points by default).
  2. The head’s best run is below the base’s worst run, so the two ranges don’t overlap.
drop = mean(b) - mean(h)
overlap = max(h) >= min(b)
failed = drop > a.threshold and not overlap

The first condition says the change is big enough to care about. The second says it’s bigger than the spread you can see. Here the base range is 85 to 95, so a head result inside that range is treated as indistinguishable from base.

The rule is lenient, and that has a cost. A real 8 point drop that stays inside the noise passes. With 20 cases and 3 runs you can only reliably catch large regressions. Catching smaller ones takes more cases, more runs, or both, and the cost section shows what that does to the call count.

To pick your own threshold, run your unchanged main prompt a few times first and set the threshold above the spread. A threshold of 3 points can’t be meaningfully tested on 20 cases. If one case must never fail, give it its own check instead of hiding it in an average.

Compare base and head and watch a real failure

The compare script reads two result files, prints a markdown table and exits with code 1 when the gate fails. The head here is examples/ticket_triage_regress.txt, the base prompt with the password, login, locked out and payment keywords removed, as if someone had trimmed the rules to shorten the prompt:

python3 scripts/run_eval.py --prompt examples/ticket_triage_regress.txt --cases evals/cases.jsonl --runs 3 --out head.json
python3 scripts/compare.py base.json head.json --threshold 5; echo "exit code: $?"
examples/ticket_triage_regress.txt run 1: 14/20 = 70.0%
examples/ticket_triage_regress.txt run 2: 14/20 = 70.0%
examples/ticket_triage_regress.txt run 3: 14/20 = 70.0%
<!-- prompt-eval-report -->
### Prompt eval: FAIL

| | Runs (pass %) | Range | Mean |
| --- | --- | --- | --- |
| base | 85.0, 95.0, 90.0 | 85.0 to 95.0 | 90.0 |
| head | 70.0, 70.0, 70.0 | 70.0 to 70.0 | 70.0 |

Mean change: -20.0 points. Threshold: 5.0 points. Ranges overlap: no.
Model: stub. Calls for this run: 120.

Cases that passed less often on head: `c03` (3/3 to 0/3), `c08` (3/3 to 0/3), `c11` (3/3 to 0/3), `c15` (3/3 to 0/3), `c19` (1/3 to 0/3), `c20` (1/3 to 0/3)
exit code: 1

This output came from the zip, unzipped into an empty folder. The four cases that fell from 3/3 to 0/3 each depended on a removed keyword, so the reviewer sees which inputs broke without opening the eval files.

We also ran examples/ticket_triage_harmless.txt, which only adds two keywords that no case uses. It printed the same three run results as base, the table said PASS, the mean change was +0.0 points and the exit code was 0.

The first output line is a hidden HTML marker. The comment script uses it to find its own earlier comment, so each push updates one comment instead of adding a new one.

The workflow file

Here’s the workflow. We parsed it as YAML and checked its structure (trigger, permissions, timeout, step names), but we did not run it, so test it on a throwaway pull request first.

name: prompt-eval

on:
  pull_request:
    paths:
      - "prompts/**"
      - "evals/**"
      - "scripts/**"

# Least privilege: read the code, write PR comments. Nothing else.
permissions:
  contents: read
  pull-requests: write

# A new push to the same PR cancels the older, now stale run.
concurrency:
  group: prompt-eval-${{ github.event.pull_request.number }}
  cancel-in-progress: true

jobs:
  eval:
    # Fork PRs get no secrets and a read-only token, so skip them here.
    # Dependabot PRs are treated like forks (read-only token), so the comment step would fail there.
    if: github.event.pull_request.head.repo.full_name == github.repository
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      # Tags can move. For a real repo pin each action to a full commit SHA (see the post).
      - uses: actions/checkout@v7          # the PR head (merge commit)
        with:
          persist-credentials: false
      - uses: actions/checkout@v7          # the base branch, prompts only needed
        with:
          ref: ${{ github.event.pull_request.base.sha }}
          path: _base
          persist-credentials: false

      - name: Evaluate base prompt
        run: >
          python3 scripts/run_eval.py
          --prompt _base/prompts/ticket_triage.txt
          --cases evals/cases.jsonl --runs 3 --max-calls 100
          --out base.json
        # env:
        #   MODEL_API_KEY: ${{ secrets.MODEL_API_KEY }}   # only once you swap in a real model

      - name: Evaluate head prompt
        run: >
          python3 scripts/run_eval.py
          --prompt prompts/ticket_triage.txt
          --cases evals/cases.jsonl --runs 3 --max-calls 100
          --out head.json

      - name: Compare and gate
        run: |
          set +e
          python3 scripts/compare.py base.json head.json --threshold 5 > report.md
          echo "GATE_EXIT=$?" >> "$GITHUB_ENV"
          cat report.md >> "$GITHUB_STEP_SUMMARY"

      - name: Post or update the PR comment
        env:
          GITHUB_TOKEN: ${{ github.token }}
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: python3 scripts/post_comment.py report.md "$PR_NUMBER"

      - name: Fail the check if the gate failed
        if: env.GATE_EXIT != '0'
        run: exit 1

Details we checked against GitHub’s documentation on 2026-11-12:

  • paths filter. The workflow only runs for pull requests that change prompts/, evals/ or scripts/.
  • Two checkouts. The first gets the pull request, the second puts the base commit in _base so we can read the base prompt. Both runs use the cases and scripts from the pull request, so a new case added in the same pull request compares like with like. The actions/checkout README showed @v7 in its usage examples on 2026-11-12. A tag can be moved, and GitHub’s secure use page says pinning an action to a full length commit SHA is the way to get an immutable reference (checked 2026-11-12), so for a real repository replace the tag with a SHA you’ve verified comes from the action’s own repository.
  • persist-credentials: false. The README says this input controls whether the token is configured in local git config, and it defaults to true. Nothing later needs git credentials.
  • Concurrency group. With cancel-in-progress: true, a new push cancels the older run for the same pull request.
  • Timeout. The docs give the timeout-minutes default as 360, so the job sets 10.
  • Gate step. The compare step saves its exit code to GITHUB_ENV instead of failing at once, so the comment still posts when the gate fails. The last step then fails the job.

The comment script is 57 lines of standard library Python. It pages through the pull request’s comments 100 at a time, looks for a comment from a bot account that carries the hidden marker (so a person pasting the marker is ignored), then updates that comment or creates one. GitHub’s REST docs list GET and POST on /repos/{owner}/{repo}/issues/{issue_number}/comments and PATCH on /repos/{owner}/{repo}/issues/comments/{comment_id}, with the text in a body field. We tested the script against a local mock server with 150 comments: with a bot comment holding the marker on page 2 it updated that comment, ignored a user comment that contained the marker, and with no marker comment it created a new one. That checks our logic, not the real API, so the first real run is still your test.

Permissions for posting the comment

GitHub’s secure use documentation says to make sure the GITHUB_TOKEN is granted the minimum required permissions (checked 2026-11-12). The workflow does that with a top level block:

permissions:
  contents: read
  pull-requests: write

The workflow syntax reference says that once you specify any permission, every one you leave out is set to none. So this grants read access to contents, write access to pull requests and nothing else.

Why pull-requests: write? The REST docs for creating an issue comment say the token needs write permission on either Issues or Pull requests, and pull requests are issues for comments. The narrower grant matches the one job we do.

The token page also says you can set permissions for an entire workflow or for individual jobs. With one job the two are equivalent. Once you add a lint job, keep contents: read at the top and raise permissions only on the job that comments.

Fork pull requests and the two pull request triggers

Read this part slowly, because the mistake is easy and the consequences are real.

The pull_request trigger runs from the pull request’s merge commit. GitHub’s events documentation says that, with the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository, and that the GITHUB_TOKEN has read-only permissions in pull requests from forks (checked 2026-11-12). So on a fork pull request our eval can’t read an API key or post a comment. That’s the safe default, and the job carries a matching condition:

if: github.event.pull_request.head.repo.full_name == github.repository

Pull requests from branches in the same repository run the gate and fork pull requests skip it. GitHub’s docs also say workflows triggered by Dependabot pull requests are treated as though they come from a fork, so they get the same restrictions and the comment step would fail there.

Skipping forks isn’t the whole story. A same repository branch is trusted code, because anyone who can push one can edit the scripts and read any secret the job exposes. GitHub’s secure use page says any user with write access to a repository has read access to all of its secrets, so keep write access narrow and scope the model key to a low limit.

The pull_request_target trigger differs. The docs say it runs in the context of the default branch of the base repository, rather than in the context of the merge commit. That suits jobs like labelling fork pull requests, because the workflow definition comes from your trusted branch. But the same page warns that running untrusted code on this trigger may lead to security vulnerabilities, including cache poisoning and granting unintended access to write privileges or secrets, and says to avoid the event if you need to build or run code from the pull request.

Our eval runs scripts and prompt text from the pull request, which is exactly the case the warning describes. The secure use page adds that workflows on these triggers must not explicitly check out untrusted code, and to avoid pull_request_target if it’s not necessary.

So the rule is simple: use pull_request, skip forks, and don’t switch to pull_request_target just to get a secret or write token on fork pull requests. Commenting on fork pull requests safely needs a deliberate design that keeps untrusted code away from secrets, which this post doesn’t cover.

One more habit. The secure use page says an untrusted value such as a pull request title can be exploited when it’s interpolated into a shell script, and recommends passing it through an environment variable. The workflow passes the pull request number as PR_NUMBER in env for that reason. It’s an integer, so low risk, but the habit matters.

Where the API key lives

The demo needs no key because the model is a stub. With a real model, the key belongs in a repository secret, never in prompts/, evals/cases.jsonl or any other file in the repo.

GitHub’s documentation on using secrets says you create a repository secret in the repository settings or with gh secret set, and read it through the secrets context:

env:
  MODEL_API_KEY: ${{ secrets.MODEL_API_KEY }}

Set it as a step level env on the step that runs the model, so other steps don’t see it. The secure use page says automatic redaction in logs is not guaranteed, so never print the key, and store each sensitive value as its own secret rather than inside a JSON or YAML blob. Your call_model reads os.environ["MODEL_API_KEY"], and your local copy stays in your shell or a git ignored file.

The if condition keeps fork code away from the secret. If a key does get committed, follow what to do if an API key leaks into a GitHub repo, and consider the scanning covered in GitHub secret scanning, Dependabot, TruffleHog and Gitleaks.

Cost limits

The gate runs on every matching push, so cost scales with how often people push. One gate run makes:

calls = cases x runs x 2 prompts (base and head)

For the demo that’s 20 x 3 x 2 = 120 calls, matching the Calls for this run: 120 line above. Forty cases doubles it, and going from 3 runs to 5 multiplies it by 5/3. The stub is free, so the demo has no dollar figure. For a real price, check your provider’s pricing page.

Four guards are in the demo, and you should keep them when you swap in a real model:

  • A call budget. --max-calls makes the runner refuse to start when planned calls exceed it. We tested it: 60 planned calls with --max-calls 50 printed refusing to run: 60 calls planned, limit is 50 and exited with code 2 before any call.
  • A job timeout. timeout-minutes: 10 stops a hung run long before the 360 minute default (checked 2026-11-12).
  • A concurrency group. A new push cancels the older run for the same pull request.
  • A paths filter. Pushes that don’t touch prompts, evals or scripts don’t run the eval.

The demo doesn’t implement caching the base results per main commit, which would leave you paying only for the head run. A spending limit in your provider’s console, if it offers one, is a backstop that doesn’t depend on your workflow being correct.

What this gate won’t catch

A regression gate is a smoke alarm, not an audit. It tells you the cases you wrote still pass at about the rate they did before, and nothing about inputs you didn’t write down.

  • One case is 5 points here, so the scale is coarse.
  • Passing with a stub proves the plumbing works, not that your real prompt is good. When you connect a real model, re-measure the noise and re-pick the threshold.
  • Exact match suits label tasks. Free text answers need another scorer, which needs its own tests.
  • If the prompt and the cases change in the same pull request, review both, because loosening a case can hide a regression.

When production surprises you, turn the failure into a new case. Building your own benchmark from your logs covers that.

FAQ

What is a prompt regression gate?

It’s a CI check that re-runs a small labelled eval set when a pull request touches a prompt, compares the pass rate with the main branch, and fails if the drop beats a threshold. Here the result is posted as a pull request comment so reviewers see the numbers with the diff.

How big should the failure threshold be?

Bigger than the run to run noise you can see. The same base prompt scored 85, 95 and 90 across three runs, so the gate fails only when the mean drops by more than 5 points and the head’s best run is below the base’s worst. With 20 cases, one case is 5 points.

Why run each eval three times?

One run is a noisy number, and a gate that fails on noise gets ignored. Three runs give a range to compare. The rule is lenient, so a real drop inside the noise passes, and catching smaller regressions takes more cases or more runs.

Which permissions does the workflow need to comment on a pull request?

The demo sets contents: read and pull-requests: write. GitHub’s workflow syntax reference says unspecified permissions become none once you specify any, and the REST docs say creating a comment needs write access to Issues or Pull requests (checked 2026-11-12).

Should you use pull_request_target to run evals on fork pull requests?

Not for this workflow. GitHub’s docs warn that running untrusted code on pull_request_target may lead to vulnerabilities, including unintended access to write privileges or secrets. With pull_request, secrets aren’t passed to the runner for forks and the token is read-only, so the demo skips forks.

Where should the model API key go?

In a repository secret, read through the secrets context and passed only to the step that calls the model, never committed to the repo. The demo needs no key because its model is a stub, so the numbers in this post come from the stub and real results will differ.

Where to go next

Grow the eval set with the 30 case eval set guide, then replace call_model with a real call and re-measure the noise before you trust the threshold. Choosing an AI model by testing your own task pairs well with this gate.

  • #prompts
  • #evals
  • #github-actions
  • #ci