Exceptions¶
All shield exceptions inherit from GuardrailError.
| Exception | Raised by |
|---|---|
InputBlocked |
InputGuard, PromptInjection, PiiDetector, BlockedKeywords |
OutputBlocked |
OutputGuard, SecretRedaction, NoRefusals |
ToolBlocked |
ToolGuard |
BudgetExceededError |
CostTracking |
PricingError |
CostTracking(strict=True) |
Guardrail capabilities for pydantic-ai agents.
Ready-to-use capabilities for safety, cost control, and permission management. Built on pydantic-ai's native capabilities API.
Example
GuardrailError
¶
InputBlocked
¶
Bases: GuardrailError
Raised when user input is blocked by a guardrail.
OutputBlocked
¶
Bases: GuardrailError
Raised when model output is blocked by a guardrail.
ToolBlocked
¶
Bases: GuardrailError
Raised when a tool call is blocked by a guardrail.
Source code in src/pydantic_ai_shields/guardrails.py
| Python | |
|---|---|
BudgetExceededError
¶
Bases: GuardrailError
Raised when cost budget is exceeded.
Source code in src/pydantic_ai_shields/guardrails.py
PricingError
¶
Bases: GuardrailError
Raised when cost calculation fails (strict mode only).
Attributes:
| Name | Type | Description |
|---|---|---|
model_name |
The model name that failed to resolve. |
Source code in src/pydantic_ai_shields/guardrails.py
| Python | |
|---|---|