Guardrails
Guardrails are security and content moderation mechanisms that can be applied to pipelines, agents, and other entities within the Airia platform. They help enforce policies for content filtering, PII detection, prompt injection prevention, and more. See the Guardrails API reference and response types for more details.
Get Applicable Guardrails
You can retrieve guardrails applicable to a specific project and optionally a specific agent using the get_applicable_guardrails method.
Project-Level Guardrails
from airia import AiriaClient
client = AiriaClient(api_key="your_api_key")
# Get guardrails applicable at the project level
guardrails = client.guardrail.get_applicable_guardrails(
project_id="00000000-0000-0000-0000-000000000000"
)
for guardrail in guardrails:
print(f"Guardrail: {guardrail.name}")
print(f" Description: {guardrail.description}")
print(f" Enabled: {guardrail.enabled}")
print(f" Apply to Datasource: {guardrail.apply_datasource}")
print(f" Apply to Tools: {guardrail.apply_to_tools}")
print(f" Filters: {len(guardrail.filters)}")
for filter in guardrail.filters:
print(f" - {filter.filter_type} (enabled: {filter.enabled})")
Agent-Specific Guardrails
When you need guardrails specific to an agent/pipeline, provide the agent_id parameter:
from airia import AiriaClient
client = AiriaClient(api_key="your_api_key")
# Get guardrails applicable to a specific agent
guardrails = client.guardrail.get_applicable_guardrails(
project_id="00000000-0000-0000-0000-000000000000",
agent_id="11111111-1111-1111-1111-111111111111"
)
print(f"Found {len(guardrails)} guardrails for the agent")
for guardrail in guardrails:
print(f"\nGuardrail: {guardrail.name}")
# Check assignments
for assignment in guardrail.guardrail_assignments:
print(f" Assigned to: {assignment.entity_type} ({assignment.entity_id})")
# Check targets
for target in guardrail.guardrail_targets:
print(f" Target: {target.entity_type}, Type: {target.target_type}")
if target.is_exception:
print(" (Exception mode - applies to all EXCEPT listed entities)")
Async Usage
The same functionality is available with the async client:
import asyncio
from airia import AiriaAsyncClient
async def main():
client = AiriaAsyncClient(api_key="your_api_key")
guardrails = await client.guardrail.get_applicable_guardrails(
project_id="00000000-0000-0000-0000-000000000000"
)
for guardrail in guardrails:
print(f"Guardrail: {guardrail.name} (enabled: {guardrail.enabled})")
asyncio.run(main())
Understanding Guardrail Hierarchy
Guardrails use hierarchical matching logic similar to pipeline execution:
- Tenant-level guardrails apply to all projects and agents within the tenant
- Project-level guardrails apply to all agents within that project
- Agent-level guardrails apply only to the specific agent
The isException flag on guardrail targets determines the inclusion/exclusion behavior:
- When
is_exception=False(default): The guardrail applies ONLY to entities in the assignment list - When
is_exception=True: The guardrail applies to ALL entities EXCEPT those in the assignment list
Filter Types
Guardrails can include various filter types for different content detection needs:
| Filter Type | Description |
|---|---|
Pii |
Personally Identifiable Information detection |
Pci |
Payment Card Industry data detection |
Phi |
Protected Health Information detection |
Moderation |
Content moderation for inappropriate content |
PromptInjection |
Prompt injection attack detection |
Secrets |
Secret/credential detection |
AllowList |
Allowlist-based filtering |
KeywordDetector |
Keyword-based detection |
CustomDetector |
Custom detection rules |
HtmlSanitization |
HTML content sanitization |
UrlSanitization |
URL sanitization |
RateLimiting |
Rate limiting controls |
AgentAlignment |
Agent alignment verification |
PythonFilter |
Python-based custom filters |
AgentSystemPromptAdherence |
System prompt adherence checking |