Skip to content

Guardrail Manager

Manage content guardrails using pluggable guardrail engines.

Authors

Kevin Yauris (kevin.yauris@gdplabs.id) Moch. Nauval Rizaldi Nasril (moch.n.r.nasril@gdplabs.id)

References

[1] https://github.com/NVIDIA/NeMo-Guardrails [2] https://docs.google.com/document/d/1YCR6XZ_tTtJ95CLtArnX4EKuhbfLm-FiHM3T9eVSkKo/edit?tab=t.0#heading=h.v80cs9wempa6

GuardrailManager(engine, empty_content_safe=None, error_conservative=None)

Bases: Component, GuardrailConstants

Manage content guardrails using pluggable engines.

This component provides content filtering and safety checks and delegates the provider-specific logic to a GuardrailEngine.

Attributes:

Name Type Description
engine GuardrailEngine | list[GuardrailEngine]

Required pluggable engine for guardrail operations. Provide a custom engine or a list of engines to handle guardrail logic. If a list is provided, engines are executed sequentially in the order they appear.

empty_content_safe bool | None

Whether empty content should be considered safe. Defaults to None.

error_conservative bool | None

Whether to mark content as unsafe on errors. Defaults to None.

Initialize the GuardrailManager class.

Parameters:

Name Type Description Default
engine GuardrailEngine | list[GuardrailEngine]

Required pluggable engine for guardrail operations. Provide a custom engine or a list of engines to handle guardrail logic. If a list is provided, engines are executed sequentially in the order they appear.

required
empty_content_safe bool | None

Whether empty content should be considered safe. Defaults to True.

None
error_conservative bool | None

Whether to mark content as unsafe on errors. Defaults to True.

None

check_content(content, engine_kwargs=None) async

Check the content for safety using configured engines.

This method iterates through the configured engines sequentially and returns the first unsafe result found. This "fail-fast" approach ensures efficient processing while maintaining strict safety guarantees.

Engines with DISABLED mode are skipped entirely. For active engines, it checks input content if the engine's guardrail_mode includes input checking, then checks output content if the input passed and the engine's mode includes output checking.

Parameters:

Name Type Description Default
content str | GuardrailInput

The primary content to check. If str, treated as input-only content.

required
engine_kwargs dict[str, Any] | None

Arguments to pass to each engine. Defaults to None.

None

Returns:

Name Type Description
GuardrailResult GuardrailResult

The result of the content safety check. Returns safe result only if all engines pass all applicable checks.

Raises:

Type Description
ValueError

If content is neither str nor GuardrailInput