Nemo engine
Default NeMo Guardrails engine implementation.
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. |
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
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 |
|---|---|---|
lm_invoker |
BaseLMInvoker | None
|
Invoker used by the NeMo adapter. |
config_dict |
dict[str, Any] | None
|
Legacy NeMo guardrails config dict (deprecated). |
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. |
colang_config |
str | None
|
Optional Colang configuration string. |
nemo_kwargs |
dict[str, Any] | None
|
NeMo-specific kwargs. |
from_model_config(model_id, credentials=None, config=None, **kwargs)
classmethod
Create a NemoGuardrailEngineConfig from a model configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str | ModelId
|
The model ID. |
required |
credentials
|
str | dict[str, Any] | None
|
The credentials for the model. |
None
|
config
|
dict[str, Any] | None
|
The model configuration. |
None
|
**kwargs
|
Any
|
Additional kwargs to pass to the constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
NemoGuardrailEngineConfig |
NemoGuardrailEngineConfig
|
The created NemoGuardrailEngineConfig. |
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. |