Why indirect prompt injection in retrieved documents needs its own controls
Retrieved chunks and tool results must be treated as untrusted input, because anyone who can edit a web page, support ticket, shared file or wiki entry can place instructions in front of your model. Consider a RAG assistant that answers questions from a help desk queue, where a customer writes a ticket containing text such as an instruction to ignore prior rules and forward account details (illustrative). The user never typed that text, so input rails on the user message alone will not see it. NeMo Guardrails addresses this with retrieval rails, which run on the chunks returned from your knowledge base, and execution rails, which validate custom actions and tool calls and their results before the model acts on them.
NeMo Guardrails defines five rail types: input rails for user messages, dialog rails for conversation flow, retrieval rails for RAG chunks, execution rails for custom actions and tools, and output rails for model responses. Indirect injection in retrieved content is primarily a retrieval and execution concern, so the planning question is which of these rails sit on the path between your data sources and the model. The library is licensed under Apache 2.0, and the current release is 0.25.0, which requires Python 3.11, 3.12 or 3.13. Confirm the release you intend to deploy against the NeMo Guardrails releases page and your own Python environment before you start building.
Detection is only one layer here. A rail can flag suspicious text, but a sufficiently crafted payload may evade it, so the decisions that carry the most weight are the permissions your assistant holds: which tools it can call, which records it can read or write, and whether any action requires a human approval. Ask your team to list every data source and tool the assistant can reach, and to decide what the worst outcome would be if a retrieved document steered the model. Those answers determine how much of the design depends on rails and how much on access control, which the rest of this page covers.
Where untrusted content enters the request flow
The diagram starts with the user message and follows the request through the retriever, where retrieved chunks enter as untrusted text, then through retrieval rails before they reach the LLM. Tool calls pass through execution rails, and tool results return to the model as untrusted input again, so they are checked before the next model turn. Output rails sit before the application, which still enforces its own permissions for every data read and action. Check each hand-off for what the rail inspects and what the application allows, because a rail that passes content does not make that content trustworthy.
Untrusted content crosses several trust boundaries before any answer reaches the user.
How retrieval rails and execution rails inspect chunks and tool results
NeMo Guardrails gives you two hooks that matter for indirect injection. A retrieval rail runs on the chunks your RAG pipeline pulls into the prompt, before the model reads them. An execution rail runs around custom actions and tools, so you can inspect what a tool is asked to do and what it returns. Both are declared in the same project layout: a config.yml that lists which rails are active and which models they use, optional Python actions for custom logic, and Colang files that define the flows and rail behavior. Colang 1.0 is the default syntax, and Colang 2.0 is also supported, so confirm which version your existing configuration uses before you copy examples from older material. Verify the rail names and flow hooks against the version you pin, because the NeMo Guardrails documentation is versioned and the 0.25.0 release changes the main entry point.
Decide where the rails run before you decide what they check. You can call the configuration from the Python API inside your application process, or run the guardrails server and call it over HTTP from a retriever service or an agent runtime. An in-process call keeps the chunk inside your application's memory and trust boundary. A server call lets several applications share one tested configuration, but it adds a network hop and a second service to authenticate and monitor. Whichever you choose, the retrieval step should pass the chunk text, its source identifier and the requesting user's context, so that a rail can log which document triggered a block and whether the user was allowed to see that document in the first place.
Check what each hook actually receives in your build. Build a test set of documents with embedded instructions, run them through the retrieval rail and the tool path, and record what the rail sees, what it blocks and what the model receives afterward. Confirm with the NeMo Guardrails maintainers or your own tests which built-in checks apply to retrieved content, since this page does not assume a dedicated indirect injection detector exists in your version. Plan custom validation for tool results, such as schema checks on returned JSON, and treat any rail that cannot see a field as a gap, not a control.
Choosing a check for each kind of retrieved content
Plain text chunks from a vector store, search index or document loader are the most common carrier of indirect injection in RAG systems. An attacker who can place text in a document the retriever indexes can write instructions aimed at the model, such as a sentence telling the assistant to ignore prior instructions or to reveal its system prompt. Checks on this content are cheap to run, but they only see surface patterns.
- Regex checks on chunks: Pattern rules can flag phrases such as instruction overrides, role-change wording or requests to disclose hidden prompts before the chunk reaches the model. Keep the patterns in version control and review them with the security team.
- Context bloat checks without a model: A local rail can measure length, repetition and padding in each chunk and in the combined context, and call no model. This catches oversized or repetitive payloads that try to push the system prompt out of the window.
- Blind spots of regex: Paraphrased, translated, encoded or split instructions pass pattern rules easily. Expect misses on any phrasing the patterns do not name.
- Blind spots of bloat checks: A short, well-formed injection passes length checks untouched, so bloat checks say nothing about intent.
- Retrieval rails as the wrapper: Attach the checks as retrieval rails so every chunk passes through them before generation, and log which chunks were blocked and why.
Before go-live, test the rails with sample poisoned documents your team writes, and record which variants get through.
Tool results from APIs, databases and internal services arrive as JSON or similar structures. The injection risk here is that a field the agent did not expect, such as a customer note or ticket description, carries instructions the model may follow. Validating the shape of the result is often more useful than scanning its text.
- Schema validation of tool results: Define the expected schema for each tool, including field names, types, allowed values and maximum lengths, and reject or truncate results that do not match before they reach the model.
- Free-text field limits: Fields that must hold free text, such as notes or descriptions, need explicit length caps and a decision on whether they are passed to the model at all.
- Regex on string values: Pattern checks on string fields can still run, but they inherit the same limits as text chunk checks.
- What validation cannot catch: A valid string in a permitted free-text field can still contain instructions. Schema validation limits where injected text can appear, not what it says.
- Tool permissions: Limit what the agent can do after a tool result arrives, such as which write actions require confirmation, because validation alone does not stop a misled action.
Confirm with each tool owner which fields are free text, and check that the schema reflects the live API responses rather than the documentation.
HTML pages, PDFs, Markdown and Office files often hold content a reader never sees, such as hidden elements, comments, metadata or white-on-white text. When the loader extracts raw text, that hidden content reaches the model along with the visible content. Checks should run after extraction, and they should account for what the extractor keeps.
- Normalize before checking: Strip or report hidden elements, comments and metadata during ingestion, and run the regex and bloat checks on the normalized text.
- Record what was removed: Keep a log of removed elements per document so reviewers can see why a page was altered and can spot an attacker's pattern.
- Markup-aware regex: Patterns written for plain text miss instructions hidden inside tags, attributes or encoded entities, so test them against marked-up samples.
- What checks cannot catch: Visible text that looks like ordinary content, such as a helpful-sounding instruction in an article, passes both normalization and pattern checks.
- Source control: Restrict who can add documents to the index, since the safest content check is a trusted source.
Confirm how your loaders handle each file type and test one sample per type before relying on the checks.
Why permissions matter more than detection for RAG and agents
A detector can flag a poisoned chunk or a suspicious tool result, but it cannot be the last line of defense. The cards below describe the application controls that limit what an injected instruction can actually do, and they stay in place even when a rail misses a payload.
Least privilege on tools
Give each agent only the tools its task needs, with the narrowest arguments and scopes those tools allow. A summarizer that reads a web page should not also hold a tool that sends email or changes records. Review the tool list whenever a new action is added, because an injected instruction can only call what the application exposes to it.
Read-only retrieval scopes
Connect the retriever and any document store to the agent with read access only. Where the application must write summaries or notes, send them to a separate store that the agent cannot use to alter source documents. Confirm that the database role, API token and file share used by retrieval cannot modify or delete the content it indexes.
Per-user document access enforced by the retriever
Apply the requesting user's document permissions inside the retrieval query, not in the prompt. If the retriever returns a chunk the user could not open directly, an attacker can plant instructions in content they are allowed to upload and have them read by someone with broader access. Test this with a user who lacks access to a document that matches the query.
Human approval for write actions
Require a person to approve any action that sends data outward, changes a system of record, or spends money, and show the approver the exact parameters. An approval step stops an injected instruction that a detector missed from completing its goal. Ask who approves, how long requests wait, and whether approvals are logged with the requested arguments.
Egress limits on tools
Restrict where tools and the agent's runtime can send data by allowing only named destinations, such as approved API hosts and internal services. Block arbitrary URLs in fetch tools, and deny outbound traffic from the sandbox by default. Confirm the limits at the network layer, because a rail that inspects text cannot stop a request the runtime is already allowed to make.
A detector can miss a payload
Pattern rules, classifiers and heuristics catch known shapes of injection and miss new phrasing, encoding tricks and instructions split across chunks. Treat every detector result as one signal among several and test the application with injected documents that the rails were never tuned on. Plan for the case where a payload passes, and confirm that the permissions above still limit the damage.
Configuration options and when each fits
This table compares the controls you can place around retrieved chunks and tool results, from the cheapest local checks to model-based classifiers. Read each row as a layer that catches a different failure, and expect that no single row stops a document that is trusted to carry instructions. The main takeaway is that every option sits beside the permissions your application grants, which limit the damage any injected text can do.
| Option | What it checks | When it fits | Trade-off to confirm |
|---|---|---|---|
| Retrieval rail with a custom action | Each retrieved chunk before it reaches the prompt, through a rail your team writes | Corpora from mixed sources where you can define which chunks are allowed or must be filtered | Custom code needs its own tests, and the action's failure behavior must be confirmed for your version |
| Regex rule on chunks | Known injection phrases and patterns such as instruction overrides or role changes | Fast, deterministic screening for a narrow, well-understood set of phrases | Easy to evade with paraphrase, encoding or other languages, so treat it as one layer only |
| Context bloat rail | Oversized, padded or repetitive retrieved text that can crowd out system instructions | Long documents, scraped web pages or search results with variable length | Thresholds must be set against your real documents, or legitimate long sources get blocked |
| Tool result validation in an execution rail | Structure, size and content of tool output before the model reads it | Agents that call internal APIs, databases or search tools and act on what they return | Validation rules must match each tool's schema, and new tools need new rules |
| Output rail as a last check | Model responses for signs of injected behavior, leaked data or unauthorized actions | A final backstop when earlier layers miss or when the model can reach sensitive content | Runs after the damage may already be in the prompt or tool calls, so it cannot replace earlier controls |
| Model-based classifier | Semantic likelihood that a chunk or tool result contains instructions aimed at the model | Mixed-language or paraphrased attacks that patterns miss, with capacity to host the model | Adds latency and a dependency whose outage behavior must be confirmed, and the classifier needs its own evaluation |
How to set up retrieval and tool result checks in NeMo Guardrails
This sequence builds a NeMo Guardrails configuration that screens retrieved chunks and tool results before they reach the model, then proves with injected test content that malicious material is blocked and clean material passes.
Confirm the Python version and environment
The platform engineer creates an isolated Python environment running Python 3.11, 3.12 or 3.13, since NeMo Guardrails 0.25.0 requires one of those versions. Record the interpreter version and the pinned package version in your project so later upgrades are deliberate. Done means the interpreter reports one of the supported versions inside the environment you will use for the RAG service.
Install nemoguardrails and pin the version
The engineer installs the nemoguardrails package from PyPI, which is published under Apache-2.0, and pins the exact version in your dependency file. Confirm the installed version matches the release you tested against, and check the NeMo Guardrails release notes before adopting a newer one. Done means a basic import succeeds and the pinned version appears in your lock file.
Create config.yml and Colang files
The engineer creates a configuration folder containing config.yml, which declares the model and enabled rails, and Colang files that define the retrieval and execution rail flows. Choose Colang 1.0 or 2.0 deliberately, because 1.0 is the default and converted configurations need manual review. Done means the framework loads the folder without configuration errors and lists the rails you declared.
Add a retrieval rail for RAG chunks
The engineer adds a retrieval rail that runs on each chunk returned by the retriever before the chunk is placed in the prompt. The rail flags or removes chunks containing instruction-like text, such as directives aimed at the model, and the team decides whether a flagged chunk is dropped or the request is rejected. Done means a chunk with a test instruction is intercepted by the rail and its handling is logged.
Add an execution rail for tool results
The engineer adds an execution rail that checks the output of custom actions and tools before the model reads it, validating structure, length and any embedded instructions. Pair the check with the permissions the agent holds, because a rail that inspects text cannot replace limits on what a tool may do. Done means a tool returning a test payload with embedded instructions is caught and the agent receives the sanitized or rejected result.
Wire the rails into the RAG pipeline
The application developer calls the guardrails configuration from the retrieval step, passing retrieved chunks through the retrieval rail and tool outputs through the execution rail before generation. Confirm that the pipeline calls the rails on every path, including error and fallback branches, so no unchecked content reaches the model. Done means traced requests show the rails running in the expected order for each retrieval and tool call.
Write test cases with injected chunks
The security engineer builds a test set of documents and tool outputs that contain injected instructions, along with clean documents that should pass. Include examples that are clearly labeled as illustrative and vary phrasing and placement, such as text hidden in long chunks. Done means the test set is versioned in the repository with expected outcomes recorded for every case.
Verify blocked and passed outcomes
The security engineer runs the test set against the pipeline and compares each result with its expected outcome, recording every injected case that was blocked and every clean case that passed. Investigate false positives and misses, adjust rail configuration, and rerun until results match. Done means the run report shows the expected outcome for each case and the team has confirmed which residual risks remain, with application permissions still limiting what any injected instruction could achieve.
Security and operational risks to plan for
Retrieval rails reduce indirect prompt injection, but they add their own failure modes. The cards below cover what slips past pattern checks, what gets blocked by mistake, what each rail costs in latency, what the logs end up holding, and how the rule set stays current.
Encoded and paraphrased payloads
Regex and YARA checks on chunks match known phrasing. An attacker can encode instructions in Base64, split them across chunks, use other languages or rephrase them so no pattern fires. Test the retrieval rails against encoded, translated and paraphrased versions of your own sample payloads, and assume some will pass. Pair the chunk checks with restricted tool permissions so a missed payload has little to act on.
NeMo Guardrails docsFalse positives on legitimate documents
Pattern checks can flag ordinary content such as security runbooks, developer documentation, code samples and policy text that quotes instructions. Blocking these chunks silently removes answers your users depend on. Build a labeled set from your own corpus, record which chunks are blocked and why, and review the blocked set with the content owners before you tighten any rule.
Latency added per rail
Each retrieval rail runs before the model sees the chunks, so every check adds time to the request path. Local regex and length checks cost little, while rails that call a classifier or a separate model add a network hop and inference time. Measure p95 latency with each rail enabled separately, then decide which checks run on every chunk and which run only on sources you do not fully trust.
Logging retrieved content with personal data
Blocked chunks and their matches are useful for tuning, but the logs can capture customer records, employee details or health information that sat inside the documents. Decide what the rail logs, for example the rule ID and a hash rather than the full chunk, and set retention and access limits on those logs. Confirm the logging settings in your deployment before you send production traffic through the rails.
Keeping the rule set current
Injection techniques change, and a rule set written for last quarter's payloads ages quickly. Assign an owner for the YARA rules, regex patterns and any model-based detectors, and set a review cycle tied to NeMo Guardrails release notes. Check each upgrade against your regression set, since a new release can change how rails and configurations behave.
Guardrails releasesQuestions teams ask before blocking indirect prompt injection
How much effort does blocking indirect prompt injection take?
The effort depends mostly on how many retrieval sources and tools the application uses, how much of its content is untrusted, and how strict the permission model must be. A single knowledge base with read-only access is a small job. An agent that reads email, tickets and web pages and can then send messages or change records is a larger one, because each source and each write action needs its own trust decision. The work breaks into four parts: mapping every path where external text enters the prompt, adding retrieval and tool result checks, tightening permissions, and testing. Ask any partner to price each part separately so you can see which ones your team already covers.
Can an in-house team block indirect prompt injection on its own?
Yes, if the team has engineers who know the application's retrieval path and tool layer and can run NeMo Guardrails in their own environment. The rails themselves are open source under the Apache 2.0 license, so the software is not the cost. The harder parts are design work that only the application owner can settle, such as which sources are trusted and which actions need a human approval step, and adversarial testing, which benefits from someone who was not involved in building the system. Many teams build the controls internally and bring in an outside tester to check them. DeployOpen can take on any of these parts under a written scope.
What input does the work need from our team?
Plan to provide four things before work starts: a list of every retrieval source and its owner, a list of every tool or action the model can call with the permissions each one uses, a description of how users and service accounts authenticate, and a sample of real document types, including the unusual ones such as scanned PDFs, HTML from the web, and email threads. Access matters as much as content. Read-only test accounts that mirror production permissions give more useful results than an admin account. Confirm with your security team whether test traffic can go to a staging model endpoint, since the testing will send deliberately hostile documents.
How long does testing take as the number of tools grows?
Testing time grows with the number of tools and the number of distinct permission combinations, not with the number of documents alone. Each tool that can write, send, delete or fetch external content adds cases for injected instructions that try to trigger it, and each permission scope the tool can run under multiplies those cases. A ten-tool agent with overlapping scopes needs far more test cases than a two-tool assistant that only reads. Ask a partner for the test matrix before agreeing on a timeline, and confirm how many retest rounds are included after fixes. Timelines should come from that written matrix, not from a general estimate.
Does the NeMo Guardrails microservice sunset affect this work?
The sunset affects the microservice deployment, not the open-source library. NVIDIA says the NeMo Guardrails microservice container has been sunset as of October 1, 2026, with no new releases, and that NeMo Microservices documentation directs existing users to their NVIDIA account team. The library is licensed under Apache 2.0 and the current release is 0.25.0, published on 19 November 2026. If your design runs the microservice, plan a move to the library running in your own container or to the platform NVIDIA names as its successor, and confirm the path with NVIDIA before you build. Your retrieval and tool rails should be designed so the policy logic does not depend on one deployment form.
Do guardrails replace application permissions?
No. Guardrails reduce the chance that injected text reaches the model or changes its output, but they cannot make an unsafe permission model safe. If an agent holds write access to a mailbox, a single successful injection can still send mail, so the permission must be narrowed regardless of how good the detector is. The control order that holds up under review is: least-privilege tool credentials, explicit allow lists for actions, human approval for sensitive writes, and then rails for detection and validation. Treat any rail as one layer that reduces noise and catches known patterns, and confirm each permission with the system owner.
What should we ask a partner before signing a scope?
Ask for a written scope that lists each retrieval source, each tool and its permissions, the rails to be installed, the test cases to be run, the retest rounds included, and what your team must provide and approve. Ask which parts are fixed-scope deliverables and which would be billed as additional work if the inventory changes. Ask who keeps the configuration after handover and how updates to NeMo Guardrails will be tested. DeployOpen agrees scope, deliverables and timelines in writing before work starts and does not publish a price list, so a quote follows from that written scope.
What runs after the work is delivered?
Blocking indirect prompt injection is not a one-time setting. New retrieval sources, new tools and new model versions change the attack surface, and detectors need monitoring to confirm they still run. Recurring work usually includes reviewing the permission inventory when tools change, monitoring rail outcomes and detector availability, retesting after upgrades, and updating test cases from incidents. Ask whether the operating model will be run by your team, by a retainer, or by a mix, and what logs your team will receive. Ongoing support, upgrades and continuous testing are available as retainers.
Which NeMo Guardrails deployment model to build on today
Before you design retrieval rails, confirm which deployment model you are building on, because the answer changes who supports the code. The NeMo Guardrails microservice container was sunset as of October 1, 2026, and NVIDIA states that it will receive no new releases and is no longer supported. NVIDIA's archived NeMo Microservices documentation says new development has moved to NeMo Platform and asks existing users to contact their NVIDIA account team about next steps. If your design assumes the microservice container as the place where retrieval rails run, plan to replace that assumption now rather than after a production incident.
The library and the guardrails server are a separate path. The NeMo Guardrails library is published on PyPI and developed on GitHub under the Apache 2.0 license, and the current release is 0.25.0, which requires Python 3.11, 3.12 or 3.13. The server can load a configuration folder and expose an HTTP API, so retrieval rails and tool result checks can run in a service you operate. Separately, the NeMo Helix control plane, which NVIDIA points to from the sunset notice, runs guardrail configurations as inference gateway middleware on model endpoints. Helix is a different integration point from the library, so confirm whether your retrieval and tool result rails would sit in the application, in the server or in the gateway.
Confirm the support path with NVIDIA before you commit the architecture. Ask your NVIDIA account team whether the library, the server image you build from the Dockerfile and the Helix middleware receive security fixes, and on what timeline. Ask which NeMo Platform features cover retrieval rails and tool result validation, and whether they are open source or require a commercial agreement. Record the answers in your design decision log, because the rails you choose for indirect prompt injection depend on them, and a change of deployment model later means rewriting configurations, actions and tests.
How to test indirect injection defenses before release
This sequence turns indirect injection defenses into a repeatable test: a labeled set of poisoned chunks and malicious tool outputs, run through the same pipeline production uses, with measured blocked and missed cases. It produces a baseline that every rule change and release must be retested against.
Define the untrusted input surfaces
The team lists every path where content reaches the model without being typed by the user: retrieved chunks from each knowledge base, web or email content pulled by tools, file parsers, and tool return values from internal APIs. Each surface gets an owner and a note on who can write to its source. The step is done when the list is reviewed by the application owner and the security team, and each surface maps to a retrieval rail, execution rail or both in the planned configuration.
Build the poisoned chunk and tool output set
Testers write a labeled corpus of malicious payloads for each surface: instructions hidden in documents, role-override text, requests to call tools or exfiltrate data, encoded or split payloads, and tool results that try to change later steps. Each case also gets benign look-alikes, such as documents that mention instructions in a normal way, so false positives are measured too. The output is a versioned test file with expected outcome (block, omit or allow) and the reason for each label.
Run the cases through the production pipeline
The corpus runs through the same NeMo Guardrails configuration, models, Colang files and application code that production uses, not a stripped-down copy. Tests call the Python API or the guardrails server, and each run records the rail outcomes, the final response and any tool calls made. The step is done when a run log exists for every case and the test environment matches the release candidate's configuration hash or version pin.
Measure blocked and missed cases
Results are compared with the expected labels to produce a confusion matrix per surface and per rail: blocked malicious cases, missed malicious cases, blocked benign cases and allowed benign cases. Every missed case is reviewed to decide whether the gap is in detection, in the rail wiring, or in what the application does with allowed content. The output is a short report that names each miss and the planned fix, and it is the baseline for release acceptance criteria agreed with the risk owner.
Confirm permission tests fail safely
Detection results alone do not show safety, so testers also check what a successful injection could do. They run cases where an injected chunk asks for an action outside the user's permissions, such as reading another tenant's records or sending data to an external address, and confirm the tool layer denies it regardless of the rail outcome. The step is done when each permission test produces a denied call in the logs, and any allowed call is logged as a blocking defect.
Retest after every rule or threshold change
Any change to rails, YARA rules, regex patterns, context thresholds, prompts or model versions triggers a full rerun of the corpus, because a fix for one payload can open a gap or add false positives elsewhere. Results are compared with the previous baseline, and changes that reduce blocked malicious cases or raise benign blocks are reviewed before merge. The output is a diff report attached to the change record.
Monitor blocks and misses in production
Production logs record which rail fired, the chunk source, and the action taken, with content handled under the team's data retention rules. Dashboards and alerts track block rates per surface, sudden changes in rail outcomes, and detector errors, since a failed rail may let content through without a visible block. New suspicious cases found in production are added to the test corpus so the baseline grows over time. Confirm with the operations owner which telemetry and retention settings your environment permits before enabling content capture.
How DeployOpen scopes and delivers indirect injection protection
DeployOpen treats retrieved documents and tool results as untrusted input and plans the protection around that boundary. We scope the retrieval rails, chunk checks, tool result validation and application permissions for your own infrastructure, then build, test, document and hand over the result so your team can run and review it.
How we scope
- The written scope lists every retrieval source, tool and data store that can feed text into the model.
- Scope defines which rails run on retrieved chunks, tool results and output, and which checks stay outside NeMo Guardrails.
- Scope records the application permissions that must be reviewed, since rails alone do not limit what an agent can do.
How we build
- We configure NeMo Guardrails retrieval rails and regex checks on chunks in a version you pin and test.
- We validate tool results against expected schemas before they reach the model, and we restrict tool and file permissions.
- We test injected instructions planted in sample documents and tool outputs, then retest after each fix.
How we hand over
- You receive the configuration files, Python actions and Colang files in your own repository with a documented build.
- Documentation covers each rail, what it blocks, its fail behavior and the logs it writes for your security team.
- Handover includes test cases and results so your engineers can rerun the checks after changes to documents or prompts.
How we support
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
- Ongoing support, upgrades and continuous testing are available as a retainer, including review when NeMo Guardrails releases change.
- Before you request a quote, confirm your deployment model, document sources and who owns tool permissions so the scope reflects your environment.

