What You’ll Learn
- Creating a sandbox with a
SecurityPolicycontainingPIIConfig - Configuring specific PII types to detect (
email,phone,ssn,credit_card) - Setting the redaction action (
redactreplaces PII with tokens like[REDACTED_EMAIL]) - Understanding that PII redaction operates on HTTP traffic, not stdout
- Listing all available
PIITypeandRedactionActionenum values
How PII Redaction Works
PII redaction operates via a TLS proxy that intercepts HTTP traffic between the sandbox and external APIs (e.g., OpenAI, Anthropic). It does not scanstdout.
- Code inside the sandbox makes an HTTP request containing PII
- The proxy intercepts the request and scans for configured PII types
- Detected PII is replaced with redaction tokens (e.g.,
[REDACTED_EMAIL]) - The sanitized request is forwarded to the external API
PII scanning via the guardrails service is rolling out. This example demonstrates the SDK API for configuring PII policies — sandbox creation with the policy works today and the policy is stored and returned on the sandbox object.
Prerequisites
Code Walkthrough
- Python
- TypeScript
Build a Verify the sandbox info to confirm it was created with the policy:Running a script that prints PII to stdout does NOT trigger redaction — the proxy only watches HTTP traffic:List all available PII types and redaction actions:
SecurityPolicy with PIIConfig and pass it at sandbox creation: