Skip to main content

What You’ll Learn

  • Creating a sandbox with a SecurityPolicy containing PIIConfig
  • Configuring specific PII types to detect (email, phone, ssn, credit_card)
  • Setting the redaction action (redact replaces PII with tokens like [REDACTED_EMAIL])
  • Understanding that PII redaction operates on HTTP traffic, not stdout
  • Listing all available PIIType and RedactionAction enum 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 scan stdout.
  1. Code inside the sandbox makes an HTTP request containing PII
  2. The proxy intercepts the request and scans for configured PII types
  3. Detected PII is replaced with redaction tokens (e.g., [REDACTED_EMAIL])
  4. 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

Build a SecurityPolicy with PIIConfig and pass it at sandbox creation:
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:

Available PII Types

Available Redaction Actions

When PII Is Redacted