nemoguardrails.base_guardrails

View as Markdown

Abstract base class for guardrails engines.

BaseGuardrails defines the minimum public surface every guardrails engine must implement. Concrete engines (LLMRails, IORails) inherit and provide real implementations. The Guardrails facade also inherits, presenting the same surface while delegating to a wrapped engine.

The contract is deliberately minimal: only what is truly shared across all engines belongs here. Engine-specific features (e.g. update_llm, check, register_action, runtime, explain_info) remain on the concrete classes that actually provide them.

Module Contents

Classes

NameDescription
BaseGuardrailsMinimum public surface shared by all guardrails engines.

API

class nemoguardrails.base_guardrails.BaseGuardrails()
Abstract

Minimum public surface shared by all guardrails engines.

Subclasses must set self.config (a :class:RailsConfig instance) in their __init__. The bare annotation below is informational only — it is not enforced by the ABC machinery, so a subclass that forgets to assign self.config will instantiate fine and only fail on first access.

config
RailsConfig
nemoguardrails.base_guardrails.BaseGuardrails.generate(
args: typing.Any = (),
kwargs: typing.Any = {}
) -> typing.Any
abstract

Generate an LLM response synchronously with guardrails applied.

nemoguardrails.base_guardrails.BaseGuardrails.generate_async(
args: typing.Any = (),
kwargs: typing.Any = {}
) -> typing.Any
asyncabstract

Generate an LLM response asynchronously with guardrails applied.

nemoguardrails.base_guardrails.BaseGuardrails.stream_async(
args: typing.Any = (),
kwargs: typing.Any = {}
) -> typing.AsyncIterator[typing.Any]
abstract

Stream LLM response tokens with guardrails applied.