Testing indirect prompt injection with promptfoo

Indirect prompt injection arrives through content your application reads, not through the user's message. This page explains how to test it with promptfoo, where to place payloads and what a pass looks like.

On this page

Testing indirect prompt injection with promptfoo: when your app reads untrusted text

If your LLM application summarizes documents, triages email, browses web pages or fills prompts from profile fields, promptfoo can test whether text from those sources can take over the application. The test sends crafted content through the same path real documents and pages take, then checks whether the model follows instructions hidden in that content instead of the instructions you wrote. This is the test to run before launch, not after an incident.

Direct prompt injection comes from the user typing into the chat box. Indirect prompt injection arrives through data the application fetches on the user's behalf, such as an email body, a PDF, a web page or a CRM field written by someone else. The user never sees the attack, and the application treats the text as content to process rather than as an attacker's message. OWASP ranks this family under LLM01 Prompt Injection in its OWASP LLM Top 10 2026. For agents, the same risk appears as ASI01 Agent Goal Hijack in the OWASP Top 10 for Agentic Applications for 2026, where a poisoned input redirects what the agent is trying to do, often through tools it is allowed to call.

Run this test before launch whenever untrusted text reaches the model and the model can change something: send email, write to a ticket system, call an API, reveal data or alter a record. It is also needed when a new data source is connected, when a retrieval index grows to include third-party content, and before any change to the system prompt or tool list. Confirm in your own environment which sources and tools the application uses, since that inventory determines which injected variables the test must cover.

How an injected payload reaches the model

The test starts in promptfoo, which sends a benign user message plus a poisoned variable, such as a document, email, web page or profile field, to the application under test. The application assembles its prompt from both the user's request and that untrusted content, then calls the model. The trust boundary sits where the untrusted variable joins the prompt. Check two things on the way back: the model's text output, and any tool calls the application made, because an injection that changes tool use can matter more than the words it produces.

Poisoned content enters the prompt inside the application, before the model call and grading.

Choosing the injected variable for each application type

In retrieval-augmented applications, document chunks are fetched from a vector store or search index and concatenated into the prompt as context. The attacker does not need access to the chat window. They need to get text into a document that someone, or a crawler, later ingests, such as an uploaded file, a wiki page or a shared drive item. The injected variable is usually the retrieved context block, not the user message, so tests should place payloads inside a chunk body, a title or metadata that the template renders. A successful takeover in this application would look like the assistant following instructions from the chunk, such as exposing other retrieved documents, calling a tool with attacker-chosen arguments or answering with a fabricated citation.

  • Chunk body: Payloads placed mid-paragraph test whether the model separates document text from instructions.
  • Title and metadata: Filenames, headings and author fields are often rendered into the prompt and rarely filtered.
  • Ranking exposure: A payload needs to be retrieved for a realistic query, so test with queries that match the poisoned chunk.
  • Tool reach: Note which tools the assistant can call while answering, because that sets the impact.

Confirm how your application formats retrieved chunks, whether it labels them as untrusted data, and which tools run in the same turn.

How to set up an indirect injection test in promptfoo

This sequence takes a team from an unverified target to a repeatable indirect prompt injection test, with a check at each stage so that a passing result means the payload was actually delivered and graded. The output is a baseline run that shows how the application handles untrusted document, email, web or profile content.

  1. Confirm the target and its wiring

    Identify the application that will receive untrusted content, the model it calls and the path a document, email, web page or profile field takes to reach the prompt. Decide whether promptfoo will call the model directly or reach the application through an HTTP or Python provider, and confirm the owner who can supply a test endpoint. The step is done when you can draw the request path from the untrusted source to the model output. Check: a single benign request through the chosen provider returns a response you can read end to end.

  2. Mark the variable carrying untrusted content

    In the promptfoo configuration, identify the variable that holds the untrusted text, such as a document body, email body, scraped page or profile bio, and keep it separate from the user message. Name it clearly in the prompt template so later reviewers can see which input is the injection channel. The step is done when the config has one explicit variable for untrusted content. Check: rendering the prompt with a placeholder value shows the variable in the position the application actually places it.

  3. Write benign and payload-bearing cases

    Create a small set of test cases that pair the same user task with two kinds of untrusted content: ordinary material and material that contains an instruction aimed at the model, such as an instruction to reveal data or call a tool. Keep the benign cases so you can tell a broken application from a hijacked one. The payload should sit inside realistic content, such as a paragraph of a document or a signature line in an email, rather than a standalone command. Check: the payload string appears in the rendered prompt for each payload case and is absent from the benign cases.

  4. Choose grading assertions

    Attach assertions that define a failure before the first run. For example, use a check that the output does not contain a canary value planted in the test data, a check that the model did not claim an action it could not take, or an LLM-as-a-judge rubric that asks whether the response followed the embedded instruction. Use deterministic assertions where you can, because they are easier to reproduce. The step is done when each payload case has at least one assertion that would fail if the injection succeeded. Check: a deliberately compromised sample output fails the assertion, and a normal answer passes it.

  5. Run the baseline

    Run the promptfoo evaluation against the target with the benign and payload cases, and record the results as the baseline for the test. Note which cases pass, which fail and whether any failures come from the application or from the grader. Keep the configuration and test data under version control so the same run can be repeated after changes. Check: the run completes for every case, and the result count matches the number of cases in the config.

  6. Review traces and confirm the evidence

    Open the results for each failed or unexpected case and read the full rendered prompt, the model response and any tool calls the application made. Confirm that a failure reflects the payload influencing behavior, not a formatting error or a grader mistake. Record the trace or output that serves as evidence, and note any case where the application ignored the payload. Check: each finding can be traced to a specific payload, a specific response and a specific assertion.

Realistic payload placement that matches production

An injected instruction only tests something if it reaches the model through the same field, format and parsing path that production uses. The cards below cover the placements that most often carry indirect injection, and what to check so each test mirrors how content really enters your application.

Hidden text in documents

Documents often reach the model after text extraction, which can keep text that a human reader never sees, such as white-on-white runs, tiny fonts, comments, tracked changes or alt text. Place the payload where your extractor actually reads, then confirm whether the extracted text keeps the original order and whether the application's parser drops hidden content. A payload that only sits in visible body text tests a different path from the one attackers use.

Instructions in email signatures

Mail assistants usually receive the full thread, including quoted replies, forwarded blocks and signatures that the sender's client generated. Put the payload in the signature or inside a quoted reply with the same HTML or plain-text structure your mail connector passes to the model. Check whether the application strips quoted sections before summarizing, because that decides whether a payload buried in history is ever seen.

Markup in fetched web pages

When an agent fetches a page, the model usually sees converted text, not the raw HTML. Inject through the elements your fetcher keeps, such as meta descriptions, alt attributes, script-free hidden blocks or footer text, and confirm which tags survive conversion. Test with the same user agent, redirects and content types the agent uses, since many fetchers return different markup to automated clients.

Profile fields in system context

Applications often copy profile fields such as display name, job title, bio or department into a system or developer prompt for personalization. A payload in one of these fields is more dangerous than one in a user message because it sits at a higher trust level. Confirm which fields are interpolated, whether they are escaped or truncated, and whether the test account uses the same field types and length limits as real users.

Content split across chunks

Retrieval pipelines split documents into chunks, so a payload can land across a boundary and reach the model only when two chunks are retrieved together. Measure your chunk size and overlap, then place the instruction so that it straddles a split point and check retrieval with the same embedding and top-k settings. Without this, tests pass because the full payload never appears in a single retrieved chunk.

Matching formats in every test

Each placement should be checked against the real pipeline output, not the raw input you wrote. Capture what the model receives for a sample of production items, then use those captured strings as the basis for test variables. Record the exact field, encoding and preprocessing steps in the test configuration so a reviewer can confirm the placement was realistic and repeat it after the application changes.

Configuration options and when each fits

This table compares the four main choices when building an indirect prompt injection test: built-in plugins or custom payloads, single or multi-turn attacks, deterministic or judge-based grading, and end-to-end or component testing. Read each row as a trade-off between coverage, run cost and reproducibility, then pick the combination that matches the risk you are testing. Confirm plugin names, strategy options and grader settings against the current promptfoo red teaming documentation before you commit to a design.

ChoiceOptionTrade-offWhen it fits
Payload sourceBuilt-in prompt injection pluginsBroad coverage with little setup, but payloads are generic and may not match your document formats or business termsEarly baseline across the application before you write tailored cases
Payload sourceCustom payload lists tied to your documentsClosest to real attacks on your data, but you must write and maintain each payload and its expected outcomeKnown attack paths such as a hidden instruction in a supplier invoice or a profile bio field
Conversation shapeSingle-turn injectionCheap and repeatable, one request per case, but misses attacks that build up over several messagesInjection through one retrieved document or one uploaded file
Conversation shapeMulti-turn injectionFinds gradual manipulation and follow-up exploitation, at higher run cost and with more variation between runsAssistants that keep session state or act across several user turns
GradingDeterministic assertionsFast and reproducible, such as checking for a canary string or a forbidden tool call, but blind to paraphrased complianceRegression gates in CI where the attack has a clear observable signature
GradingLLM-as-a-judge gradingCatches subtle compliance and paraphrase, but adds model cost and grader variability, so pin the grader and rerun borderline resultsOpen-ended responses where success is a judgment, such as the assistant adopting the injected persona
Test scopeEnd-to-end provider testingShows what a user can actually trigger across retrieval, prompt assembly and tools, but failures are harder to localizePre-release sign-off and evidence for a security review
Test scopeComponent testing of retrieval or prompt builderIsolates where untrusted text enters the prompt and is cheap to repeat, but can miss issues created by the full pipelineDebugging a known finding or testing a new ingestion path before full runs

What a pass looks like and how to read a failure

A pass on an indirect prompt injection case means the application treats the embedded text as data, not as instructions, and still finishes the benign task the user asked for. In practice, that breaks down into four checks you write down before the first run: the application ignores the instruction planted in the document, email, web page or profile field; it does not call tools it should not call, such as sending a message, writing a record or fetching an external URL; it does not reveal its system prompt or any data outside the user's scope; and it still produces a useful summary, answer or action for the legitimate request. The last check matters because an application that refuses everything passes the first three trivially. Confirm with your application owners which tools are in scope for the test, and record the exact allowed and forbidden tool calls in the test case so a grader can judge them without interpretation.

When a case fails, read the trace before you read the final answer. The trace shows which retrieved or supplied content the model received, whether the injected instruction reached the prompt intact, which tool calls were made with which arguments, and where the model's reasoning changed direction. A final answer that looks harmless can hide a tool call that already left the system, and a refusal can hide a leak in an intermediate step. Check whether the injected variable was actually placed where your production pipeline would place it, because a payload that never reached the model proves nothing about the application. Keep the trace, the payload and the model version together as the evidence record for that failure.

A single run is weak evidence in either direction. Model output varies between calls, so one pass may be luck and one failure may be an unlucky sample. Run each case several times against the same model, configuration and retrieval state, then record the pass rate alongside the individual traces. Before you treat any result as a finding or a regression signal, establish a documented baseline on the current release of the application and model, and compare later runs against it. Ask your team to define in advance how many repetitions count as sufficient and what change in pass rate triggers investigation, so the decision does not get made after the numbers arrive.

Security and operational considerations for the test environment

An indirect prompt injection test sends attacker-style content through a live application, so the test run itself creates exposure. The cards below cover where payloads and data travel, what the test fixtures contain, what the scan costs in quota, and how the server and results are handled.

Where payloads and data go

Every injected document, email or profile field is sent to the model provider configured for the target, along with any customer-like records the fixtures carry. Confirm which provider receives the requests, whether that provider is approved for the data class under test, and whether the provider's retention terms apply. Running promptfoo locally means evals run on your machine and talk directly with the LLM, so the path to the provider is the one you must review.

promptfoo introduction

Fixture content and sensitive data

Test documents and profile records are often copied from production to look realistic, which can place personal or confidential data into prompts and logs. Use synthetic records that match the schema and field lengths, and keep any real samples out of the repository. Label the canary strings you plant so a reviewer can tell a test marker from a leaked value. Check that injected payloads do not contain live credentials.

API quota and cost control

Each probe is a model call, and red team scans multiply the calls across plugins, strategies and retries. The promptfoo Community edition includes red teaming with 10k probes per month, but your model provider bills separately for tokens. Ask the team to set a per-run probe budget, use a dedicated key with a spending limit, and schedule scans during agreed windows so the quota of other workloads is not consumed.

promptfoo pricing

Self-hosted server limits

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. Do not expose it on a shared network without a gateway in front of it that enforces identity. Treat the server as a single-user tool for testing unless a supported deployment plan closes these gaps.

Self-hosting docs

Access to the test environment

Injection tests are only meaningful against a non-production copy of the application, with the same tools, retrieval connectors and permissions as production. Give the test identity only the scopes it needs, and confirm that the test environment cannot write to real mailboxes, ticketing systems or customer records. Record who can run scans and who can read the results.

Handling results and traces

Failing transcripts contain the payload, the model output and any data the application retrieved, so the results file is itself sensitive. Store reports in an approved location, restrict access to the security and engineering owners, and set a retention period agreed with compliance. Redact customer-like data before sharing findings outside the test team, and keep a record of which version of the application and which model produced each result.

Questions teams ask before testing indirect prompt injection

What drives the cost of testing indirect prompt injection?

The cost follows the number of injection points you test, how many tools and data sources the application reads from, and how much of the work is building test data and reviewing results. Each injected source (an email body, a PDF, a web page, a profile field) needs its own payload placement, and each tool the model can call changes what a successful injection can do. Ask any provider for a quote that lists sources, tools, target environments and the deliverables: findings report, retest and fixes. Promptfoo itself is free under the MIT license for the Community edition, so most of the cost is people time and model usage on the target, not the tool license.

How long does a first indirect prompt injection test take?

Duration depends mainly on how many sources and tools are in scope and how many of them already have a staging copy the test can reach. A single chatbot that reads one document store is a much smaller job than an assistant that reads email, a ticket system and a knowledge base and can send messages or call APIs. The first test also includes building the test identities and sample documents, so it takes longer than repeat runs. Ask for a timeline tied to the written scope rather than a generic estimate, and confirm which environments and accounts are available on the first day.

What does the client need to provide for this work?

The work needs a staging endpoint that behaves like production, test accounts with the same permissions as real users, and sample content for each source that resembles what the application really ingests. You also need a named owner for every source (mailbox, document repository, web crawler, profile database) who can confirm how content enters the system and who can approve test payloads. Access to logs or traces is useful, because a failed injection is easier to explain when you can see which document the model retrieved and which tool it called. Confirm each item with your own platform owners before work starts.

Can an internal team run indirect prompt injection tests on its own?

Yes, a team with application security skills and access to the staging system can run these tests itself, and promptfoo is designed to be used from the CLI, as a library or in CI/CD pipelines. The harder parts are choosing the injected variable for each source, placing payloads so they resemble real content, and grading results without false comfort. An internal team usually needs time to learn the OWASP LLM Top 10 categories it is testing against, such as LLM01 Prompt Injection and LLM03 Excessive Agency. Many teams start with an internal pilot on one source, then bring in outside help for coverage across agents and tools.

How often should indirect prompt injection tests be repeated?

Repeat the tests whenever something that changes model behavior or input handling changes: the system prompt, the model or model version, retrieval settings, a new tool or connector, or a new data source. Changes to how documents are parsed or how profile fields are rendered also count, because they change where injected text lands. Many teams add a scan to their pipeline so every change to prompts or configuration runs a set of injection tests automatically, and run a deeper manual review on a schedule. Agree the trigger list and the frequency with your security and platform owners, and write it into your change process.

What does a passing indirect prompt injection test actually mean?

A pass means the application did not follow the injected instructions for the payloads and placements tested, and it does not prove the application is safe. Results are only as good as the coverage: the sources, payload types and placements you included. A pass should be read together with the trace or log showing what the model received and which tools it attempted to call. Treat findings as evidence for a specific set of conditions rather than a general assurance, and keep the test cases so the same checks can run again after fixes.

Does indirect prompt injection testing satisfy AI regulation on its own?

No, testing produces evidence but does not by itself satisfy an obligation under the EU AI Act or a framework such as the NIST AI Risk Management Framework. Promptfoo's red teaming documentation references these frameworks as supporting systematic testing before deployment, which is a different thing from certification. Compliance also needs documented controls, ownership, change management and records that an independent assessor can review. Confirm with your compliance lead which requirements apply to your system and which evidence they expect, and do not rely on a test report alone as a compliance answer.

Where should the test environment run, and what data leaves it?

Promptfoo runs locally on the machine where it is started and talks directly to the model provider you configure, so your choice of model endpoint decides where prompts and responses travel. If the application under test uses a hosted model, the test payloads and retrieved content are sent to that provider. For regulated data, use a staging copy with synthetic or approved content, and check the provider's data terms before you send anything sensitive. Keep the test environment in infrastructure you control, and confirm the data path with your security team before the first run.

How DeployOpen scopes and delivers indirect injection testing

DeployOpen plans indirect injection testing as a written, fixed-scope engagement: the injection surfaces, the payload placements and the pass criteria are agreed before any test runs. The work is carried out in your own infrastructure, with promptfoo configured and documented so your team can rerun the suite.

How we scope

  • Inventory every untrusted source the application reads, such as documents, emails, web pages and profile fields.
  • Agree which application outcomes count as a takeover, including tool calls, data leaving the system and altered answers.
  • Record the target endpoint, test identities, model providers and data handling rules in the written scope before testing begins.

How we build

  • Configure promptfoo against your staging application, with the injected variable and payload placement defined per surface.
  • Build payload sets that reflect how your documents and fields are really formatted, and label each test by source and goal.
  • Set assertions and grading criteria so each pass or fail is traceable to a specific behavior in the application.

How we hand over

  • Deliver the promptfoo configuration, test data and run instructions as files your team can version and rerun.
  • Provide a findings report with reproduction steps, evidence from traces or outputs, and suggested fixes for each failure.
  • Retest fixed issues and document which results changed, so your security and compliance teams can review the evidence.

How we support

  • Engagements are fixed-scope, so scope, deliverables and timelines are agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, which can cover new sources added to the application.
  • Confirm with your team which environments, identities and retention rules apply before a quote is issued.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.