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 not safe) or None |
filtered_content |
str | None
|
Cleaned/filtered version of content (if available) or 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, and filtered_content keys |
required |
Returns:
| Type | Description |
|---|---|
GuardrailResult
|
GuardrailResult instance |
safe(filtered_content=None)
classmethod
Create a safe result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filtered_content
|
str | None
|
Optional filtered content |
None
|
Returns:
| Type | Description |
|---|---|
GuardrailResult
|
GuardrailResult indicating safe content |
to_dict()
Convert to dictionary format for backward compatibility.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary representation of the result |
unsafe(reason, filtered_content=None)
classmethod
Create an unsafe result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str
|
Reason for rejection |
required |
filtered_content
|
str | None
|
Optional filtered content |
None
|
Returns:
| Type | Description |
|---|---|
GuardrailResult
|
GuardrailResult indicating unsafe content |