Examples¶
Real-world examples of using pydantic-ai-shields.
Security¶
| Example | Description |
|---|---|
| Security Overview | Combining multiple shields for defense-in-depth |
| PII Detection | Detect personally identifiable information |
| Prompt Injection | Block injection and jailbreak attempts |
| Toxicity Check | Screen content for toxic language |
| JSON Schema Validation | Validate tool arguments |
Cost Control¶
| Example | Description |
|---|---|
| Cost Tracking | Token usage monitoring and budget enforcement |
Quick Example¶
Python
from pydantic_ai import Agent
from pydantic_ai_shields import (
CostTracking, PromptInjection, PiiDetector, SecretRedaction, NoRefusals,
)
agent = Agent(
"openai:gpt-4.1",
capabilities=[
CostTracking(budget_usd=5.0),
PromptInjection(sensitivity="high"),
PiiDetector(),
SecretRedaction(),
NoRefusals(),
],
)
result = await agent.run("Hello!")
Each shield handles a specific concern, keeping your code clean and modular.