Skip to content

Base engine

Base protocol for guardrail engines.

Authors

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

References

None

BaseGuardrailEngineConfig(guardrail_mode=GuardrailMode.INPUT_ONLY) dataclass

Base configuration for guardrail engines.

This config determines which types of content the engine will check. Engines can be configured to check input only, output only, or both.

Attributes:

Name Type Description
guardrail_mode GuardrailMode

Specifies what content the engine should check. - DISABLED: Skip this engine entirely - no checks performed - INPUT_ONLY: Check only user input (queries, prompts, context) - OUTPUT_ONLY: Check only system output (LLM responses, generated text) - BOTH: Check both input and output content

GuardrailEngine

Bases: Protocol

Base engine interface for guardrail engines.

This protocol defines the contract that all guardrail engines must implement. Engines can check content for safety violations using various techniques such as phrase matching, topic classification, or external API calls.

All engines must be asynchronous to support both sync and async guardrail providers.

Attributes:

Name Type Description
config BaseGuardrailEngineConfig

Engine configuration specifying what content types to check

check_input(content, **kwargs) async

Check input content for safety violations.

This method should implement provider-specific safety checks on 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

Additional engine-specific parameters (optional)

{}

Returns:

Type Description
GuardrailResult

GuardrailResult indicating if content is safe, with reason if unsafe

Raises:

Type Description
Exception

If the safety check fails due to engine errors

check_output(content, **kwargs) async

Check output content for safety violations.

This method should implement provider-specific safety checks on 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

Additional engine-specific parameters (optional)

{}

Returns:

Type Description
GuardrailResult

GuardrailResult indicating if content is safe, with reason if unsafe

Raises:

Type Description
Exception

If the safety check fails due to engine errors