PII Detection¶
Detect personally identifiable information in user input.
Basic Usage¶
Python
from pydantic_ai import Agent
from pydantic_ai_shields import PiiDetector
agent = Agent("openai:gpt-4.1", capabilities=[PiiDetector()])
# This will raise InputBlocked:
await agent.run("Email me at john@example.com")
Detect Specific Types¶
Python
agent = Agent("openai:gpt-4.1", capabilities=[
PiiDetector(detect=["email", "ssn", "credit_card"]),
])
Built-in types: email, phone, ssn, credit_card, ip_address.
Log Instead of Block¶
Python
detector = PiiDetector(action="log")
agent = Agent("openai:gpt-4.1", capabilities=[detector])
result = await agent.run("My email is test@example.com")
# Allowed through, but recorded:
print(detector.last_detections)
# [{"type": "email", "count": 1}]