Skip to main content

What You’ll Learn

  • Creating sandboxes with each of the three PII action modes: redact, block, and log_only
  • The full SecurityPolicy JSON produced by each mode
  • What each mode does when the guardrails service is active

The Three PII Action Modes

ActionWhat Happens When PII Is Detected
redactPII tokens are replaced with placeholders; request is forwarded
blockThe entire HTTP request is rejected; sandbox code receives an error
log_onlyDetection 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:
from declaw import Sandbox, SecurityPolicy, PIIConfig, RedactionAction

def demonstrate_action(action: RedactionAction) -> None:
    policy = SecurityPolicy(
        pii=PIIConfig(
            enabled=True,
            types=["email", "phone", "ssn", "credit_card"],
            action=action.value,
        )
    )

    print(f"Policy configuration:\n{policy.to_json()}")

    sbx = Sandbox.create(template="base", timeout=300, security=policy)
    try:
        print(f"Sandbox created: {sbx.sandbox_id}")
        info = sbx.get_info()
        print(f"  State: {info.state.value}")
    finally:
        sbx.kill()
        print("Sandbox killed.")
Iterate over all actions:
for action in RedactionAction:
    demonstrate_action(action)
redact mode replaces PII with placeholder tokens, then forwards the request:
"jane@example.com"     ->  "[REDACTED_EMAIL]"
"555-867-5309"         ->  "[REDACTED_PHONE]"
"123-45-6789"          ->  "[REDACTED_SSN]"
"4111-1111-1111-1111"  ->  "[REDACTED_CREDIT_CARD]"
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 redact when you want to call external APIs but prevent PII from leaving the sandbox in plaintext.
  • Use block for the strictest posture — if any PII is detected, the request must not proceed.
  • Use log_only during development to understand how much PII is flowing before enforcing redaction.