What You’ll Learn
- Creating sandboxes with each of the three PII action modes:
redact,block, andlog_only - The full
SecurityPolicyJSON produced by each mode - What each mode does when the guardrails service is active
The Three PII Action Modes
| Action | What Happens When PII Is Detected |
|---|---|
redact | PII tokens are replaced with placeholders; request is forwarded |
block | The entire HTTP request is rejected; sandbox code receives an error |
log_only | Detection is logged but the request passes through unchanged |
Prerequisites
This example is available in Python. TypeScript version coming soon.
Code Walkthrough
The example creates a sandbox for each action mode and prints the resulting policy. A helper function keeps the pattern clean:redact mode replaces PII with placeholder tokens, then forwards the request:
block mode rejects the entire HTTP request when PII is detected. The sandbox code receives an error response from the proxy.
log_only mode detects and records PII in the audit log but passes the HTTP traffic unchanged. Useful for monitoring PII exposure without disrupting the application.
Choosing the Right Action
- Use
redactwhen you want to call external APIs but prevent PII from leaving the sandbox in plaintext. - Use
blockfor the strictest posture — if any PII is detected, the request must not proceed. - Use
log_onlyduring development to understand how much PII is flowing before enforcing redaction.