How to measure LLM hallucinations with promptfoo before each release
A team shipping an LLM feature that answers from facts or documents needs evidence that fabricated answers are caught before release, not discovered by customers afterward. promptfoo can run hallucination-focused tests locally using reference-based factuality, context faithfulness and the hallucination red team plugin, and the same suite can repeat on every release. promptfoo is licensed under the MIT license and runs on your machine, so evals talk directly with the model under test without sending the test set through a promptfoo-hosted service. This page covers how to build each of these three test types, what each one proves, and what none of them prove.
Each test answers a different question. A factuality check compares the output against a reference answer you wrote, so it tells you whether the model contradicts a known truth in your domain. A context faithfulness check asks whether an answer in a retrieval-augmented application is supported by the passages it was given, which catches invention even when the claim sounds plausible. The hallucination red team plugin generates adversarial prompts designed to pull fabrications out of the model, including questions about things that do not exist. Each one is a sample, not a proof: a passing run means the cases you wrote were handled, and the coverage depends on how well those cases represent your users. Treat the suite as a regression signal, not a guarantee of accuracy.
Before the first run, confirm three things with your own team: who owns the reference answers and how they are reviewed, which grader model will judge faithfulness, and whether that grader is separate from the model under test. Record the pass rate for each release in the same format so the trend is comparable. Check the promptfoo version you pin against the promptfoo releases page, and confirm the Node.js requirement for your build agents before adding the suite to a pipeline. Keep the hallucination suite in version control next to the prompts it tests, so a change to either is visible in review.
Choosing a hallucination check by application type
Assistants that answer questions with a known correct answer, such as policy lookups, product specifications or internal definitions, are the simplest place to start. Each test case pairs a question with a reference answer, and the factuality assertion grades whether the output agrees with that reference.
- Start with the
factualityassertion in each test case, with the reference answer supplied as the expected value. - Build reference sets from owned sources: approved policy text, product catalogs or verified FAQ entries, and record who approved each answer and when.
- Cover paraphrase and negation: ask the same question in several phrasings, because fabrications often appear when the wording shifts.
- Keep the grader separate from the model under test: the judge should not be the system being measured, or its errors can hide the target's errors.
- Include out-of-set questions: add questions the reference set does not answer and check that the assistant says it does not know.
Before relying on these results, confirm that each reference answer is current and that every test names the source it came from. The factuality assertion proves agreement with the reference set only. It says nothing about questions outside that set, and a reference that is wrong will grade a wrong answer as correct.
When an application answers from retrieved documents, the central question is whether each claim is supported by the context the model received. The context-faithfulness assertion checks that the output's claims trace back to the retrieved text, which separates grounding failures from retrieval failures.
- Start with
context-faithfulness, passing the retrieved passages into each test so the grader sees exactly what the model saw. - Capture context from the live pipeline: hand-picked passages can pass tests while production retrieval returns different material.
- Include questions the corpus cannot answer: check that the output declines and states the information is missing, instead of filling the gap with plausible text.
- Measure retrieval separately: pair faithfulness with context-relevance and context-recall so weak retrieval is not mistaken for a model problem.
- Record the pipeline version: store the chunking, embedding and retrieval settings with each run so a drop in scores can be traced to a change.
Confirm which passages each test uses and that the pipeline version is recorded with the results. Faithfulness to context does not prove that the context is correct or current. A model can faithfully repeat an outdated or wrong document, and the assertion will pass it.
Assistants without a source, such as general advice, drafting or open-domain question answering, have no reference answer to grade against. The practical approach is adversarial. The hallucination red team plugin generates prompts that push the model toward invented facts, citations or confident answers about things it cannot verify.
- Start with the hallucination plugin in a red team configuration pointed at the application endpoint, not only the bare model, so the system prompt and tools are included.
- Add behavioral rubrics: use an
llm-rubricassertion to check that the output signals uncertainty when a question has no verifiable answer. - Verify citations outside the grader: when the assistant names sources, check that each title, author or URL exists, because a model grader will not confirm that.
- Track results by category: separate invented names, dates, figures and regulated claims so findings point to a specific fix.
- Rerun the same probes after each change: keep the configuration fixed so the rate can be compared across releases.
Confirm which plugin categories the scan covered and whether the probes reflect how your users phrase questions. A clean scan shows that the generated probes did not elicit fabrication. It does not show that the assistant is reliable on topics the probes did not reach, and probe coverage is always finite.
Reference-based factuality: catching answers that contradict known facts
Reference-based factuality testing starts with a reference set: a list of questions where the correct answer is known and agreed by your domain experts before any model is tested. Each case pairs a prompt with one or more reference answers written as plain statements, such as a policy limit, a product fact or a regulatory threshold. Keep the set small at first, cover the facts your application must never get wrong, and record who approved each answer and when it was last checked. The reference answers are the test's ground truth, so an error there becomes a silent false pass or a false alarm. Store the set in version control next to the eval configuration so changes to facts are reviewed like code changes.
In promptfoo, the factuality assertion compares the model output against the reference answer and returns a category, such as a subset, a superset, an agreement or a contradiction, rather than a simple match. Set the assertion's threshold to fail only on the categories you treat as hallucination, and review the category results before you decide which categories count as failures. Answers that are correct but worded differently are where objective checks like equals or contains fail for the wrong reasons. The factuality grader is designed to accept paraphrase, so use it for those cases and reserve exact-match assertions for fields that must match character for character, such as identifiers or codes.
The grader is a model, so its own errors and cost need to be measured before you trust a pass rate. Ask the grader to judge a small sample of answers you have labeled by hand, including deliberately wrong answers, and track how often it disagrees with your labels. Pick a grader model separate from the model under test where your setup allows it, and confirm the grader's provider, token usage and rate limits in your own environment, since each graded case adds a model call. Run the grader calibration again whenever you change the grader model or the reference set, because both shift the results over time.
How to set up a hallucination test suite in promptfoo
This sequence takes a team from a clean install to a local hallucination suite that runs the same way on every change. The output is a versioned config with reference-based and faithfulness tests, plus a baseline of failures your team has reviewed.
Install promptfoo from npm
An engineer installs promptfoo from the npm registry on a workstation or CI runner that meets the Node.js requirement. promptfoo's current release requires Node.js 22.22.0 or newer, so check the runtime version first. Confirm the install by running the CLI's version command and recording the output in the repository's README so every contributor uses the same release.
Create the config with the target provider
Create a promptfooconfig.yaml file in a dedicated eval folder and point its providers entry at the model or application that answers in production. Keep the prompt in its own file so later edits show up as diffs. Run the config validation or a single dry-run prompt to confirm the provider authenticates and returns an answer. The step is done when one test case produces output without errors.
Add reference-based factuality tests
Write test cases that pair each question with a reference answer written by a subject matter expert, then attach a factuality assertion to each one. Start with a small set of questions where the correct answer is unambiguous, and record who approved each reference. The check is that a deliberately wrong answer in a dry run fails the factuality assertion, which shows the grader can tell fabricated content from correct content.
Add context faithfulness tests for RAG
For retrieval-augmented applications, pass the retrieved passages into each test and add a context-faithfulness assertion so the grader checks that claims come from the supplied source rather than the model's general knowledge. Keep the passages inline or in versioned files so the test does not change when the document store changes. The check is that an answer that adds an unsupported claim fails, while a faithful answer passes.
Run the eval locally and capture results
Run the eval from the terminal so it executes on your machine and calls the model directly, as promptfoo's documentation describes. Save the output file with the run so it can be compared later. Note the grader model you used, since it affects scores. The step is done when the run finishes and produces a results file that lists pass and fail counts for each assertion.
Review failures and tune the assertions
Open the failing cases in the web viewer and read each answer against its reference and source passage. Sort failures into true hallucinations, grader errors and reference errors, then fix the matching item: change the prompt or retrieval, correct the expected answer, or rewrite the assertion. Record the decisions in the repository. The step is done when every failure has a labeled cause and the team agrees the suite measures what it should.
Confirm the suite runs the same way on each change
Pin the promptfoo version and the grader model in the config, then run the same command from a clean checkout on two different machines or in CI. Compare the results files for the same inputs. If scores differ beyond what the grader's variation explains, fix the settings before using the suite as a release signal. The step is done when the repeated runs agree and the command is wired into the team's change process.
Context faithfulness for RAG: does the answer stay inside the retrieved text?
A hallucination in a retrieval-augmented app can come from two places: the retriever handed the model the wrong text, or the model ignored the text it was given. These cards separate the two so a failing test points to the component that needs fixing. Each one builds on the same idea: the grader must see the retrieved context, and the claims in the answer must be traced back to it.
Pass retrieved context into each test
Faithfulness can only be judged against the text the model actually saw. Store the retrieved chunks alongside each test case, either as fixed context in the test file or captured from the retriever during the run, and pass them into the assertion as the context the grader uses. Check that the chunks in the test match the production retrieval settings, including chunk size, top-k and reranking. If the test uses hand-picked context, a passing score says little about the live pipeline.
Promptfoo introductionCheck each claim against the context
A fluent answer often mixes supported statements with invented details such as a date, a figure or a named source that does not appear in the chunks. Ask the grader to split the answer into individual claims and mark each one as supported or unsupported by the provided context. Set the test to fail when any claim is unsupported, not only when the overall answer looks wrong. Unsupported claims are the failure to catch.
Separate retrieval failures from generation failures
When an answer is wrong, the cause is either that the right text never reached the model or that the model did not use the text it received. Pair a context-recall or context-relevance check with the faithfulness check so each failing case is labeled by its cause. A case with missing relevant context is a retriever problem, and a case with the right context but an unsupported claim is a prompt or model problem. Fixing the wrong component wastes a release cycle.
Use the RAG evaluation guide for retrieval metrics
Faithfulness is one layer of RAG quality. Retrieval metrics such as context relevance and context recall measure what the retriever returned, and they need their own test cases and thresholds. Keep those metrics in a separate suite so that a drop in retrieval quality does not get hidden inside an answer score. The companion topic on evaluating RAG pipelines covers how to set those up alongside faithfulness.
Watch for false passes from fluent answers
Graders tend to reward answers that read well and cite the right topic, even when a key number or condition is invented. Test with paraphrased context, with answers that repeat the question's wording, and with cases where the context says the information is absent. An answer that correctly says the documents do not cover the question should pass, and an answer that confidently fills the gap should fail. Review a sample of passing outputs by hand before trusting the threshold.
How a hallucination eval moves from dataset to release gate
The run starts with a reference dataset of questions and vetted answers, plus retrieved context for RAG targets. promptfoo sends each prompt to the target application, which is kept separate from the grader model that scores factuality and context faithfulness. Results from the hallucination red team scan are stored per release, and the pass rate gate decides whether the release can ship. Check that the grader is not the model under test, and that the stored results can be compared across releases.
Test data flows through the target, separate graders and a gate that reads stored results.
Using the hallucination red team plugin to probe fabrication
The promptfoo hallucination red team plugin tests whether a model fabricates answers when it is pushed to, which is a different question from whether it answers correctly on a known set of questions. Reference-based tests such as factuality assertions compare output against answers you already know. The hallucination plugin instead generates adversarial prompts that tempt the model to invent facts, sources, citations, product details, dates or quotations, often for topics where no reliable answer exists or where the question presumes something false. Use it alongside your reference tests, not in place of them, because a model can score well on known answers and still improvise confidently when a question falls outside its grounding.
Place this testing inside a recognized risk framework so the results can be explained to reviewers. The promptfoo red teaming documentation references the OWASP LLM Top 10, the NIST AI Risk Management Framework and the EU AI Act as frameworks that support systematic testing before deployment. Map the hallucination results to the category that matches your risk owner's language, and record which plugin version, target configuration and grader produced each run. Confirm with your compliance team which framework mapping they expect, since the documentation names the frameworks but does not decide which one your organization must follow.
Plan the scan size before you configure the plugin. The number of probes you can run depends on the promptfoo edition and plan: the Community edition includes red teaming with 10k probes per month, while Enterprise and On-Premise plans are priced separately, so confirm the probe allowance in writing for the edition you will use. Decide which application surface each scan covers, such as a plain chat model, a RAG pipeline or an agent with tools, because a fabricated citation in a RAG answer may matter more than a fabricated date in a general chat reply. Review a sample of flagged outputs by hand before treating the failure rate as a release signal.
Configuration options and when each fits
This table compares the promptfoo options available for hallucination testing, from reference-based factuality to faithfulness checks, the hallucination red team plugin, grader choice, pass thresholds and stored results. Read each row against the kind of fabrication you expect, because no single option catches every form of invented output.
| Option | What it controls | When to use it | Trade-off |
|---|---|---|---|
| Factuality assertion with reference answers | Compares each output to a trusted reference answer and grades whether it agrees, omits or contradicts it | You have vetted answers for a fixed question set, such as product facts or policy lookups | Needs a maintained reference set, and correct answers phrased differently can be graded as wrong without careful reference writing |
| Context faithfulness with supplied context | Checks whether the answer stays within the source passages your application retrieved | A RAG application where the answer must be supported by the documents it was given | Says nothing about facts outside the context, so an answer can be faithful to a wrong document |
| Hallucination red team plugin | Generates adversarial prompts that tempt the model to invent details, citations or capabilities | You need to probe fabrication under pressure before release, including questions with no true answer | Generated probes measure resistance to specific pressure, not overall accuracy on your real traffic |
| Grader model choice | Which model scores the outputs for model-graded assertions and red team results | Use a grader that is separate from the model under test so the system does not mark its own answers | A stronger grader costs more per run and can change scores when swapped, so pin it and record it |
| Pass threshold | The score or failure count at which a run is treated as failing | Set a threshold once you have a baseline, so CI blocks releases that increase fabrication | A strict threshold on a noisy grader produces flaky failures, and a loose one lets regressions through |
| Per-release result storage with the self-hosted server | Keeps eval results from each release in one shared place for comparison over time | Several people or pipelines must compare hallucination rates across releases | The self-hosted server uses a single SQLite database, has no built-in authentication or SSO and is not recommended for production, so confirm the setup with your team before relying on it |
Tracking the hallucination rate across releases
A hallucination rate means little on its own. It becomes useful when each release is scored against the same frozen cases, stored where the team can compare it, and read alongside the version of the grader that produced it. The cards below cover those pieces and the storage decision that the self-hosted server forces.
Store results for every release
Tag each eval run with the application version, prompt version, model name and the promptfoo version used, then keep the output file or database record. Without these tags, a drop in pass rate cannot be traced to a change. Check that your pipeline writes results on failed runs too, since a release that fails the gate is the one you most need to explain later. Record the exact model snapshot, not only a family alias.
promptfoo introductionCompare pass rates on a fixed set
A release comparison is only valid when both runs use the same test cases, assertions and thresholds. Compare the factuality and context faithfulness pass rates per case category, not just in aggregate, so a regression in one area is not hidden by gains elsewhere. Treat small differences on a few dozen cases as noise and decide in advance how large a drop must be before it blocks a release.
Freeze the test set
Keep the hallucination test set under version control and change it only through a reviewed commit that records why. If you add cases whenever a bug appears, the new release is being scored on different questions than the last one. Add new cases to a separate set and report results on both, so the trend line stays comparable. Store the set's hash or commit ID with each run.
Version the grader separately
The model that grades factuality or faithfulness is a dependency that can change under you. Pin the grader model, its provider settings and grading prompts, and record them in each run. When you change the grader, re-grade the previous release's outputs with the new grader before comparing, or label the break in the trend as a grader change rather than a quality change.
Plan team-wide history storage
The self-hosted promptfoo app stores data in a local SQLite database that cannot be shared across replicas, has no RBAC, horizontal scaling, built-in authentication or SSO, and is not recommended for production use. A shared release history therefore needs a planned approach: keep versioned result files in your own artifact or object store, or consider the Enterprise edition. Confirm with promptfoo which option fits your access and retention rules before you build dashboards on top.
Self-hosting docsQuestions buyers ask about hallucination testing with promptfoo
What drives the cost of hallucination testing with promptfoo?
The cost is driven by four things: building the test set, paying for grader model calls, the volume of red team probes, and reviewer time spent on failures. promptfoo itself is MIT licensed and the Community edition is free, so the spend is mostly people time and model API usage. Test set creation is largely one-time work, while grader calls and probe runs recur every time the suite runs in CI or before a release. A quote should separate the one-time build (reference answers, context fixtures, initial grader tuning) from the recurring run costs and the expected review time per release. Ask the partner to state which model provider will be billed for grading and target calls, and at what volume.
How long does a first hallucination test suite take to build?
The duration depends mainly on how many reference answers and retrieval contexts you already have, how many features or document sets are in scope, and how many people must review grader decisions. A suite built on existing support tickets or verified documents moves much faster than one that needs subject-matter experts to write answers from scratch. Ask for a written scope listing the features, the number of test cases per feature and the review steps before agreeing to a timeline. DeployOpen works on fixed-scope engagements, so the timeline is set in writing before work starts.
What does the team need to provide for this work?
Three inputs matter most. First, domain experts who can write or verify reference answers, because a factuality check is only as good as its ground truth. Second, access to the retrieval context your application uses, such as the documents, chunks or search results returned for each query, so faithfulness can be checked against what the model actually saw. Third, CI access if the suite should run on every change, including permission to store secrets for the model providers. Expect the domain reviewers to be the constraint, not the tooling.
Can our own engineers build hallucination tests in-house?
Yes, a capable engineering team can build these tests in-house, since promptfoo runs locally from the CLI and its documentation describes evals that talk directly with the model. The hard parts are not the configuration files. They are writing trustworthy reference answers, choosing graders whose verdicts your reviewers accept, and keeping the suite current as documents and features change. Teams that lack an evaluation owner or time for reviewer calibration often find the work stalls after the first run. A partner can take on the build and hand over a documented suite your team maintains.
Which assertions catch fabricated answers, and how do I check the grader?
Reference-based factuality checks compare an answer with a known correct answer, while context faithfulness checks whether a RAG answer is supported by the retrieved context. The hallucination red team plugin probes for invented answers using adversarial prompts. Each grader needs its own check: sample graded outputs, have a reviewer label them by hand, and compare the grader's verdicts with those labels before trusting the suite. Confirm the exact assertion names and plugin options against the current promptfoo documentation for the version you deploy, because these change across releases.
What changes between the Community and Enterprise editions for this work?
The Community edition is free and includes all LLM evaluation features, all model providers and integrations, and red teaming with 10k probes per month, with community support. Enterprise adds team sharing, teams-based access control and SSO, custom roles and permissions, continuous monitoring, a centralized guardrail dashboard, remediation recommendations and priority support with SLAs, at custom pricing. For hallucination testing alone, the test logic is the same in both editions. Enterprise matters when several teams must share results, when access must be controlled through SSO, or when the organization needs support commitments. Enterprise On-Premise runs that functionality on your own infrastructure with a dedicated deployment engineer. Ask for a quote based on your user count and deployment model.
What does it cost to keep hallucination tests running over time?
Recurring cost comes from model API calls for targets and graders, probe volume against the 10k monthly probes included in the Community edition, and the time reviewers spend on new failures and on keeping reference answers current. Each new release, document update or prompt change adds both model calls and review work. Ask the partner to describe a retainer or handover option for updates, and to estimate the review hours per release based on your test volume. Confirm with your model provider the current pricing for the models you grade with, since those rates are set by the provider.
Limits and what to confirm in your environment
A passing hallucination suite lowers risk but does not remove it. The cards below cover where the method is weak and what your team should confirm about graders, data handling and plan limits before relying on the numbers in a release decision.
Model graders can hallucinate too
Factuality and rubric assertions often run on a model grader, and that grader can accept a fluent, confident fabrication as correct. Treat grader output as a measurement with its own error rate. Spot-check a sample of passes and fails by hand, and check that the grader model differs from the model under test so one model does not mark its own answers. Record which grader and version produced each score.
promptfoo introductionPassing tests do not prove absence
A suite only detects fabrications that its test cases happen to provoke. Questions outside the covered domain, multi-step reasoning, and rare entities can produce invented answers that no assertion checks. Report results as a rate over a named set of cases, not as a statement that the application does not hallucinate, and say which question types the set omits.
promptfoo red teamingReference sets go stale
Reference answers encode facts that change, such as prices, policies, product versions and personnel. A reference set that was correct at release time can start marking correct answers as wrong, or wrong answers as right. Assign an owner to each reference set, set a review date, and version the sets alongside the prompts so a score change can be traced to a data change or a model change.
Confirm grader model access
Model-graded assertions call a separate model, which you must have access to, budget for, and be allowed to use under your provider agreement. Confirm which grader models your accounts can reach, their rate limits, and whether the grader is available in every environment where evals run, including CI runners and air-gapped networks. A grader change can shift scores, so pin it in configuration.
Confirm data handling for provider prompts
Every test prompt, retrieved document and model output sent to a hosted grader or target leaves your infrastructure under that provider's terms. Confirm retention, training use and regional processing with each provider, and decide whether test data containing customer or patient records is allowed to reach them at all. The promptfoo documentation states that evals run locally and talk directly with the LLM, so the provider relationship is the boundary to review.
Confirm red team probe limits on your plan
Red teaming run volume depends on the edition you use. The Community edition includes red teaming with a monthly probe allowance, while Enterprise and On-Premise pricing is custom. Confirm the probe count your plan includes, how a hallucination scan consumes it, and what happens when the allowance runs out mid-release. Ask for these limits in writing before you set a release gate that depends on them.
- Community probes per month
- 10k
How DeployOpen works on this
DeployOpen plans and builds hallucination test suites for promptfoo inside the infrastructure you control, so the test data, judge models and results stay where your security and compliance teams can review them. The work starts with a written scope that names the applications, sources of truth and release gates the suite must cover.
How we scope
- Inventory the LLM features, the models behind them and the reference or retrieved sources each answer depends on.
- Agree in writing which factuality, context faithfulness and hallucination red team checks apply to each feature.
- Define the pass criteria, the rate you will track across releases and who approves a release that misses them.
How we build
- Build reference datasets and RAG context fixtures from your approved sources, with owners named for each dataset.
- Configure promptfoo assertions and judge models, keeping the judge separate from the model under test.
- Wire the suite into your pipeline and run it against a known-bad baseline to confirm the tests catch fabricated answers.
How we hand over
- Document the suite layout, assertion choices, grading thresholds and how to add test cases as sources change.
- Deliver a run record showing the baseline rate per feature, so later releases can be compared against it.
- Walk your engineering and compliance teams through the evidence the suite produces and where its limits are.
How we support
- Fixed-scope engagements have deliverables and timelines agreed in writing before work starts.
- Ongoing support, upgrades of promptfoo and suite maintenance are available as a retainer.
- Confirm with us and your own team how judge model costs and run frequency will be budgeted before the suite goes into daily use.

