Testing RAG applications for indirect prompt injection with garak

garak's latent injection probes hide instructions in resumes, reports, translations and WHOIS records to test whether your retrieval pipeline follows text it should only read.

On this page

Testing RAG applications for indirect prompt injection with garak

A team running a retrieval pipeline needs to know whether text pulled from its document store can steer the model, even when the user never typed anything hostile. garak's latentinjection module answers that question by burying instructions inside content a retrieval system would plausibly return, such as a resume, a financial report, a legal fact snippet, a translation task or a WHOIS record, and then checking whether the model follows them. The module is part of garak, the Generative AI Red-teaming and Assessment Kit, which is licensed under Apache 2.0 and developed in the NVIDIA GitHub organization. The latest release at the time of writing is v0.17.1, released on 16 October 2026, so confirm the version you install against the garak releases page before you pin it in your scan environment.

The module's probes are a useful fit for RAG because they mirror the way injected text reaches a model. A resume or report in a knowledge base is not an attack from the user's side, yet once retrieved it sits in the same context window as the system prompt and the question. Run the scan when you add a new document source, change chunking or ranking, add a summarization or extraction step over retrieved text, or give the model any tool that acts on its output. Also rerun it after a model swap, since the same pipeline can behave differently on another model. Before the first run, confirm with your engineers which fields of the RAG endpoint the probes will reach, because a scan that only sends prompts to the model and skips retrieval will miss the path you care about.

Treat a FAIL as evidence about the whole pipeline, not only the model. A hit can mean the model followed an instruction it should have ignored, but it can also mean your prompt template gave retrieved text the same authority as your own instructions. Record which probes failed, the model and retrieval configuration under test, and the retrieved context that surrounded the attempt, since garak's report shows the attempt and its evaluation but not your application's design choices. Decide in advance who owns triage: the team that maintains prompts, the team that controls ingestion, or both. A clean result is also limited evidence, because garak samples a fixed set of injected payloads, and it does not prove that every document in your corpus is safe.

Where the scan enters a RAG request flow

The scan starts at garak's REST generator, which sends each probe as a user query to the full RAG endpoint, not to the model alone. The query passes through the retriever, which pulls matching passages from the document store, including any documents that carry injected text. Prompt assembly then joins the user query, retrieved passages and system instructions into one prompt for the model. Check the response for whether the model followed the instructions hidden in the retrieved content, because that is the failure the latent injection probes are looking for.

garak sends probes through the whole RAG path, with retrieved content as the untrusted zone.

Choosing what garak should test: the model or the full RAG endpoint

Pointing garak at the model directly uses a built-in generator such as the Hugging Face, OpenAI API or LiteLLM generators. garak then sends its latent injection prompts straight to the model, with no retrieval step, no document store and no application prompt template around the request. This answers a narrow question: does the model itself follow instructions that appear inside text it is asked to process? That is useful for model selection and for comparing versions, because the same probe set can be run against each candidate. It cannot show what your application does with retrieved content, since none of your chunking, ranking, system prompt or output handling is in the path.

  • Isolates the model: Results reflect model behavior alone, which helps when comparing candidate models on the same probes.
  • Easy to repeat: Changing the model name is the only configuration change needed between runs.
  • Misses retrieval effects: Injected text that never reaches the model through your retriever is not tested.
  • No application prompt: Your system prompt and instruction hierarchy are absent, so a pass may overstate your protection.
  • Model-level findings only: A failure tells you the model is susceptible, not that a user can exploit your product.

Before relying on a bare model result, confirm which model version and inference settings your production endpoint actually uses.

Configuration options and when each fits

This table compares the main garak settings you will choose when pointing latentinjection probes at a full RAG endpoint, from the REST generator fields to the report outputs. Read each row as a decision: what the option controls, when it fits, and what to confirm with the team that owns the endpoint before the first run.

OptionWhat it controlsWhen it fitsWhat to confirm in the endpoint contract
REST generator YAML fieldsHow garak sends prompts to the RAG endpoint and reads the reply as plaintext or JSONAny RAG service reachable over REST, where the retrieval and generation sit behind one HTTP callThe request body shape, where the prompt is inserted, which JSON field holds the answer, and the authentication header
Probe selection for latentinjectionWhich latent injection probes run, such as resume, financial report, translation and WHOIS-style payloadsTesting whether retrieved documents carrying hidden instructions change the model's behaviorWhether the endpoint retrieves from a corpus you can seed with test documents, or only accepts user input
Generations per prompt (default 5)How many times each prompt is sent, so intermittent injection successes are caughtInitial runs where you want to see whether any attempt succeeds, or cost and rate limits are not a concernRate limits, per-call cost and whether the endpoint keeps conversation state between generations
Default probewise harnessRuns each selected probe with the detectors it recommends and records a pass or failFirst scans, when you want a standard baseline before custom detectors or tuningWhether recommended detectors match what counts as a failure for your application's answers
Recommended detectorsScores each output for signs that the injected instruction was followedConfirming that the model obeyed the buried text rather than answering the user's questionWhether the detector can see the injected output in the field garak reads from the response
JSONL reportEvery attempt, its prompt, output and evaluation, one record per lineEvidence for review, reruns and comparisons across endpoint changesWhere reports are stored and who may read them, since they hold prompts and model outputs
garak.log fileDebugging detail that continues across runsTroubleshooting failed connections, parsing errors or unexpected responsesLog retention rules and whether logs may contain sensitive document text

Setup sequence for a RAG endpoint scan

This sequence takes a RAG application from an unconfigured workstation to a reviewed garak report that shows whether the retrieval pipeline follows instructions hidden in documents. Each step ends with a check, so a failure is caught before the next step depends on it.

  1. Install garak from PyPI

    The scan operator, usually a security engineer on a dedicated test host, creates a virtual environment on Python 3.11 or newer and installs garak with pip from PyPI. garak is a command-line tool developed on Linux and macOS, so a Linux or macOS host is the safer starting point. Confirm the install by running the garak help command and checking that the version printed matches the release your team has agreed to test with. A clean help output with the expected version means the tool is ready.

  2. Confirm the endpoint request and response format

    Before writing any configuration, the application owner and the scan operator capture one real request to the RAG endpoint, using a test account and a benign question. Record the request body shape, the header used for authentication, where the user question is placed, and where the generated answer appears in the response. Note whether the response is plaintext or JSON and whether the endpoint returns retrieved source snippets alongside the answer. This is done when you have a saved example request and response that both teams have reviewed.

  3. Write the REST generator YAML

    Using the request and response details from the previous step, the scan operator writes a short YAML file that describes the endpoint to garak's REST generator. The file sets the URL, headers, the request template with a placeholder for the prompt, and the path to the answer text in the response. Store the file in version control and keep credentials out of it by reading them from environment variables. Confirm the setup by running a single benign prompt through the generator and checking that the reply printed by garak matches the answer the endpoint gave in your manual test.

  4. Seed the test corpus with a benign canary

    The application owner loads a small set of test documents into a non-production knowledge base, such as a resume, a financial report, and a WHOIS-style record, each containing a harmless canary instruction that asks the model to output a unique marker string. The canary must be harmless and easy to recognize, and the documents must be indexed by the same embedding and retrieval settings used in production. Confirm the seed by running a retrieval query that should return one of the planted documents and checking that the snippet appears in the retrieved context.

  5. Run the latentinjection probes

    The scan operator runs garak's latentinjection probes against the configured generator, pointing the scan at the RAG endpoint rather than a bare model so retrieval is part of the test. Keep the default generations per prompt unless the team has a documented reason to change it, and save the run with a clear name so it can be compared later. Confirm the run completed without generator errors by checking garak.log for connection or parsing failures before reading any results.

  6. Review the JSONL report

    The scan operator opens the JSONL report that garak wrote for the run and reviews each attempt alongside its evaluation. Look for attempts where the marker string from the canary appears in the endpoint's answer, and check whether the retrieved context for those attempts contained the planted document. Record the probes that failed, the failure rates reported, and any attempts that look like false positives. The step is complete when each flagged result has been traced to a document and a reviewer has signed off on the findings.

Security and operational considerations for the test

A RAG scan sends adversarial documents through a live retrieval path and generates many model responses, so the test itself can expose data, spend budget or reach real users. The cards below cover the decisions to make before the first probe runs and the records to keep once it finishes.

Use a non-production index

Point the scan at a staging index loaded only with synthetic documents that you write for the test. Latent injection payloads are meant to be retrieved, so any document the index serves can be read back in model output. Confirm that the staging retriever cannot reach production vector stores, and that the synthetic corpus mirrors the document shapes your production index holds (resumes, reports, translations, registry records) without copying their content.

Handle real data the retriever touches

If the staging index must contain real documents, treat the whole scan as processing sensitive data. Check which tenants, customers or employees own the documents, whether your data handling terms allow them to be sent to the model endpoint under test, and whether the endpoint logs prompts. Remove or mask personal fields before ingestion where you can.

Scope endpoint credentials

The REST generator configuration holds the credentials garak uses to call your RAG endpoint. Issue a dedicated, short-lived service credential with access only to the staging application, and keep it out of the YAML file committed to source control. Ask the team that owns the endpoint whether the credential can trigger tool calls, write to storage or send email, because injected text can make the model attempt those actions.

Plan rate limits and repeated generations

Each probe runs several generations per prompt by default, and the latent injection probes multiply across many payloads, so the request count can climb quickly. Ask the endpoint owner for the rate limit and the per-request cost of the model and any reranker or embedding calls. Set generation counts and probe selection so the run stays inside those limits, and record the request total so repeat scans can be budgeted.

Default generations per prompt
5

Store reports as sensitive output

The JSONL report and the garak.log file record every prompt and model response, and a successful injection may quote retrieved document text or internal instructions. Store them in access-controlled storage with a retention period set by your security team, not in shared build artifacts. Review the log for copies of real data before sharing a report outside the test team.

Keep traffic off production

Confirm the target URL resolves to staging before the first run, since a copied configuration can point at production with the same credentials. Restrict the scan host's network egress to the staging endpoint, and tell the on-call team when the scan window starts so alerts from unusual query volume are not treated as an attack on live users. Verify the target in the first few log lines of the run.

Questions teams ask before testing RAG injection with garak

Is garak free to use?

Yes. garak is licensed under the Apache 2.0 license, and its maintainers describe it as a free tool. The license covers the tool itself, not the cost of the work around it. Your team still pays for the time to configure the endpoint, prepare a test corpus, run scans and read the results, and for any hosted model calls the scans make against your endpoint. Ask a partner to separate those costs in a quote, and confirm the license terms with your legal team before adoption.

How long does a RAG injection scan take?

The duration depends mainly on three things: how complex the endpoint is, how many probe prompts run, and how many generations each prompt gets. garak makes 5 generations per prompt by default, so each additional generation multiplies the number of model calls your endpoint receives. A single REST endpoint that returns plain text is quick to wire up. A pipeline with retrieval, reranking, tool calls and a guardrail in front takes longer to configure and verify. Ask for a written scope that states the endpoint shape, the probe set and the generation count, because those three decisions set the effort.

What does the team need to provide for the scan?

Three things make the work start quickly:

  • Endpoint access: a non-production URL for the full RAG pipeline, with credentials and a request and response format that garak's REST generator can handle as plaintext or JSON.
  • A test corpus: documents, resumes, reports or web records that represent what your retrieval layer actually ingests, so the injected text reaches the model through the same path as real content.
  • Someone who can read JSONL reports: the run writes a JSONL file of every attempt and its evaluation, and a person must interpret those results and decide what counts as a real failure in your application.
Can our own engineers run garak against a RAG endpoint?

Yes, a platform or security engineer who can run Python tools can install garak from PyPI and configure a REST generator in a short YAML file. garak requires Python 3.11 or newer and is developed on Linux and macOS. The harder part is the design of the test: choosing which latent injection probes match your ingestion sources, making sure the injected text reaches the retrieval index, and interpreting what a failure means for your application. Teams often run a first pass in-house to learn the tool, then bring in help for the endpoint wiring and the review of findings.

How does garak test injected text in documents?

garak's latentinjection module places prompt injections inside other content, such as a resume, financial report, legal fact snippet, translation task or WHOIS record. The idea is to check whether the model follows an instruction it found in data it was asked to summarize or answer from, rather than the user's question. For a RAG application, the question to answer is whether the retrieval step surfaces that content and whether the generator obeys it. Read the probe source in the garak repository to see the exact templates before you decide which ones match your document types.

When should we bring in an outside partner for RAG injection testing?

Bring in a partner when the RAG system holds sensitive data, reaches internal tools, or feeds an agent that can take actions, because a failed injection there has consequences beyond a bad answer. Outside help also makes sense when your team lacks time to build the endpoint wiring, when a regulator or customer security review asks for documented testing, or when you need a retest after fixes. DeployOpen plans and runs fixed-scope engagements, with scope, deliverables and timelines agreed in writing before work starts, and offers retainers for continuous testing. Independent auditors, not DeployOpen, issue any audit reports or certifications.

Do garak results prove our RAG pipeline is safe?

No. A scan shows whether the probes you ran produced undesirable output under the settings you chose. A pass on one probe set does not show that no injection path exists, since attackers can rephrase instructions, use other document types and chain steps. Treat results as evidence of what was tested, with the endpoint, probe names, generation count and version recorded for each run. Tell stakeholders which probe families were excluded and why, and rerun after changes to the retrieval layer, the prompt template or the model.

What to do with a FAIL in a RAG pipeline

Treat a FAIL from a latent injection probe as a question about the pipeline, not a verdict on the model. Start by confirming the injected text actually reached the model context. Pull the JSONL report entries for the failing attempts and compare the prompt that garak sent with what your retriever returned and what your prompt template assembled. If the payload was dropped by chunking, truncated by a context limit, or never retrieved, the failure is a retrieval or assembly issue and the model never had a fair chance to refuse. Only when the text is present in the final prompt does the result show that the model followed embedded instructions.

Next, decide where to intervene. Prompt assembly changes are the cheapest first step: clearly delimit retrieved documents as data, state in the system prompt that instructions inside documents are not to be executed, and keep user and system roles separate. Retrieval filtering narrows what enters the context, for example by stripping or quarantining documents from untrusted sources before indexing. Output checks inspect what the model returns before it reaches a user or downstream system. Tool permission limits matter most for agents: restrict which tools the model can call from a retrieval turn, scope credentials to read-only actions where possible, and require confirmation for anything that sends data or changes state. Choose the layer that stops the harmful action, and record the reasoning.

Finally, rerun the same probes, with the same generations, detectors and endpoint configuration, after each change. Compare failure rates in the reports against the baseline rather than relying on one passing run, because the default of 5 generations per prompt means a single clean result proves little. Confirm which changes moved the numbers and which only moved the output format. Ask your vendor or internal platform team to confirm how the RAG framework handles document delimiters and metadata, since those settings often determine whether the fixes take effect.

How DeployOpen scopes and delivers RAG injection testing

DeployOpen plans and runs indirect prompt injection testing of a RAG application as a fixed-scope engagement, starting from the full retrieval path rather than the bare model. The work covers the document sources, the retriever, the prompt assembly and the endpoint users actually call, with results documented so your security and engineering teams can act on them.

How we scope

  • Written scope names the RAG endpoint, document sources, retrieval stack and the user roles that can reach it.
  • We agree which latent injection probe families apply, such as resume, report, translation and WHOIS-style carriers.
  • Scope states the test accounts, sample corpus, rate limits and hours the scan may run against your environment.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before any testing starts.

How we build

  • We deploy garak in your test environment and configure a REST generator for the RAG endpoint from a short YAML file.
  • Planted documents are seeded into a test knowledge base so retrieval, not just the model, decides what reaches the prompt.
  • Each run uses garak's default probewise harness, with detector results checked by hand on a sample of flagged attempts.
  • We record run settings, probe versions and endpoint configuration so every scan can be repeated after a change.

How we hand over

  • Deliverables include the JSONL reports, the garak.log files and a findings write-up for each failed probe family.
  • Each finding maps to the retrieval step, prompt template or tool permission that let injected text through.
  • We provide fix recommendations for ingestion, output handling and privilege limits, then retest the affected probes.
  • Your team receives a runbook for rerunning the scan, including what to confirm with the vendor after a garak upgrade.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the initial engagement.
  • A retainer can schedule rescans after new documents, model swaps or prompt template changes.
  • Support covers garak version upgrades, so report comparisons stay meaningful across releases.
  • Ask for a quote that lists the scan hours, retest rounds, and who on your side reviews results.

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.