Overview
RDK can automatically redact Personally Identifiable Information (PII) from your traces before they’re sent to the collector. This helps you maintain compliance while still getting valuable observability data.Quick Start
Enable built-in redaction
Passredact_pii=True to init() to enable default PII redaction:
Custom redaction
For fine-grained control, build a redactor withRedactorConfig:
Built-in Patterns
| Type | Example | Redacted As |
|---|---|---|
john@example.com | [EMAIL REDACTED] | |
| Phone | 555-123-4567 | [PHONE REDACTED] |
| SSN | 123-45-6789 | [SSN REDACTED] |
| Credit Card | 4111-1111-1111-1111 | [CARD REDACTED] |
| API Key | sk-abc123... | [API_KEY REDACTED] |
RedactorConfig Fields
Redact email addresses.
Redact phone numbers (formats:
555-123-4567, 555.123.4567, 5551234567).Redact US Social Security Numbers (
123-45-6789).Redact 16-digit credit card numbers.
Redact API keys matching common patterns (
sk-, api_key, bearer ...).List of
(compiled_pattern, replacement_string) tuples applied after built-in patterns.A function applied to each string value before the built-in patterns. Use for custom logic that regex can’t express.
Utility Functions
redact_all_pii(value) — One-shot redaction using all default patterns. Useful for sanitizing data outside of traces.
create_default_redactor() — Returns a reusable redactor with all defaults enabled.
What Gets Redacted
Redaction is applied to:- Span inputs — messages sent to the LLM
- Span outputs — responses from the LLM
- Tool arguments and results
- Trace/span IDs
- Timestamps
- Token counts
- Model names
- Metadata keys (only values are scanned)
Best Practices
- Always enable PII redaction in production
- Test custom patterns against realistic sample data before deploying
- Use
custom_redactorfor preprocessing (e.g., tokenization) before regex matching
See Also
- create_redactor() — API reference
- RedactorConfig — Full config reference

