Creates and configures an anonymizer instance for PII detection and replacement.
Signature
Parameters
config (optional)
mode
string
default: "'pseudonymize'"
Anonymization mode:
'pseudonymize' — Reversible. Returns an encrypted piiMap for later rehydration.
'anonymize' — Irreversible. No piiMap is returned; PII is permanently removed.
NER model configuration Show NERConfig properties
Model mode: 'disabled' | 'quantized' | 'standard' | 'custom'
Custom model path (required when mode is 'custom')
Custom vocab path (required when mode is 'custom')
Auto-download model if not present
Confidence thresholds per PII type (0.0-1.0)
Download progress callback
Enable case-insensitive fallback for detecting lowercase names. Runs a second NER pass on title-cased text and merges new detections. Doubles NER inference time but catches names like "tom" that the case-sensitive model would otherwise miss.
Confidence penalty multiplier for case-fallback detections (0.0–1.0). Applied as confidence * caseFallbackPenalty. Lower values are stricter.
Inference backend: 'local' (ONNX on device) or 'inference-server' (remote GPU server)
URL of the inference server (required when backend is 'inference-server')
Inference server request timeout in milliseconds
Semantic enrichment configuration Show SemanticConfig properties
Enable semantic enrichment (gender/scope attributes)
Auto-download semantic data if not present
Download progress callback
Encryption key provider. If not provided, generates a random key.
Storage provider for session-based PII map persistence
Default anonymization policy
Secrets/credentials detection configuration Show SecretsConfig properties
Enable secrets detection (API keys, tokens, connection strings, etc.)
Paths to .env files for literal value redaction
Redact secret values found in .env files
Additional patterns to match secret key names
Minimum value length to consider a secret
Tag format for PII placeholder tags. Controls the delimiters and keyword. Show TagFormat properties
Opening delimiter (e.g., "<" for XML, "[[" for bracket style)
Closing delimiter (e.g., "/>" for XML self-closing, "]]" for bracket style)
Tag keyword. Allows using e.g., "REDACTED" instead of "PII"
onValidationWarning
(warnings: Array<{ code: string; message: string }>) => void
Callback for validation warnings. When not provided, warnings are silently ignored — check stats.leakScanPassed in the result instead.
Custom recognizer registry (uses default if not provided)
Returns
An Anonymizer instance with these methods:
Examples
Basic (Regex Only)
With NER
With Semantic Enrichment
With Storage
Irreversible Anonymization
With Inference Server
With Custom Thresholds
With Custom Policy
Excluding Countries and Regions