[presidio] extra). DLP runs before policy evaluation so detections become first-class policy fields.
See DLP concepts for the philosophy and policy patterns. This page is the API.
Enable
Three knobs — pick one:Modes
| Constant | Value | Behavior |
|---|---|---|
DLP_MODE_OFF | "off" | Detector disabled. |
DLP_MODE_REGEX | "regex" | Built-in regex patterns only. |
DLP_MODE_PRESIDIO | "presidio" | Presidio NER + regex (requires [presidio] extra). |
DLP_MODE_AUTO | "auto" | Presidio if available, otherwise regex. |
DlpDetection
| Field | Notes |
|---|---|
detected | True if any pattern fired. False only if the detector ran and found nothing. |
severity | The highest severity tier of any match. |
types | Sorted list of matched type names (EMAIL, SSN, AWS_KEY, …). |
matches | Detailed match records — value (sometimes redacted), location, type, severity. |
DlpMatch
Custom detector
Any object with this shape:dlp=MyDetector() on bootstrap. The SDK calls .detect() once per evaluate(), passing the combined metadata dict (input + args + kwargs).
Built-in regex patterns
The default regex detector covers:| Type | Severity |
|---|---|
EMAIL | low |
PHONE | low |
IP_ADDRESS | low |
JWT | medium |
GITHUB_TOKEN | medium |
SLACK_TOKEN | medium |
GENERIC_API_KEY | medium |
SSN | high |
CREDIT_CARD | high |
AWS_ACCESS_KEY | high |
MEDICAL_RECORD_NUMBER | high |
_PATTERNS map.
Failures
If a detector raises duringdetect(), the SDK logs and treats it as no-detection. Your evaluate() proceeds with dlp_detected: false. Fix the detector and you’re back. Detector exceptions never propagate up to the caller.