Nemo engine
Default NeMo Guardrails engine implementation.
References
[1] https://github.com/NVIDIA/NeMo-Guardrails
NemoGuardrailEngine(config=None)
Bases: GuardrailEngine
Default engine that keeps current NeMo Guardrails behavior.
This engine implements the GuardrailEngine protocol to provide NeMo Guardrails functionality for content safety checking.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
NemoGuardrailEngineConfig
|
Engine configuration specifying what content types to check. |
rails |
LLMRails | None
|
LLMRails instance. |
Initializes a new instance of the NemoGuardrailEngine class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
NemoGuardrailEngineConfig | None
|
NemoGuardrailEngineConfig with both base and NeMo-specific settings. Defaults to None. |
None
|
check_input(content, **kwargs)
async
Check input content for safety violations.
This method implements NeMo Guardrails checking for user input such as query content, context, or prompts before sending to LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The input text to evaluate for safety. |
required |
**kwargs
|
Any
|
Additional engine-specific parameters. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GuardrailResult |
GuardrailResult
|
GuardrailResult indicating if content is safe, with reason if unsafe. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the guardrail engine is not initialized. |
check_output(content, **kwargs)
async
Check output content for safety violations.
This method implements NeMo Guardrails checking for system output such as LLM responses, generated text, or static messages before showing to users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The output text to evaluate for safety. |
required |
**kwargs
|
Any
|
Additional engine-specific parameters. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
GuardrailResult |
GuardrailResult
|
GuardrailResult indicating if content is safe, with reason if unsafe. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the guardrail engine is not initialized. |
NemoGuardrailEngineConfig(guardrail_mode=GuardrailMode.INPUT_ONLY, config_dict=None, colang_config=None, denial_phrases=None, topic_safety_mode=None, allowed_topics=None, denied_topics=None, include_core_restrictions=None, core_restriction_categories=None)
dataclass
Bases: BaseGuardrailEngineConfig
NeMo-specific configuration that extends base guardrail config.
This config inherits the basic guardrail_mode from BaseGuardrailEngineConfig and adds NeMo-specific settings for advanced guardrail functionality.
Attributes:
| Name | Type | Description |
|---|---|---|
config_dict |
dict[str, Any] | None
|
Dictionary of NeMo-specific configuration. |
colang_config |
str | None
|
Optional Colang configuration string. |
denial_phrases |
list[str] | None
|
Phrases that indicate blocked content. |
topic_safety_mode |
TopicSafetyMode | str | None
|
Topic safety mode. |
allowed_topics |
list[str] | None
|
List of allowed topics for responses. |
denied_topics |
list[str] | None
|
List of denied topics for responses. |
include_core_restrictions |
bool | None
|
Whether to include core safety restrictions. |
core_restriction_categories |
list[str] | None
|
List of enabled core restriction categories. |
init_guardrails_provider_registration()
Register global NeMo Guardrails chat provider once.
This avoids redundant registration per preset/component. Safe to call once during process initialization.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if registration succeeded, False otherwise. |