Commit 59e069e
User
feat(high): Add comprehensive PII audit trail for compliance
Implemented immutable audit logging for PII detection:
- PIIAuditTrail class with SQLite storage
- PIIAuditRecord dataclass for audit entries
- Automatic logging of all PII scans and blocking decisions
- Retention policy enforcement (default: 90 days)
- Query interface for investigations and reporting
Features:
- Immutable audit records (never modified after creation)
- SHA-256 hashing of field values (never store actual PII)
- Comprehensive metadata (session_id, timestamp, confidence, risk_level)
- Detection method tracking (rule-based, ai-based, hybrid)
- Blocking decision audit trail
- Statistics and compliance reporting
Integration:
- Integrated into PIIDetector.scan_text()
- Integrated into PIIDetector.should_block_processing()
- Automatic logging on every PII scan
- Session ID tracking for correlation
- Image path tracking for context
Database schema:
- SQLite with indexed columns for fast queries
- Indexes on: session_id, timestamp, blocked, risk_level
- Automatic cleanup of old records
- Export capabilities for compliance reports
Benefits:
- Full compliance with GDPR audit requirements
- Transparent PII detection decisions
- Investigation capabilities for false positives/negatives
- Statistical analysis for model improvement
- Retention policy enforcement
Tests:
- 10 comprehensive unit tests for audit trail
- Test record creation, storage, retrieval
- Test filtering by session, date, blocked status
- Test cleanup and statistics
- All audit trail tests passing (10/10)
Note: Updated PIIDetector.should_block_processing() to async
to support audit trail logging. Updated all call sites.
Resolves: openai#8 (HIGH priority)
Impact: Enables compliance and transparency for PII validation1 parent e5d7b4d commit 59e069e
File tree
5 files changed
+1882
-16
lines changed- examples/erni-foto-agency
- erni_foto_agency
- erni_agents
- security
- utils
- tests/unit
5 files changed
+1882
-16
lines changed
0 commit comments