Skip to content

Schema

Schema for guardrail components.

GuardrailInput

Bases: BaseModel

Guardrail input data model.

This model represents the input data for guardrail operations. Use this when you need to check both input and output in a single call, or when you want to be explicit about which content to check.

Example

Check user query only

input_only = GuardrailInput(input="Tell me about AI", output=None)

Check LLM response only

output_only = GuardrailInput(input=None, output="AI is artificial intelligence...")

Check both query and response

both = GuardrailInput( input="Tell me about AI", output="AI is artificial intelligence..." )

from_dict(data) classmethod

Create from dictionary format for backward compatibility.

Parameters:

Name Type Description Default
data dict[str, Any]

Dictionary with input and output keys

required

Returns:

Type Description
GuardrailInput

GuardrailInput instance

GuardrailResult

Bases: BaseModel

Result of a guardrail content safety check.

This model represents the standardized return value for all guardrail operations, providing type safety and validation for safety check results.

Attributes:

Name Type Description
is_safe bool

Whether the content passed the safety check.

reason str | None

Human-readable reason for rejection if content is not safe. Defaults to None.

filtered_content str | None

Cleaned/filtered version of content if available. Defaults to None.

category str | None

Violation category metadata. Defaults to None.

policy str | None

Policy key that triggered the result. Defaults to None.

score float | None

Score/probability associated with the result. Defaults to None.

from_dict(data) classmethod

Create from dictionary format for backward compatibility.

Parameters:

Name Type Description Default
data dict[str, Any]

Dictionary with is_safe, reason, filtered_content, category, policy, and score keys.

required

Returns:

Name Type Description
GuardrailResult GuardrailResult

Parsed result instance.

safe(filtered_content=None, score=None) classmethod

Create a safe result.

Parameters:

Name Type Description Default
filtered_content str | None

Filtered content. Defaults to None.

None
score float | None

Highest policy score observed. Defaults to None.

None

Returns:

Name Type Description
GuardrailResult GuardrailResult

Safe result.

to_dict()

Convert to dictionary format for backward compatibility.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Dictionary representation of the result including optional metadata.

unsafe(reason, filtered_content=None, category=None, policy=None, score=None) classmethod

Create an unsafe result.

Parameters:

Name Type Description Default
reason str

Reason for rejection.

required
filtered_content str | None

Filtered content. Defaults to None.

None
category str | None

Violation category. Defaults to None.

None
policy str | None

Policy key that triggered the result. Defaults to None.

None
score float | None

Score or probability for the violation. Defaults to None.

None

Returns:

Name Type Description
GuardrailResult GuardrailResult

Unsafe result.

GuardrailStreamChunk

Bases: BaseModel

A single item emitted by a streaming guardrail pipeline.

Attributes:

Name Type Description
chunk str

The original source chunk value when safe. An empty string indicates a terminal unsafe marker rather than source content.

is_safe bool

Whether the content represented by this chunk is safe.

reason str | None

Reason when this item marks an unsafe terminal decision; otherwise None. Defaults to None.