windlass.providers.guardrails.nemo¶
nemo
¶
NVIDIA NeMo Guardrails adapter.
NeMo Guardrails brings conversational policy that regexes cannot express: topical rails ("never discuss competitors"), dialogue flows written in Colang, fact-checking rails, and model-based jailbreak detection.
Install with::
pip install "windlass[guardrails]"
Windlass gives NeMo a sensible default configuration so .guardrails('nemo')
works out of the box, and lets you point at your own Colang config directory
when you outgrow it.
Example
from windlass import Windlass # doctest: +SKIP agent = Windlass.agent().guardrails("nemo", config_path="./rails") # doctest: +SKIP
NeMoGuardrail
¶
NeMoGuardrail(
*,
config_path: str | Path | None = None,
colang: str | None = None,
yaml_config: str | None = None,
llm: Any = None,
on_violation: str = "block",
stages: tuple[str, ...] = ("input", "output"),
**config: Any
)
Bases: Guardrail
Guardrail backed by NeMo Guardrails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
str | Path | None
|
Directory holding |
None
|
colang
|
str | None
|
Inline Colang content, as an alternative to |
None
|
yaml_config
|
str | None
|
Inline YAML rails configuration. |
None
|
llm
|
Any
|
Model NeMo should use for its own rails. Windlass passes its configured model through so both layers agree. |
None
|
on_violation
|
str
|
|
'block'
|
stages
|
tuple[str, ...]
|
Which stages to run at. |
('input', 'output')
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
ConfigurationError
|
When the configuration cannot be loaded. |
Performance
NeMo rails involve extra model calls, so expect meaningful added latency
per request. Run :class:~windlass.providers.guardrails.rules.RuleGuardrail
first for the cheap deterministic checks, and reserve NeMo for policy
that genuinely needs a model.
Source code in src\windlass\providers\guardrails\nemo.py
native
¶
acheck
async
¶
acheck(
content: str, *, stage: str = "input", context: dict[str, Any] | None = None
) -> GuardrailResult
Run the configured rails against content.
A rail that refuses produces a different response than the input; that difference is how a violation is detected, since NeMo's public API returns a message rather than a verdict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The text to inspect. |
required |
stage
|
str
|
|
'input'
|
context
|
dict[str, Any] | None
|
Extra signals, forwarded to NeMo as conversation context. |
None
|
Returns:
| Type | Description |
|---|---|
GuardrailResult
|
The verdict. When a rail fires, |
GuardrailResult
|
message. |