Retrieval rails: filtering retrieved chunks in NeMo Guardrails

Retrieval rails let you validate, filter and mask retrieved chunks before they enter the prompt. This page covers what they do, the checks available, and the engine and setup requirements to confirm.

On this page

What retrieval rails filter in NeMo Guardrails and when you need them

If your assistant answers from retrieved documents, the question is not only whether the model answers well but what those documents are allowed to contribute to the prompt. Retrieved text is untrusted input. A chunk can be out of date, outside the user's permissions, carry personal data, or simply be irrelevant and pull the answer off course. NeMo Guardrails handles this with retrieval rails, one of its five rail types, which are defined specifically for RAG chunks. The other four are input rails, dialog rails, execution rails for custom actions and tools, and output rails. Retrieval rails sit between your retriever and the generation step, so they act before the model sees the evidence.

The problems they address fall into three groups: unwanted chunks, such as content your policy excludes or material from a source the user should not reach; sensitive chunks, where personal or confidential data would otherwise be copied into an answer; and irrelevant chunks, which dilute or distort the context the model reasons over. You need retrieval rails when your retrieved corpus mixes audiences or classification levels, when documents are user-generated or externally sourced, or when you have to show a reviewer that filtering happens before generation. If your corpus is a small, curated set of internal documents with access enforced upstream in the retriever, you may need less than you expect. Decide this per corpus, not for the whole assistant.

Before you design around retrieval rails, confirm three things in the NeMo Guardrails documentation for the version you run: the exact checks and actions available on retrieval rails, how a rail rejects or modifies a chunk, and which engine and configuration format the rail requires. The NeMo Guardrails documentation is the place to check these, because this page does not list them. Then test the rails with chunks you know should be blocked, masked or kept, and record the results. That test set is the evidence a security or compliance reviewer will ask for.

How a retrieved chunk moves through the retrieval rail

The flow starts at your retriever, which pulls chunks from your own store and passes them to NeMo Guardrails as the relevant chunks for a question. Retrieval rails then check, mask or drop each chunk before the prompt is built. The trust boundary sits between your retrieval store and the model context, so treat every chunk as untrusted input. Check what the rail removes and confirm that only the surviving chunks reach the generator.

Chunks move from your retriever through retrieval rails into the prompt, with masked and dropped chunks removed.

Which checks run on retrieval rails and what each one does

Validation checks ask whether a retrieved chunk is acceptable to use at all. They run before the chunk is placed into the prompt and typically examine the chunk's content or the way it is shaped, not the user's question. Their job is to stop obviously unsuitable material from influencing the answer, while leaving judgment about the answer itself to the fact-checking rails.

  • Content screening: A chunk can be checked for harmful, abusive or policy-violating text before the model sees it, using the safety models covered in the content safety topic.
  • Injection screening: Retrieved documents can contain instructions aimed at the model. Checks for injection payloads in chunks are the retrieval-side counterpart of the input protections covered in the jailbreak and prompt injection topic.
  • Format and size constraints: Chunks that are empty, malformed or outside expected length limits can be rejected before they consume context.
  • Source conditions: Chunks can be tested against metadata such as document status or origin, so content from unapproved sources is not used.

Confirm in the documentation for your installed version which of these checks are built in, which need a custom action, and the exact configuration keys that enable them.

Retrieval rail configuration options and when each fits

This table compares the ways to feed retrieved chunks through NeMo Guardrails, the outcomes a retrieval rail can produce, and the configuration choices that set them. Read each row against your own retriever and the complexity you are willing to own, and confirm any option marked for verification in your installed release before you design around it.

OptionWhen it fitsComplexity and trade-off
Built-in knowledge base (kb folder)Small, Markdown-only document sets where a simple in-framework index is acceptableLowest integration effort, but limited to Markdown and the built-in chunking and embedding defaults
Custom retrieval actionExisting vector store or retriever that must stay the source of truthHigher effort: you write and maintain the action that returns chunks to the rails
Passing chunks from your own RAG pipelineApplication already retrieves and generates, and rails need the chunks as contextModerate effort: the chunk contract, metadata and ordering must be kept consistent with the rails
Filtering outcomeIrrelevant, out-of-scope or low-quality chunks should be dropped while the answer continuesKeeps answers flowing, but dropped evidence can reduce answer quality; test coverage carefully
Masking outcomeChunks may contain personal or sensitive fields the model should not see but the answer can still useNeeds a masking rule per data type and tests that masked values do not leak through other paths
Blocking outcomeChunks from untrusted or restricted sources must never reach the promptStrictest option; users may see refusals more often, so define the fallback response with the business owner
Per-rail enablement in config.ymlOnly some rails should run on chunks, to control latency and scopeLow effort, but each enabled rail adds calls and must be reviewed when the configuration changes
Retrieval rail placement in the flowChecks should run before the chunks reach generation rather than after the answerConfirm the exact flow hook and ordering for your release, since configuration syntax has changed across versions

How to set up retrieval rails step by step

This sequence takes a team from a clean Python environment to a retrieval rail that inspects each retrieved chunk before it reaches the prompt, with a check at every step. The result is a version-pinned configuration folder and a tested set of decisions for known good and bad chunks.

  1. Confirm the Python version

    Check that the Python interpreter in the target environment is 3.11, 3.12 or 3.13, the versions NeMo Guardrails 0.25.0 requires. Run python3 --version in the same virtual environment or container image you plan to use in production, not only on a developer laptop. The step is done when the reported version falls in that range and the interpreter is the one the install will use. Anything outside that range is not covered by the 0.25.0 requirements, so confirm the plan with your platform team before going further.

  2. Install the library at a pinned version

    Create an isolated virtual environment and install the package from PyPI with pip install nemoguardrails==0.25.0. The package is licensed under Apache 2.0, and the platform team should record the pinned version in the requirements file so upgrades happen on purpose. Confirm the install by running nemoguardrails --help and importing the package in Python. The step is done when both succeed and the installed version reads 0.25.0.

  3. Create the configuration folder

    Create a configuration folder containing config.yml for the model settings and enabled rails, one or more Colang files, and any optional Python actions. Keep the folder in version control from the first commit so every change to a retrieval rule is reviewable. Load the folder with the Python API or start it as a guardrails server. The step is done when the configuration loads without errors and any missing file is named in the output.

  4. Choose the Colang version deliberately

    Colang 1.0 is the default, and Colang 2.0 is also supported. The two versions use different syntax, so choose one before writing any flow, because the choice affects every file that follows. If you are converting an existing 1.0 configuration, NVIDIA documents a migration path using the nemoguardrails convert tool, and converted files still need manual review. The step is done when the team has written down the version and, for conversions, the reviewed output is committed alongside the original.

  5. Declare the retrieval rail in config.yml

    Add the retrieval rail under the rails section of config.yml and reference the Colang flow that will inspect each chunk. Take the key names and flow naming pattern from the NeMo Guardrails documentation for your chosen Colang version, and confirm them against the pinned release because the names are matched at runtime. The step is done when the load output lists the retrieval rail as active. If it does not appear, compare the names in the file against the documentation before changing any logic.

  6. Write the chunk decision logic

    Write the Colang flow or Python action that decides what happens to each chunk: keep it, drop it, or mask a span before it enters the prompt. Start with one simple rule, such as dropping chunks that fail a single check, so the behavior is easy to test and explain to reviewers. Any external call made by the action should be to a service your security team has approved. The step is done when a single chunk passed to the action returns the expected decision and the function runs without calling unapproved services.

  7. Wire retriever output into the rails

    Connect your retriever so that the chunks it returns are the ones the rail inspects before generation. If you use a custom RAG pipeline, pass the retrieved chunks to the rails call in the form your pinned version expects, and confirm the chunk text matches what the generator will receive. Log the chunks before and after the rail for one request. The step is done when the logged prompt contains only the chunks that passed and masked spans appear masked.

  8. Test with known good and bad chunks

    Build a test set of chunks that should pass, chunks that should be dropped, and chunks that should be masked. Use invented sample text and label it as illustrative so it cannot be mistaken for real customer data. Include a few borderline cases, since they show where a rule is too broad or too narrow. Store the set in version control and rerun it after every configuration or version change. The step is done when every expected decision matches and the results are recorded.

Engine requirements to confirm before building retrieval rails

Retrieval rails sit inside the NeMo Guardrails engine, so the runtime, deployment shape and framework settings decide how they are built and tested. Confirm these six items before writing any chunk filter, because a later change to the Python version, Colang version or API surface can force rework across every rail.

Python version

NeMo Guardrails 0.25.0 requires Python 3.11, 3.12 or 3.13. Confirm the interpreter in your build image and CI runners matches one of these versions, and that any custom retrieval actions you write import cleanly under the same version. Mismatches usually surface only when the first retrieval rail loads, so test the install in the environment you will deploy to.

Supported Python
3.11 to 3.13
PyPI package

Python API or guardrails server

Decide whether retrieval rails run inside your application through the Python API or in a separate guardrails server that loads a configuration folder and exposes an HTTP API. The server path includes a Dockerfile for building an image. Your choice determines where retrieved chunks are passed in, how you authenticate calls and how you test the rail end to end.

Colang version choice

Colang 1.0 is the default, and Colang 2.0 is also supported. Confirm which version your retrieval flows use before writing them, since flow syntax differs. If you start on 1.0 and plan to move later, NVIDIA's convert tool helps, but its output still needs manual review of every retrieval flow.

Colang 2 migration guide

LangChain opt-in setting

LangChain integration is opt-in and is enabled with the environment variable NEMOGUARDRAILS_LLM_FRAMEWORK=langchain. Confirm whether your application chain is LangChain-based before deciding how retrieved chunks reach the rail. Set the variable explicitly in every environment, because a missing value can leave a LangChain-wrapped retriever disconnected from the rail.

LLMRails deprecation

NeMo Guardrails 0.25.0 deprecates the LLMRails class in favor of Guardrails. Removal is planned no earlier than 0.27.0, so code that calls LLMRails will still run for now but will need changing. Check every retrieval integration and test harness for LLMRails references, and pin the version so the rename does not arrive unannounced.

The 0.25 migration guide

NVIDIA publishes a 0.25 migration guide that covers the class rename and related changes. Read it before you write retrieval code, then list each change that touches your configuration, custom actions or server setup. Record the result in your design document so reviewers can confirm the retrieval rail was built against the version you deploy.

NeMo Guardrails docs

Trade-offs of filtering chunks before the prompt

Aggressive filtering lowers leakage but can starve the answer of evidence. When a retrieval rail drops or masks chunks before they reach the prompt, the application LLM sees less sensitive or off-policy text, which reduces the chance of data exposure and of injected instructions reaching the model. The cost is recall. A strict relevance or policy check can remove the one chunk that answers the question, and the model then either refuses, answers from its own training data, or produces a weaker answer. Before tightening any retrieval rail, run a set of representative questions with known source passages and compare answer quality with and without the rail. Record which chunks were dropped and why, so the team can tell a correct block from a false positive.

Light filtering keeps recall high but accepts more exposure. Chunks that contain personal data, credentials, or instruction-like text pass through to the model, and the output rails and PII controls become the main line of defense. That only works if those downstream controls are tested against the content the retriever actually returns, not against clean sample data. The decision depends on the corpus. An internal policy library with controlled authorship supports lighter filtering than a wiki or ticket archive that many people can edit. Confirm with the owners of each source which content classes they consider sensitive before setting thresholds.

Retrieval rails also interact with fact-checking rails, which need the relevant chunks to judge whether an answer is grounded. If the retrieval rail removes or masks a passage, the grounding check compares the answer against a smaller or altered evidence set. An answer that was supported by the original chunk can then be flagged as unsupported, and a masked value can make a correct answer look contradicted. The order of rails therefore matters. Check whether your configuration passes the filtered or the original chunks to the fact-checking step, and document that choice. Test the pair together with cases where filtering removes evidence, because a grounding check that passes on clean chunks may fail, or pass incorrectly, once filtering is active.

Security and operational risks of retrieval rails

Retrieval rails sit between your knowledge sources and the model, so they inherit the risks of both. The cards below cover what can leak or be injected through retrieved content, what gets logged, who can reach the source store, and what changes when configurations or hosting change.

Sensitive data in retrieved chunks

A retrieval rail only sees what the retriever returns, so a chunk can carry personal data, credentials or internal figures into the prompt even when the user never asked for them. Decide which fields and document classes may reach the model, and test with representative documents from each source. Check whether masking or blocking runs on the chunk before the prompt is built, not only on the final answer.

Injection text hidden in documents

Documents in a knowledge base can contain instructions aimed at the model, such as text hidden in comments, metadata or white-on-white markup. Retrieval rails can filter or flag chunks, but they do not guarantee that every instruction is caught. Include poisoned sample documents in your test set and confirm which injection checks your configuration actually enables.

Logging of raw chunks

Debug and trace output often records the retrieved chunks, which means the raw content of your documents can end up in log storage with its own retention and access rules. Decide what the rails log by default, whether content capture is enabled, and who can read those logs. Confirm the logging options in the NeMo Guardrails documentation for your version before you turn on verbose output.

NeMo Guardrails docs

Access control on the source store

Retrieval rails filter content after retrieval, so they do not enforce the permissions of the system that holds the documents. If the retriever can read a folder that a given user should not see, the rails may still pass that content through. Keep authorization in the source store or the retriever, and use the rails as an additional check, not as the only access boundary.

Testing gaps after configuration changes

Changing a Colang flow, a rail action, a prompt or the knowledge base can alter which chunks are blocked or masked, and a change that looks small can open a gap. Keep a fixed set of retrieval test cases with expected outcomes and rerun it after every change, including library upgrades. Colang 1.0 to 2.x conversions still need manual review, so include them in the rerun.

Microservice sunset changes hosting

NVIDIA has retired the NeMo Guardrails microservice, which NVIDIA says is no longer supported after the sunset date. Teams that deployed the container must plan a move to the library server or to NeMo Platform, and confirm with their NVIDIA account team what applies to their contract. Re-verify the retrieval rails, logging and network controls in the new location before production traffic moves.

Sunset date
October 1, 2026
NGC container page

Questions teams ask before building retrieval rails

How much effort does building retrieval rails take?

The effort depends less on the rail code than on how many retrieval sources you have, how varied their documents are, and how strict the filtering must be. A single internal knowledge base with consistent Markdown or plain text needs a small number of checks, such as chunk validation, masking of identifiers and a relevance filter. Effort grows when you add several retrievers, mixed file formats, per-user access rules or checks that call a second model. Each added check also needs tests, so plan for the test set as a cost in its own right. Ask any partner to split its quote into design, rail implementation, test data and evaluation, and retesting after changes.

Can an internal team build retrieval rails on its own?

Yes, if the team has Python engineers who can work with the NeMo Guardrails configuration model and a retriever they already operate. The library is open source, and its configuration uses a config.yml file, optional Python actions and Colang files. The skills that are often missing are Colang design, evaluation of filtering decisions against real queries, and security review of what gets masked or dropped. Teams that build alone usually underestimate evaluation work. A partner can cover part of the build, while your team keeps ownership of the policy decisions about which content may reach the model.

What does the work need from our team?

Three inputs matter most. First, read access to the retriever and its index, including the metadata that carries source, owner and access labels, because filtering rules depend on those fields. Second, a representative sample of documents across the sources the assistant will use, including the awkward cases such as scanned text, tables and duplicated content. Third, a test set of realistic user questions with the chunks you expect to be allowed, blocked or masked. Your security team should also name who approves the filtering policy and who can review blocked-content logs. Ask for these inputs in writing before the scope is fixed.

Can we start with the open-source library without a commercial license?

The NeMo Guardrails library is licensed under Apache 2.0, and its source is published in the NVIDIA-NeMo/Guardrails repository. You can review the license terms and start a prototype without buying a NVIDIA commercial license for the library itself. Two points need checking before production. The library's Python requirements are version-specific, and the current release, 0.25.0, requires Python 3.11, 3.12 or 3.13. Also confirm which models your rails call, since those models carry their own licenses and hosting costs. Your legal team should review the Apache 2.0 terms and any model licenses against your use case.

How long does building retrieval rails take?

Timing is driven by the same factors as effort, with two additions: how quickly your team can make decisions about filtering policy, and how much evaluation is needed before the assistant goes live. Schedules slip most often when the access model is unclear, when retrieval metadata is inconsistent, or when a second model must be hosted and tested before the rails can run. Ask any provider for a written schedule tied to the agreed scope, with named milestones for policy sign-off, test results and a retest after fixes. Duration figures should come from that written plan, not from general guidance.

What changes after a NeMo Guardrails upgrade?

Upgrades can change configuration and Python behavior, so retrieval rails should be retested after every version change. NVIDIA's 0.25.0 release deprecates the LLMRails class in favor of Guardrails, with removal planned no earlier than 0.27.0, and publishes a 0.25 migration guide. If your configurations use Colang 1.0 or 2.x, NVIDIA documents a conversion path with the nemoguardrails convert tool, and states that converted configurations still need manual review. Plan for a regression test set that covers allowed, blocked and masked chunks, and treat each upgrade as a change to a control that needs its own evidence.

How DeployOpen scopes and delivers retrieval rails

DeployOpen treats retrieval rails as part of the RAG data path, so the work starts with what your retriever returns and what must never reach the prompt. We scope, build, test, document and hand over the rails in your own infrastructure, with the engine and Python version confirmed before any code is written.

How we scope

  • Inventory the retriever, document sources and chunk metadata that feed the retrieval rail
  • Define which checks apply to chunks: validation, filtering and masking, with the owner of each rule
  • Confirm the NeMo Guardrails release, Python version (3.11, 3.12 or 3.13) and Colang version before build
  • Agree deliverables, acceptance tests and timelines in writing; engagements are fixed-scope

How we build

  • Wire the retrieval rail between your retriever or knowledge base and the prompt, using the configuration your stack needs
  • Implement custom actions for organization-specific chunk checks, with logging of every filtered or masked chunk
  • Use Colang files and config.yml under version control so each rail change is reviewed and traceable
  • Run configuration tests against known-bad and known-good chunks before any user traffic reaches the assistant

How we hand over

  • Deliver the configuration folder, actions, deployment files and a runbook for the retrieval rail
  • Document each check, its input, its outcome and the evidence it produces for your security reviewers
  • Walk your platform and security teams through operating, debugging and changing the rules
  • Provide a written findings and fixes record for the handover, so your team knows what was tested

How we support

  • Plan upgrades across NeMo Guardrails releases, including configuration changes flagged in migration guides
  • Offer ongoing support, upgrades and continuous testing as a retainer after handover
  • Retest retrieval rails after changes to the retriever, embedding model, document corpus or prompts
  • Ask for a quote built from the written scope, including which parts recur and which are one-time

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.