Audit Mode
Detect PII without anonymizing — assess before you enforce
Audit mode lets you see what PII Rdakt AI would detect and anonymize, without actually modifying any requests. Use it to assess your application's PII exposure before enabling anonymization.
Enable Audit Mode
Via YAML
mode: auditVia Code
from rdakt_ai import RdaktMiddleware
middleware = RdaktMiddleware(mode="audit")Override at Middleware Level
from rdakt_ai import RdaktMiddleware, load_config
config = load_config("rdakt.yaml") # mode: active
middleware = RdaktMiddleware(config=config, mode="audit") # Override to auditWhat Happens in Audit Mode
| Step | Active Mode | Audit Mode |
|---|---|---|
| Detection | Runs | Runs |
on_entities_detected callback | Fires | Fires |
| Anonymization | Replaces PII | Skipped |
on_anonymized callback | Fires | Does not fire |
| Request to LLM | Anonymized text | Original text |
| Response deanonymization | Runs | Skipped |
Logging Detected Entities
Combine audit mode with callbacks to build a PII inventory:
import json
from rdakt_ai import RdaktMiddleware, Entity
pii_log: list[dict] = []
def log_pii(entities: list[Entity], text: str) -> None:
for entity in entities:
pii_log.append({
"type": entity.type,
"value": entity.value,
"position": f"{entity.start}-{entity.end}",
})
middleware = RdaktMiddleware(
mode="audit",
on_entities_detected=log_pii,
)
# After running your test suite through the middleware:
print(json.dumps(pii_log, indent=2))Workflow
- Deploy with
mode: audit— observe what PII is flowing to your LLM provider - Review the audit log — check for false positives, missing patterns
- Add custom patterns if needed for domain-specific PII
- Switch to
mode: active— enable anonymization