Guardrails Configuration
This section describes how to configure guardrails in the config.yml file to control LLM behavior.
The rails Key
The rails key defines which guardrails are active and their configuration options.
Rails are organized into five categories based on when they trigger during the guardrails process.
Rail Categories
The following table summarizes the different rail categories and their trigger points.
The following diagram shows the guardrails process described in the table above in detail.

Basic Configuration
Input Rails
Input rails process user messages before they reach the LLM:
For a complete list of available input flows, refer to the YAML Schema Reference: Input Rails.
Output Rails
Output rails process LLM responses before returning to users:
For a complete list of available output flows, refer to the YAML Schema Reference: Output Rails.
Retrieval Rails
Retrieval rails process chunks retrieved from the knowledge base:
For a complete list of available retrieval flows, refer to the YAML Schema Reference: Retrieval Rails.
Dialog Rails
Dialog rails control conversation flow after user intent is determined:
For a complete list of available dialog flows, refer to the YAML Schema Reference: Dialog Rails.
Execution Rails
Execution rails control custom action and tool invocations:
Rail-Specific Configuration
Configure options for specific rails using the config key:
YAML Schema
Complete guardrails configuration example:
Parallel Execution of Input and Output Rails
You can configure input and output rails to run in parallel. This can improve latency and throughput.
IORails Engine
The IORails engine is an optimized execution engine that runs NemoGuard input and output rails in parallel with dedicated model management. The IORails engine is an opt-in feature. By default, the NeMo Guardrails library uses the LLMRails engine.
IORails is an early-release feature and currently does not support streaming, reasoning models, and telemetry as in LLMRails.
Supported Flows
The IORails engine supports the following flows:
content safety check input/content safety check outputtopic safety check inputjailbreak detection model
When IORails is enabled and the configuration uses only these flows, the engine runs them in parallel.
Configurations that include custom flows, dialog rails, or other unsupported flows
silently fall back to the LLMRails engine and emit a warning. Pass require_iorails=True
to Guardrails(...) to raise a ValueError at initialization instead.
Enabling IORails
To enable the IORails engine, set the NEMO_GUARDRAILS_IORAILS_ENGINE environment variable to 1:
When using the Python API, import the Guardrails class directly and pass use_iorails=True:
YAML-Based Parallel Execution
You can also configure existing LLMRails flows to run in parallel using the parallel: True
option in the config.yml file. This approach works with any flow type and does not require
the IORails engine.
When to Use
Use YAML-based parallel execution:
- For I/O-bound rails such as external API calls to LLMs or third-party integrations.
- If you have two or more independent input or output rails without shared state dependencies.
- In production environments where response latency affects user experience and business metrics.
When Not to Use
Avoid parallel execution:
- For CPU-bound rails; it might not improve performance and can introduce overhead.
- During development and testing for debugging and simpler workflows.
Configuration Example
To enable parallel execution, set parallel: True in the rails.input and rails.output sections in the config.yml file.
Input rail mutations can lead to erroneous results during parallel execution because of race conditions arising from the execution order and timing of parallel operations. This can result in output divergence compared to sequential execution. For such cases, use sequential mode.
The following is an example configuration for parallel rails using models from NVIDIA Cloud Functions (NVCF). When you use NVCF models, make sure that you export NVIDIA_API_KEY to access those models.
Save the following code snippet to config.yml.
Download prompts.yaml and put this in the same directory as the config.yml.
Speculative Generation
Speculative generation runs input-rail and main LLM response generation in parallel, rather than sequentially. If response generation takes longer than the input-rail latency, this hides the latency of the input-rail check. The tradeoff is that the main LLM will begin generating a response for unsafe requests, with a corresponding token cost. However, responses are always checked by output rails before being returned to the client so no unsafe responses will be seen.
When to use Speculative Generation
In many applications, safe requests are much more likely than unsafe requests. Speculative generation takes advantage of this by assuming all requests are safe for generation. Assuming a 2% rate of unsafe requests, the remaining 98% of safe requests will hide the input-rail latency by running in parallel with response generation. The cost of this latency saving is that tokens for the 2% of unsafe requests will be generated and then discarded. To decide whether Speculative Generation makes sense for your use-case, explore the unsafe request rate and potential latency savings.
Experimental Feature
Speculative generation currently requires the opt-in IORails engine. To
enable IORails, set NEMO_GUARDRAILS_IORAILS_ENGINE=1. Speculative
generation is supported only for non-streaming requests (generate_async).
When speculative generation is enabled, streaming requests (stream_async)
fall back to sequential execution and emit a warning.
How Speculative Generation Works
Without speculative generation, the IORails engine runs the input rails first and only starts the main LLM call once the input is determined to be safe:
- Run input rails on the user message. If the input is unsafe, return the refusal message and stop.
- If the input is safe, generate a response from the main LLM.
- Run output rails on the LLM response. If the output is unsafe, return the refusal message and stop.
- Return the response.
With speculative generation enabled, the input rails and the main LLM call start at the same time and race to completion:
- Start the input rails and the main LLM call in parallel.
- Wait for whichever finishes first, then resolve the race:
- If the input rails finish first and the input is unsafe, cancel the LLM call and return the refusal message.
- If the input rails finish first and the input is safe, wait for the LLM call to finish.
- If the LLM call finishes first, wait for the input-rail verdict; discard the response and return the refusal message if the input is unsafe.
- Run output rails on the LLM response.
- Return the response, or the refusal message if output rails blocked it.
The engine handles three outcomes:
Output rails always run after the main LLM completes. Speculative generation does not change the output-rail path.
Configuration Example
To enable speculative generation, set speculative_generation: True under rails.input in the config.yml file.
Speculative generation requires the IORails engine; see IORails Engine for how to enable it.
speculative_generation and parallel can be combined.
Input rails will run in parallel with each other and concurrently with the main LLM call.