Testing RAG document poisoning with promptfoo: when your team needs it
Run a RAG poisoning test when your application ingests documents it does not fully control and the answers it gives could change what people do. Typical sources include supplier contracts, uploaded files, web pages, shared drives and tickets written by staff or outsiders. The question to answer before deployment is whether text planted in one of those documents can steer the model's answers, override its instructions or push users toward a wrong or harmful conclusion. promptfoo's RAG poisoning utility is built for that question. It inserts malicious content into the context or knowledge base that your application retrieves from, then checks whether the application's response follows the planted content. It tests resilience to poisoned context, not the quality of your retriever in general.
In the OWASP Top 10 for LLM Applications 2026, the closest category is LLM05 Data and Model Poisoning, which covers corrupted data entering the pipeline. Two neighbouring entries matter here too: LLM01 Prompt Injection, since poisoned documents often carry instructions, and LLM08 Hidden Context Exposure, which the 2026 edition added at LLM08 in place of the 2025 Vector and Embedding Weaknesses entry. LLM09 Vector and Embedding Weaknesses still applies to retrieval itself. Map your test results to these entries in your own risk register, and check the current mappings in the OWASP source before you cite them to an auditor. For agentic systems, ASI06 Memory and Context Poisoning in the OWASP Top 10 for Agentic Applications for 2026 describes the same pattern when retrieved content persists into later actions.
Plan the test before the application goes live, and repeat it when you change the document sources, the retriever, the chunking, the prompt template or the model. A useful gate is whether your team can name who may add documents, how those documents are reviewed, and what the application is allowed to do with an answer. If the application only summarizes internal policy from a controlled repository, a lighter review may be enough. If it drives payments, approvals or customer messages, run the test and treat any followed instruction as a release blocker. Before you start, confirm with your own legal and data owners what the test sends to a hosted service, because the data handling section of this page covers that.
Configuration options and when each fits
This table compares the main choices in a poisoning test: which knowledge base to seed, how many poisoned documents and goals to run, how results are graded, and whether the test runs once or on a schedule. Read each row against your own review capacity, because broader coverage means more documents leave for hosted generation and more results to review. Most teams should start small in an isolated copy and widen only after the grading criteria are agreed.
| Decision | Option | Trade-off | When it fits |
|---|---|---|---|
| Knowledge base | Isolated copy of the index | Lowest risk to live content, but it may not match production chunking or metadata | First runs, and any time poisoned text must never reach a real user or index |
| Knowledge base | Staging index that mirrors production | Closer to real retrieval behavior, but needs strict access controls and cleanup | Pre-release checks once the isolated copy results are understood |
| Poisoned documents and goals | Small set, a few goals per document | Quick to review and cheap to generate, but misses variations in phrasing and placement | Initial baseline or a new application with a narrow document set |
| Poisoned documents and goals | Broad set across document types and goals | Wider coverage, but more complete documents are sent to hosted generation and more output needs review | Before a major launch or after a change to ingestion or retrieval |
| Grading criteria | Written pass and fail rules agreed before the run | Adds upfront effort, but keeps results consistent between reviewers and runs | Any test that feeds evidence to a security review or audit |
| Grading criteria | Default grading with spot checks | Faster to start, but a reviewer may disagree with the grader on borderline answers | Exploratory work where the team is still learning what a fail looks like |
| Run pattern | One-off run by the security team | Produces a single report, with no protection against later regressions | Initial assessment or a point-in-time review |
| Run pattern | Scheduled pipeline run after ingestion changes | Catches regressions, but recurring hosted generation and reviewer time must be budgeted | Knowledge bases that change often or are fed by external sources |
Where the poisoned content and your data travel
The flow starts at your own machine, where the promptfoo CLI loads the document you want to poison and the goal you want the attack to pursue. The CLI sends the complete document contents and that goal to the hosted generation endpoint, which sits outside your infrastructure, even when you have configured your own API key. The poisoned document then returns to your side and is loaded into the test knowledge base that the RAG application under test reads from. Check the trust boundary before you run anything: if the source document contains customer records, internal policies or unreleased material, that content leaves your environment on this step.
Document contents and the attack goal leave your environment for hosted generation, then the poisoned file returns to your test knowledge base.
Setting up a poisoning test against a test knowledge base
This sequence takes a team from a clean promptfoo install to a reviewed set of results showing whether a RAG application follows instructions planted in its documents. Each stage ends with a check, so problems surface before the test runs against anything that matters.
Install promptfoo on a supported Node.js version
The engineer responsible for the test installs promptfoo on a workstation or CI runner that meets the requirement for Node.js 22.22.0 or newer, which is the minimum for the 0.124.1 npm release. Run the install in a dedicated project folder so the configuration and generated files stay together. The step is done when the promptfoo version command prints the installed version and the Node.js version check passes on the same machine.
Configure the RAG application as a provider
Point promptfoo at the RAG application under test by defining it as a provider in the configuration file, using an HTTP endpoint or a script that accepts a prompt and returns the answer and retrieved context. Confirm that the endpoint targets a test deployment and not production data. The step is done when a single benign question sent through the provider returns an answer that promptfoo can parse, with the retrieved sources visible if your application exposes them.
Build a non-production knowledge base
The team creates a separate knowledge base that holds only synthetic or approved documents, loaded into a test index with the same ingestion pipeline as production. Record which documents are clean and which will be poisoned later, and confirm that no production content, customer records or credentials are included. The step is done when a known question retrieves the expected clean document from the test index, which shows that ingestion and retrieval work before any attack content is added.
Review data leaving for hosted generation
Before running the poison utility, the team reviews what it sends: promptfoo's data handling documentation states that redteam poison always uses hosted generation and sends the complete document contents and the requested goal to api.promptfoo.app, even when your own API key is configured. Security and privacy owners approve that transfer for the chosen documents or choose a different test method. The step is done when a written approval names the documents allowed to leave your environment.
Generate poisoned documents with redteam poison
Run the redteam poison command against the approved clean documents and a defined goal, such as a specific instruction the application should refuse to follow. promptfoo returns poisoned variants that you add to the test knowledge base alongside the clean set, tagged so they can be traced later. The step is done when the output file lists each poisoned document with its source document and goal, and a reviewer has read every generated document before ingestion.
Load the poisoned documents and run the test
Ingest the poisoned documents into the test index using the same pipeline as the clean set, then run a promptfoo evaluation that asks questions likely to retrieve them. Keep the test identical across runs so changes in results come from the application, not the setup. The step is done when the run completes for every test case and each output is saved with the retrieved context and the answer.
Review results and confirm each finding
Read each failed and passed case, checking whether the answer followed the planted instruction, whether the poisoned document was actually retrieved, and whether the grader scored the response correctly. Record any findings with the document, query and output that show the behavior. The step is done when every flagged case has a written verdict and the team has decided which fixes to test next, such as source filtering, retrieval limits or output checks, followed by a rerun on the same test knowledge base.
Security and data handling risks to plan for
Poisoning tests create files that look like attacks and carry the content they were built from. The cards below cover where that content goes, what it contains, how the artifacts are stored and who can read the results. Plan these before the first run, not after the first finding.
Hosted generation sends document contents out
Per promptfoo's data handling documentation, redteam poison always uses hosted generation and sends the complete document contents and the requested goal to api.promptfoo.app, even when your own API key is configured. Your key does not keep the content inside your network. Before any run, confirm with your security team that this transfer is allowed for every document you plan to feed in, and record the approval with the test plan.
Keep real customer documents out of the test set
Poisoning works best when the seed document resembles the content your application already retrieves, which makes real customer files tempting. Do not use them. Build seed documents from synthetic or public content that matches the structure, headings and tone of your corpus. Illustrative example: a fictional policy handbook with the same section layout as your internal handbook, rather than a copy of the handbook itself.
Treat poisoned files as sensitive artifacts
A generated poisoned document is a working attack payload, and it may also contain fragments of the source text sent to hosted generation. Store the files in a restricted location, tag them as test artifacts, and keep them out of the production knowledge base, shared drives and general backups. Set a deletion step at the end of each test cycle so that stale payloads do not accumulate in a repository.
Isolate the test knowledge base
The poisoned documents must enter a test index that is separate from production data and that the application can reach only in a test environment. Check that the test index uses its own credentials, that ingestion pipelines cannot write poisoned content into production, and that the test application cannot reach production tools, mailboxes or customer records during a run.
Scope who can read results
Red team reports quote the injected payload, the retrieved context and the model response, which can expose sensitive wording from your own system prompt or internal policies. Limit read access to the security and application owners who need it. Confirm where reports are stored, who holds the account if you use a hosted or self-hosted promptfoo server, and how long results are kept. The Community edition does not include team access control, so plan that control separately if you need it.
Check the license and version before adoption
promptfoo is MIT licensed, and the npm release 0.124.1 requires Node.js 22.22.0 or newer. Confirm the version your pipeline pins and the runtime it needs before adding poisoning tests to a build. Review the poison command's current data handling page at the time of each upgrade, because the data path is a documented behavior that can change between releases.
Questions teams ask before testing RAG document poisoning
What drives the cost of testing RAG document poisoning with promptfoo?
The cost is set mostly by the amount of work around the scan, not by the scan itself. The main drivers are the size of the document corpus you want to cover, the number of attack goals you test, how much human review the grading needs, and how often you retest after changes. Each added document type, knowledge base or goal adds setup and review time. Promptfoo's Community edition is free under the MIT license, so software licensing is not usually the expensive part. Labor is: someone must build the test knowledge base, define goals that match your application's purpose, read the results and confirm which failures are real. Ask any partner for a quote that lists corpus size, goal count, review hours, retest rounds and who pays for hosted generation usage, if any applies to your setup.
How long does a RAG document poisoning test take?
Duration depends on the same drivers as cost: how many documents and goals are in scope, how complex the application's retrieval path is, and how quickly your team can provide a working test environment. A narrow test of one retrieval pipeline runs much faster than a test across several knowledge bases with multiple user roles. Review time often takes longer than generation. Agree on a schedule in writing before work starts, including who approves the data-handling decision and when the retest happens after fixes. Ask the provider to state the phases, dependencies on your team and the dates each deliverable is due.
What does my team need to provide before the test starts?
Three things are needed before poisoned documents are generated. First, a test knowledge base: a copy of your retrieval index or a staging corpus that holds no production records, so injected content cannot reach real users. Second, application access: a test endpoint for the chatbot or search assistant, with credentials for a test user and a way to see retrieved sources. Third, an approved data-handling decision. Promptfoo's redteam poison utility always uses hosted generation and sends complete document contents and the requested goal to api.promptfoo.app, even when your own API key is configured. Legal, privacy and security owners must approve that transfer or you must use a different method. Confirm this decision before any document leaves your environment.
Can our own team run RAG document poisoning tests with promptfoo?
Yes, a team with some engineering skill can run the tests with the open-source CLI, which is MIT licensed and runs locally. The workflow is to create poisoned documents, add them to a test knowledge base, query the application and grade whether it followed the injected instruction. The hard parts are not the commands. They are choosing realistic goals, placing payloads where your retrieval will actually surface them, keeping the test corpus isolated, and reading results with enough domain context to tell a true failure from a false alarm. Your team also needs a decision on hosted generation before running redteam poison. A partner can take on any part of this work under a written scope, or review your setup and results.
Does a clean result mean our RAG application is safe from document poisoning?
No. A clean run means the application did not follow the specific poisoned documents and goals you tested, against the corpus, retrieval settings and model version you used at that time. It does not prove that other payloads, document formats, retrieval configurations or future content will fail safely. Results also depend on the grading method, so a missed attack can come from a weak grader. Changes to the embedding model, chunking, prompts, the underlying model or the knowledge base can change behavior. Treat a clean result as evidence for a defined scope, record that scope, and retest after material changes. Testing supports compliance evidence, but it does not replace an assessment by an independent auditor.
How often should we retest after changing the knowledge base or model?
Retest whenever a change could alter what the retriever returns or how the model weighs retrieved text. Common triggers include a new document source, a change to the embedding model or chunking strategy, a new generation model or version, edits to the system prompt, and new tool access for the agent. Scheduled retests, for example before each release, are common in mature programs, and they can run in a pipeline if your team wants that. Ask any provider whether retesting after fixes is included in the fixed scope or sold as a separate retainer, and what happens if the knowledge base changes between rounds.
Which OWASP and MITRE references should our test scope cover?
Start with LLM05 Data and Model Poisoning in the OWASP Top 10 for LLM Applications 2026, which covers the poisoning risk directly, and LLM01 Prompt Injection, because injected document text often carries instructions. LLM08 Hidden Context Exposure and LLM09 Vector and Embedding Weaknesses are also relevant to retrieval. If the RAG application is part of an agent, ASI06 Memory and Context Poisoning in the OWASP Top 10 for Agentic Applications for 2026 applies. On the MITRE ATLAS side, map your goals to LLM Prompt Injection: Indirect (AML.T0051.001). Confirm the mappings your reviewers expect, since frameworks are updated and your auditors may prefer a specific edition.
Limits to confirm in your environment
Poisoned-document testing sends material outside your environment and only covers the document types and failure modes the plugin generates. The cards below list what to confirm before a test run, and what a passing result does not establish.
Hosted generation and data leaving your network
The poison plugin always uses hosted generation, even when you configure your own API key. Complete document contents and the requested goal are sent to api.promptfoo.app. Before running it, ask your data owner whether these documents may leave your environment, and whether they contain personal, customer or regulated data. If the answer is no, use synthetic or sanitized documents only, or test the retrieval pipeline with a different poisoning method.
Data handling docsNode.js version requirement
The current npm release of promptfoo, 0.124.1, requires Node.js 22.22.0 or newer. Confirm that the runner image, developer workstations and CI agents that will run the test meet that minimum, and pin the version you tested with so that results stay comparable between runs. Older Node.js images in shared build pools are a common cause of failed installs.
Coverage against your document types
The poisoning utility generates content for the documents it is given, but its coverage of your formats is not something to assume. Check how your pipeline parses PDFs, scanned images, spreadsheets, HTML and email attachments, and confirm that the poisoned text survives chunking and embedding in the same way real content does. A poisoned payload that is stripped during ingestion tests nothing about the application.
Passing tests are not an audit
A clean result from this test covers the payloads and grading criteria you chose, on the knowledge base you loaded, at the time you ran it. It does not establish that the application is secure, and it is not an audit report, attestation or certification. Where a regulator or customer asks for independent assessment, plan that work with an auditor or certification body, and use promptfoo output as supporting evidence only.
Retention and access to results
Results from a poisoning run contain the injected documents and model responses, which may themselves hold sensitive material. Confirm where the output files are written, who can read them, how long they are kept and whether they are copied into shared CI artifacts. Self-hosted promptfoo stores data in a local SQLite database that is not recommended for production use, so decide the storage location before the first run.
What to do with a failed poisoning test
A failed poisoning test means the application followed instructions that arrived inside a retrieved document. The first decision is where to fix it, because the control that matters most usually sits outside promptfoo. Promptfoo reports the failure, but it does not change your retrieval pipeline, your prompt template or your ingestion rules. Start with source filtering and provenance: decide which document sources may enter the knowledge base at all, record who approved each one and keep that metadata with every chunk so the application and reviewers can trace an answer back to its origin. Then check whether the prompt separates retrieved text from instructions. Retrieved content should be labeled as data in the prompt, and the system instructions should state that nothing inside that data can change the task, the tools or the output format. Output checks come last: validate that answers stay within the expected format and that cited sources match what was retrieved, so a poisoned chunk that slips through has less room to cause harm.
Map the findings to the OWASP Top 10 for LLM Applications 2026. The poisoning payload is a prompt injection case, so the relevant entry is LLM01 Prompt Injection, and the knowledge base contamination itself falls under LLM05 Data and Model Poisoning. Be precise about what the test covers. A poisoning test shows whether this application, with this retrieval setup and model, obeyed a planted instruction on the documents you supplied. It does not establish that the knowledge base is clean, that every ingestion path is controlled or that LLM05 is addressed across the organization. Record that boundary in the findings report so nobody reads a pass as broader assurance. Confirm with your own security team which control owners will act on each finding.
After each change, run the same poisoning suite again against the same knowledge base and the same model version, then compare results. Keep the configuration file, the generated documents and the outputs as evidence, and note any change to the model, embedding setting or chunking rule, since each can change the result. Also confirm the data path before you run the test on any real content. The redteam poison utility always uses hosted generation and sends the complete document contents and the requested goal to api.promptfoo.app, even when your own API key is configured. Use only test documents or sanitized copies in that run, and review the promptfoo data handling documentation with your privacy and compliance teams before the first run.
How DeployOpen scopes and delivers RAG poisoning tests
DeployOpen plans and runs promptfoo RAG poisoning tests inside the client's own environment, with a written scope that defines which knowledge base, application endpoint and documents are in play. The work is documented so the client's security and engineering teams can rerun it and decide what to fix.
How we scope
- Engagements are fixed-scope, with the knowledge base, retrieval pipeline and target endpoint agreed in writing before work starts.
- The scope records which document types and goals are tested, and whether hosted generation is approved for poisoned content.
- Scope also states what counts as a pass, so the client knows which application behavior is accepted and which is a finding.
How we build
- We configure a test knowledge base that mirrors production ingestion, using a copy of your document pipeline rather than live data.
- Poisoned documents are generated, reviewed by the client for sensitivity, then added to the test corpus with traceable identifiers.
- The application is connected as a promptfoo target, and each run is recorded so results can be reproduced after a fix.
How we hand over
- You receive the promptfoo configuration, the poisoned document set, the generation records and the outbound data inventory.
- The findings report lists each case the application followed, with the retrieved context, the expected behavior and a suggested fix.
- A retest runs after fixes are applied, and the final run is documented as evidence for your own review.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers, including reruns when the corpus or model changes.
- Support covers updates to promptfoo versions and configuration, so the test suite keeps working as the application evolves.
- Your team keeps ownership of the test assets, and the retainer scope is agreed in writing before any recurring work begins.

