Changing one sentence in a system prompt can fix three cases and break five, and you will not notice until a customer does. promptfoo evaluation attacks that problem with a matrix: list your prompts, list the models, list the test inputs, and let the tool run every combination and grade each cell. You get a grid where regressions are obvious at a glance, produced by a YAML file anyone on the team can read in a pull request.
This guide is for engineers who iterate on prompts often and want a fast, config-driven loop rather than writing a test harness from scratch. We will build a config from the ground up, layer assertion types from cheap to expensive, wire in model-graded checks, compare providers, and set up a CI gate. Syntax follows the promptfoo documentation; confirm option names against the current docs when you copy.
The mental model: prompts × providers × tests
promptfoo’s central idea is a three-axis matrix. Prompts are the templates you are comparing. Providers are the models or endpoints that run them. Tests are the input variables plus assertions about what a good output looks like. Every prompt runs against every provider for every test, and results land in a table you can open in a local web viewer.
That structure makes it the natural tool for questions with a “versus” in them: prompt A or prompt B, a cheaper model or the current one, with or without a safety preamble. If instead your question is “does my pytest suite pass?”, a code-first framework such as DeepEval may feel more natural (we cover it in the DeepEval guide). The two coexist well.
Your first promptfooconfig.yaml
A minimal config for a support-bot prompt:
description: Refund bot prompt check
prompts:
- file://prompts/refund_v1.txt
- file://prompts/refund_v2.txt
providers:
- openai:gpt-4o-mini
- anthropic:messages:claude-3-5-haiku-latest
defaultTest:
assert:
- type: not-contains
value: "as an AI language model"
tests:
- vars:
question: "Can I return a laptop after 45 days?"
assert:
- type: contains
value: "30 days"
- type: llm-rubric
value: "Politely explains the return window and does not promise an exception"
- vars:
question: "Where is my order #A-1182?"
assert:
- type: contains-any
value: ["order status", "tracking"]
Model identifiers change often, so treat the provider lines as placeholders for whatever you actually use. Run npx promptfoo@latest eval in the folder, then npx promptfoo@latest view to open the results grid. Outputs for refund_v1 and refund_v2 sit side by side per model, each cell marked pass or fail with the reason.
Notice defaultTest: assertions placed there apply to every test, which is the right home for global rules like banned phrases or a maximum length.
Assertion layers: cheap first, judged last
Order your assertions by cost and determinism. The docs describe many assertion types; these categories do most of the work.
1. Deterministic string and structure checks. contains, not-contains, contains-any, regex, is-json, equals. They run instantly, never flake, and should catch a surprising share of regressions. If the output must be JSON with certain keys, assert it here, not with a judge.
2. Code-based checks. For logic that is awkward in YAML, a JavaScript or Python assertion can inspect the output and return pass or fail with a score. Use it for length windows, citation formats, or checking a number against a lookup.
3. Similarity and metric checks. Embedding similarity to a reference answer, or other scored comparisons, with a threshold. Useful when wording varies but meaning should not.
4. Model-graded checks. llm-rubric is promptfoo’s general-purpose “LLM as judge” assertion: you describe the criterion in plain English and a grader model decides. There are also assertions aimed at RAG, such as checks for context faithfulness or relevance. These cost tokens and add noise, so write rubrics narrowly and read the LLM-as-judge guide before you rely on one for gating.
A rule of thumb that keeps suites fast: aim for roughly three deterministic assertions for every model-graded one. If you cannot express a requirement deterministically, ask whether the requirement is clear enough to ship.
Feeding tests from files, not YAML sprawl
Inline tests are fine for ten cases. Beyond that, load them from a file so your suite can grow with your golden dataset:
tests: file://golden/refund_cases.csv
Each CSV column becomes a variable available to the prompt template, and special columns can carry assertions for that row. Alternatives include JSONL, spreadsheets, or a script that generates tests. The principle is the same one from the golden dataset article: rows have ids, tags, and a reviewer, and the config references a versioned file rather than a copy pasted into YAML.
Testing a RAG prompt without a vector store
You do not have to run your whole retriever inside promptfoo to evaluate generation. Put retrieved chunks in the test variables, captured from real pipeline runs, and test the answer prompt against them:
tests:
- vars:
question: "What is the SLA for priority tickets?"
context: file://fixtures/priority_sla_chunks.txt
assert:
- type: llm-rubric
value: "Only states facts present in the context; says it does not know otherwise"
- type: not-contains
value: "business days"
This isolates prompt behavior from retrieval changes, which is exactly what you want when tuning generation instructions. To check retrieval itself, use retrieval-focused metrics such as those in the RAGAS documentation and our RAGAS evaluation guide, or point a custom provider at your real endpoint so promptfoo exercises the full chain.
Comparing providers and prompts honestly
The side-by-side grid tempts people to eyeball and declare a winner. A few habits make comparisons trustworthy:
- Change one variable at a time. Prompt A vs B on the same model, or model X vs Y on the same prompt, not both at once.
- Disable caching for final numbers. promptfoo caches responses by default to speed iteration; use the no-cache option when you want fresh generations, and pin sampling settings such as temperature.
- Look at the failing cells, not just the pass rate. Two prompts can share 82% pass rate while failing entirely different cases.
- Mind the cost column. A prompt that scores one point higher at triple the tokens is a product decision, not an automatic win.
Making promptfoo a CI gate
The promptfoo CI/CD integration docs cover GitHub Actions and other runners. The core pattern is short: run promptfoo eval, write results to JSON, compute the pass rate, and fail the job if it falls short of your bar. The CLI offers a flag that fails on any test failure; for a percentage threshold you read the output file and check it yourself, for example with jq in a shell step.
npx promptfoo@latest eval -o results.json --no-cache
PASS_RATE=$(jq '.results.stats.successes / (.results.stats.successes + .results.stats.failures) * 100' results.json)
echo "pass rate: $PASS_RATE"
Check the results schema of your promptfoo version before relying on those field names, as output formats evolve. Then decide the gate type: any single hard-constraint failure (a banned phrase, invalid JSON) should block outright, while model-graded checks usually deserve a pass-rate margin because they are noisy. The design choices there are laid out in eval regression gates.
Keep PR runs affordable by running a smoke subset on every push and the full matrix nightly. Store the results JSON as a build artifact, and compare against the last accepted run to see which cells flipped.
Mistakes worth avoiding
- Judge and generator are the same model with no calibration. See the bias discussion in the LLM-as-judge guide; at minimum spot-check 30 judged rows by hand.
- One enormous rubric. “Is helpful, accurate, concise, and on-brand” fails opaquely. Split it into separate assertions with names.
- Prompts living only in YAML strings. Keep prompts in files so diffs are readable and production loads the exact same text.
- Ignoring tags. Add
metadataor description fields by scenario so a failure points to a category. - A suite that nobody updates. After every incident, add the failing input as a test.
Where it sits in the bigger system
promptfoo is the fast inner loop: edit a prompt, rerun, see the grid. The slower outer loop is traces, sampling, and rollback, which the LLMOps production guide maps out. For agentic systems, the harness engineering in practice article is a good complement, showing how verification steps wrap model calls so a bad generation is caught before the user sees it, and what is an agent harness gives the vocabulary for that layer.
Start with one prompt, two providers, ten tests, and three deterministic assertions per test. Add a rubric only where a string check cannot express the requirement, and grow the suite from real failures.
Practical promptfoo evaluation questions
What is promptfoo used for?
promptfoo is an open-source tool for testing and comparing prompts, models, and RAG or agent setups. You define prompts, providers, and test cases with assertions in a config file, run an eval, and review a pass or fail grid.
Do I need a judge model to use promptfoo?
No. Many assertions are deterministic, such as contains, regex, or JSON validation. A judge model is only needed for model-graded assertions like llm-rubric, which you should add selectively.
How do I run promptfoo in CI?
Run the eval command in a pipeline step, write results to a JSON file, and fail the job based on the CLI’s failure flag or a pass-rate check you compute from the file. The official CI/CD integration page includes GitHub Actions examples.
What is the difference between promptfoo and DeepEval?
promptfoo is config-first and shines at comparing prompts and models side by side from YAML. DeepEval is code-first, with pytest-style tests and a library of metrics. Many teams use both for different jobs.
Can promptfoo test a RAG system?
Yes. You can supply captured retrieval chunks as test variables to evaluate generation in isolation, or point a custom provider at your full pipeline endpoint. Retrieval quality is better measured with dedicated retrieval metrics.
Why do my promptfoo results change between runs?
Model outputs vary, and promptfoo caches responses by default, so repeated runs may look identical until the cache is bypassed. Use the no-cache option and fixed sampling settings for comparisons, and expect small variation on model-graded assertions.
AI Generated Apps AI Code Learning Technology
