CI/CD for LLMs: Quantifying Regressions with Promptfoo and GitHub Actions
Beyond the "Vibe Check": The Need for Deterministic AI Testing
If you have spent any time building LLM-powered applications, you have likely experienced the "Prompt Engineering Seesaw." You tweak a system prompt to fix a specific edge case in your customer support bot, only to realize three days later that the change inadvertently caused the bot to start hallucinating internal API keys or losing its professional tone in a different language.
In traditional software engineering, we prevent this with unit and integration tests. We have a set of inputs, and we expect a deterministic output. If the output changes, the build fails. Generative AI, however, is notoriously non-deterministic. The same input can yield slightly different outputs every time. For years, the industry standard for testing LLMs has been the "vibe check"—a developer manually eyeballs a few outputs, decides they look "good enough," and pushes to production.
As we move toward production-grade AI, the vibe check is no longer sufficient. We need to quantify performance. We need to know if a prompt change improves our accuracy by 5% or degrades our toxicity score by 10%. This is where deterministic AI testing and automated CI/CD pipelines come into play.
Why Traditional Unit Tests Fail LLMs
Traditional testing frameworks like Jest, Pytest, or Mocha are designed for binary outcomes. expect(add(1, 2)).toBe(3) works because math is static.
LLM outputs are high-dimensional and fluid. A test that expects a specific string will fail if the model chooses a synonym. If your test suite is too rigid, you face a mountain of false positives. If it is too loose, regressions slip through.
To solve this, we need a testing layer that understands semantic meaning, structure, and constraints. We need tools that can run dozens of test cases against multiple model providers simultaneously and provide a statistical overview of the results. This is the gap that Promptfoo fills.
Enter Promptfoo: Declarative Testing for Generative AI
Promptfoo is an open-source CLI tool and library designed to evaluate LLM output quality. It allows you to define test cases in a declarative YAML format, run them against various models (OpenAI, Anthropic, Ollama, etc.), and view the results in a matrix that highlights exactly where things went wrong.
What makes Promptfoo powerful for senior engineers is its focus on assertions. Instead of just looking at the output, you define what "good" looks like using a variety of metrics:
- Semantic Similarity: Does the output mean the same thing as the expected answer?
- LLM-as-a-Judge: Using a more powerful model (like GPT-4o) to grade the output of a smaller, faster model (like Llama 3).
- Regex and Pattern Matching: Ensuring the output contains (or doesn't contain) specific strings or formats (like valid JSON).
- Model-Graded Rubrics: Defining custom criteria like "Is the tone professional?" or "Did the model mention the refund policy?"
Building Your First Evaluation Suite
To implement this in a real-world project, you start by creating a promptfooconfig.yaml file. Let’s look at a practical example: a support agent that handles subscription queries.
Defining the Prompt and Providers
First, we define our prompts. You can test multiple versions of a prompt against each other to see which performs better.
prompts: - "You are a helpful assistant for a SaaS company. Answer the following user question: {{query}}" - "You are a concise support agent. Answer the user question in 2 sentences or less: {{query}}" providers: - openai:gpt-4o-mini - anthropic:messages:claude-3-5-sonnet-20240620
Designing Robust Assertions
The heart of the configuration is the tests array. This is where we move from vibes to metrics.
tests: - vars: query: "How do I cancel my subscription?" assert: - type: icontains value: "settings page" - type: llm-rubric value: "The response does not sound frustrated or impatient." - type: javascript value: output.length < 500 - vars: query: "Can I get a refund for my last three years of service?" assert: - type: semantic-similarity value: "Our policy only allows refunds for the last 30 days." threshold: 0.8 - type: not-icontains value: "sure, no problem"
In this setup, we are checking for specific keywords, using a rubric to judge sentiment, and using semantic similarity to ensure the policy alignment is correct even if the wording varies.
The CI/CD Bridge: Automating Evaluations with GitHub Actions
Running evaluations locally is great for development, but the real value is realized when these tests run automatically on every Pull Request. This ensures that no prompt change or model version update is merged without a quantitative report on its impact.
The Workflow Integration
Integrating Promptfoo into GitHub Actions allows you to block PRs that fail critical assertions or simply provide a summary of the performance changes in a PR comment. Here is a standard workflow implementation:
name: LLM Evaluation on: pull_request: paths: - 'prompts/**' - 'promptfooconfig.yaml' jobs: evaluate: runs-on: ubuntu-latest permissions: contents: read pull-requests: write steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v4 with: node-version: 20 - name: Install dependencies run: npm install -g promptfoo - name: Run Promptfoo Eval env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} run: | promptfoo eval --output output.json - name: Post PR Comment uses: promptfoo/promptfoo-action@v1 with: github-token: ${{ secrets.GITHUB_TOKEN }} cache-path: .promptfoo/cache
Quantifying Regression: The Difference Between "Better" and "Different"
When the action runs, Promptfoo compares the results of the current branch against the main branch (or a cached "baseline"). This is the critical step in quantifying regression.
The output in the GitHub PR will show a table comparing pass rates. If your pass rate drops from 98% to 92%, you have a regression. More importantly, you can see exactly which test cases started failing.
For example, you might find that while your new prompt is much better at being "concise," it failed the semantic-similarity test on the refund policy because it became too brief and left out legal disclaimers. This level of insight allows for informed decision-making rather than guessing.
Curating the "Golden Dataset"
The effectiveness of your CI/CD pipeline is entirely dependent on the quality of your test cases. As a senior engineer, your role shifts from writing code to curating this "Golden Dataset."
- Extract from Production Logs: Identify the top 50 most common user queries and add them to your test suite.
- Include Edge Cases: Did a user once try to jailbreak your bot? Add that attempt to your tests with a
javascriptassertion that checks for a standard refusal message. - Synthetic Data Generation: Use an LLM to generate 100 variations of common questions to ensure your prompt is robust against different phrasing and typos.
- Negative Tests: Always include tests where the model should refuse to answer. This is vital for safety and compliance.
Handling Failures: The Review Loop
When a test fails in CI/CD, it shouldn't always mean the code is "broken." Sometimes, the model’s output is actually better, but it triggered a false positive in your assertion.
This necessitates a review loop:
- Inspect the Failure: Look at the Promptfoo web UI (which can be hosted as a static site from the CI run).
- Adjust the Assertion: If the output was correct but the test failed, your threshold for
semantic-similaritymight be too high, or your regex might be too strict. - Update the Baseline: If the change in output is intentional and superior, update the "expected" value in your test suite to reflect the new standard.
Best Practices for a Resilient AI Pipeline
To make this system sustainable, consider these advanced strategies:
- Caching: LLM calls are expensive and slow. Promptfoo has built-in caching. Ensure your CI pipeline persists the
.promptfoo/cachedirectory across runs to save costs and speed up the feedback loop. - Secrets Management: Never hardcode API keys. Use GitHub Actions Secrets and ensure your evaluation scripts don't accidentally log sensitive outputs.
- Staged Evaluations: Run a small, fast test suite (e.g., 10 core cases) on every commit, and a "full" evaluation (e.g., 500+ cases) only when merging to the main branch.
- Cost and Latency Assertions: Promptfoo allows you to assert on metadata. You can fail a build if the average latency exceeds 2 seconds or if the token cost per request exceeds a certain threshold.
Actionable Conclusion
Moving from manual prompt testing to an automated, deterministic pipeline is the single most important step you can take to mature your AI infrastructure. By using Promptfoo and GitHub Actions, you transform LLM development from a mysterious art into a measurable engineering discipline.
Your next steps:
- Install Promptfoo:
npm install -g promptfoo. - Create a
promptfooconfig.yamlwith five core test cases for your most critical LLM feature. - Set up a GitHub Action to run these tests on every Pull Request.
- Stop guessing and start measuring.