Configuration
Configure Rdakt AI with YAML or code
Rdakt AI can be configured via a YAML file or programmatically in Python.
YAML Configuration
Create a rdakt.yaml file:
mode: active
on_error: warn_and_forward
pipeline:
- regex
session:
store: memory
entities:
EMAIL:
strategy: token
PERSON:
strategy: synthetic
SSN:
strategy: tokenLoad it in your code:
from rdakt_ai import RdaktMiddleware, load_config
config = load_config("rdakt.yaml")
middleware = RdaktMiddleware(config=config)Configuration Options
mode
| Value | Behavior |
|---|---|
active (default) | Detect and anonymize PII |
audit | Detect and log PII, but forward original text |
on_error
| Value | Behavior |
|---|---|
warn_and_forward (default) | Log error, forward unanonymized |
block | Raise exception, don't send request |
pipeline
List of detectors to run, in order:
pipeline:
- regex # Built-in regex patterns
- ner: # spaCy NER (requires rdakt-ai[ner])
model: en_core_web_smentities
Per-entity-type configuration:
entities:
EMAIL:
strategy: token # Override strategy for this type
EMPLOYEE_ID:
pattern: "EMP-\\d{6}" # Custom regex pattern
strategy: tokensession
Session store backend:
# In-memory (default)
session:
store: memory
# SQLite
session:
store: sqlite
path: /var/lib/rdakt/sessions.db
# Redis
session:
store: redis
url: redis://localhost:6379
ttl: 3600
prefix: "rdakt:"Programmatic Configuration
from rdakt_ai import RdaktMiddleware, RdaktConfig, EntityConfig, SessionConfig
config = RdaktConfig(
mode="active",
on_error="block",
pipeline=["regex", {"ner": {"model": "en_core_web_sm"}}],
entities={
"EMAIL": EntityConfig(strategy="token"),
"PERSON": EntityConfig(strategy="synthetic"),
"EMPLOYEE_ID": EntityConfig(pattern=r"EMP-\d{6}", strategy="token"),
},
session=SessionConfig(store="sqlite", path="sessions.db"),
)
middleware = RdaktMiddleware(config=config)Override at Middleware Level
The middleware constructor accepts mode and error_policy overrides that take precedence over the config:
config = load_config("rdakt.yaml") # mode: active
# Override to audit mode for this specific middleware instance
middleware = RdaktMiddleware(config=config, mode="audit")ontology
Optional. A list of per-field rules keyed by JSONPath, applied before the global pipeline so that structured fields (internal IDs, domain identifiers, addresses) get treated specifically rather than scanned as free text. Default is no ontology — global pipeline runs on every text field.
ontology:
fields:
- path: "$.messages[*].content"
detect: ["EMAIL", "PHONE"]
- path: "$.messages[*].metadata.user_id"
replace_with_synthetic:
type: USER_ID
format: "user-{n:06d}"
- path: "$.messages[*].context.case_number"
detect_via_regex: '\bCASE-\d{4}-\d{6}\b'
detect_via_regex_as: CASE_NUMBER
mask_strategy: hashSee the Per-field PII ontology guide for the full rule reference, JSONPath subset, and validation rules.
Example Configurations
Minimal (defaults)
mode: active
on_error: warn_and_forward
pipeline:
- regex
session:
store: memoryProduction
mode: active
on_error: block
pipeline:
- regex
- ner:
model: en_core_web_sm
session:
store: sqlite
path: /var/lib/rdakt/sessions.db
entities:
EMAIL:
strategy: token
PERSON:
strategy: synthetic
PHONE:
strategy: token
CREDIT_CARD:
strategy: token
EMPLOYEE_ID:
pattern: "EMP-\\d{6}"
strategy: tokenDistributed (Redis)
mode: active
on_error: warn_and_forward
pipeline:
- regex
session:
store: redis
url: redis://localhost:6379
ttl: 3600
prefix: "rdakt:"