HIPAA Compliance Auditor
A clinical-grade PII/PHI detection and de-identification tool for healthcare text data.
Overview
This skill analyzes text for HIPAA-protected identifiers and automatically redacts or anonymizes them. It uses a combination of regex patterns, NLP entity recognition, and contextual analysis to identify 18 HIPAA identifier categories.
Features
- 18 HIPAA Identifiers Detection: Names, dates, SSN, MRN, phone/fax, email, geographic data, etc.
- Automatic De-identification: Replace PII with semantic tokens (e.g.,
[PATIENT_NAME], [DATE_1])
- Context-Aware Detection: Distinguishes between similar patterns (dates vs. lab values)
- Audit Logging: Track all redaction actions for compliance documentation
- Confidence Scoring: Flag uncertain detections for manual review
Usage
Command Line
python scripts/main.py --input "patient_text.txt" --output "deidentified.txt"
python scripts/main.py --text "Patient John Doe, SSN 123-45-6789..." --audit-log audit.json
Python API
from scripts.main import HIPAAAuditor
auditor = HIPAAAuditor()
result = auditor.deidentify("Patient John Doe was admitted on 2024-01-15...")
print(result.cleaned_text) # De-identified output
print(result.detected_pii) # List of found PII entities
Parameters
| Parameter |
Type |
Default |
Required |
Description |
--input, -i |
string |
- |
No |
Path to input text file |
--text |
string |
- |
No |
Direct text input (alternative to file) |
--output, -o |
string |
- |
No |
Path for de-identified output file |
--audit-log |
string |
- |
No |
Path for JSON audit log |
--confidence |
float |
0.7 |
No |
Minimum confidence threshold (0.0-1.0) |
--preserve-structure |
bool |
true |
No |
Maintain document structure |
--custom-patterns |
string |
- |
No |
Path to custom regex patterns JSON |
HIPAA Identifier Categories Detected
- Names (patient, relatives, employers)
- Geographic subdivisions smaller than state
- Dates (except year) related to individual
- Phone numbers
- Fax numbers
- Email addresses
- SSN
- Medical record numbers
- Health plan beneficiary numbers
- Account numbers
- Certificate/license numbers
- Vehicle identifiers
- Device identifiers
- URLs
- IP addresses
- Biometric identifiers
- Full-face photos
- Any other unique identifying numbers
Output Format
De-identified Text
Original identifiers replaced with semantic tags:
[PATIENT_NAME_1], [PATIENT_NAME_2] ...
[DATE_1], [DATE_2] ...
[SSN_1]
[PHONE_1], [PHONE_2] ...
[EMAIL_1]
[MRN_1] (Medical Record Number)
[ADDRESS_1]
Audit Log JSON
{
"timestamp": "2024-01-15T10:30:00Z",
"input_hash": "sha256:abc123...",
"detections": [
{
"type": "PATIENT_NAME",
"position": [10, 18],
"confidence": 0.95,
"replacement": "[PATIENT_NAME_1]",
"original_length": 8
}
],
"statistics": {
"total_pii_found": 5,
"categories_detected": ["NAME", "DATE", "PHONE", "SSN"]
}
}
Technical Architecture
- Preprocessing: Normalize text encoding, handle line breaks
- Regex Engine: Pattern matching for structured identifiers (SSN, phone, email, MRN)
- NLP Pipeline: spaCy NER for names, organizations, locations
- Context Filter: Remove false positives (e.g., "Dr. Smith" vs. "smith fracture")
- Replacement Engine: Sequential replacement with semantic tokens
- Validation: Ensure no original PII remains in output
Dependencies
- Python 3.9+
- spaCy (en_core_web_trf or en_core_web_lg)
- regex (for advanced pattern matching)
- Presidio (optional, for enhanced PII detection)
See references/requirements.txt for full dependency list.
Limitations & Warnings
⚠️ CRITICAL: This tool is designed as a helper, not a replacement for human review.
- Context-dependent PII (e.g., rare disease names + location) may not be fully detected
- Unstructured narrative text may contain identifying information not caught by patterns
- Always perform manual QA on output before HIPAA-compliant release
- AI Autonomous Acceptance Status: 需人工检查 (Requires Manual Review)
References
references/hipaa_safe_harbor_guide.pdf - HIPAA Safe Harbor de-identification standards
references/pii_patterns.json - Complete regex pattern definitions
references/test_cases/ - Sample clinical texts with expected outputs
references/requirements.txt - Python dependencies
Technical Difficulty: High
Complex NLP pipelines, contextual disambiguation, regulatory compliance requirements.
Risk Assessment
| Risk Indicator |
Assessment |
Level |
| Code Execution |
Python/R scripts executed locally |
Medium |
| Network Access |
No external API calls |
Low |
| File System Access |
Read input files, write output files |
Medium |
| Instruction Tampering |
Standard prompt guidelines |
Low |
| Data Exposure |
Output files saved to workspace |
Low |
Security Checklist
Prerequisites
# Python dependencies
pip install -r requirements.txt
Evaluation Criteria
Success Metrics
Test Cases
- Basic Functionality: Standard input → Expected output
- Edge Case: Invalid input → Graceful error handling
- Performance: Large dataset → Acceptable processing time
Lifecycle Status
- Current Stage: Draft
- Next Review Date: 2026-03-06
- Known Issues: None
- Planned Improvements:
- Performance optimization
- Additional feature support
1---2name: hipaa-compliance-auditor3description: Automatically detect and de-identify PII (Personal Identifiable Information) and PHI (Protected Health Information) from clinical/medical text to ensure HIPAA compliance. Trigger when processing medical records, patient data, clinical notes, insurance information, or any healthcare-related text containing potential patient identifiers.4license: MIT5---67# HIPAA Compliance Auditor89A clinical-grade PII/PHI detection and de-identification tool for healthcare text data.1011## Overview1213This skill analyzes text for HIPAA-protected identifiers and automatically redacts or anonymizes them. It uses a combination of regex patterns, NLP entity recognition, and contextual analysis to identify 18 HIPAA identifier categories.1415## Features1617- **18 HIPAA Identifiers Detection**: Names, dates, SSN, MRN, phone/fax, email, geographic data, etc.18- **Automatic De-identification**: Replace PII with semantic tokens (e.g., `[PATIENT_NAME]`, `[DATE_1]`)19- **Context-Aware Detection**: Distinguishes between similar patterns (dates vs. lab values)20- **Audit Logging**: Track all redaction actions for compliance documentation21- **Confidence Scoring**: Flag uncertain detections for manual review2223## Usage2425### Command Line26```bash27python scripts/main.py --input "patient_text.txt" --output "deidentified.txt"28python scripts/main.py --text "Patient John Doe, SSN 123-45-6789..." --audit-log audit.json29```3031### Python API32```python33from scripts.main import HIPAAAuditor3435auditor = HIPAAAuditor()36result = auditor.deidentify("Patient John Doe was admitted on 2024-01-15...")37print(result.cleaned_text) # De-identified output38print(result.detected_pii) # List of found PII entities39```4041## Parameters4243| Parameter | Type | Default | Required | Description |44|-----------|------|---------|----------|-------------|45| `--input`, `-i` | string | - | No | Path to input text file |46| `--text` | string | - | No | Direct text input (alternative to file) |47| `--output`, `-o` | string | - | No | Path for de-identified output file |48| `--audit-log` | string | - | No | Path for JSON audit log |49| `--confidence` | float | 0.7 | No | Minimum confidence threshold (0.0-1.0) |50| `--preserve-structure` | bool | true | No | Maintain document structure |51| `--custom-patterns` | string | - | No | Path to custom regex patterns JSON |5253## HIPAA Identifier Categories Detected54551. Names (patient, relatives, employers)562. Geographic subdivisions smaller than state573. Dates (except year) related to individual584. Phone numbers595. Fax numbers606. Email addresses617. SSN628. Medical record numbers639. Health plan beneficiary numbers6410. Account numbers6511. Certificate/license numbers6612. Vehicle identifiers6713. Device identifiers6814. URLs6915. IP addresses7016. Biometric identifiers7117. Full-face photos7218. Any other unique identifying numbers7374## Output Format7576### De-identified Text77Original identifiers replaced with semantic tags:78- `[PATIENT_NAME_1]`, `[PATIENT_NAME_2]` ...79- `[DATE_1]`, `[DATE_2]` ...80- `[SSN_1]`81- `[PHONE_1]`, `[PHONE_2]` ...82- `[EMAIL_1]`83- `[MRN_1]` (Medical Record Number)84- `[ADDRESS_1]`8586### Audit Log JSON87```json88{89 "timestamp": "2024-01-15T10:30:00Z",90 "input_hash": "sha256:abc123...",91 "detections": [92 {93 "type": "PATIENT_NAME",94 "position": [10, 18],95 "confidence": 0.95,96 "replacement": "[PATIENT_NAME_1]",97 "original_length": 898 }99 ],100 "statistics": {101 "total_pii_found": 5,102 "categories_detected": ["NAME", "DATE", "PHONE", "SSN"]103 }104}105```106107## Technical Architecture1081091. **Preprocessing**: Normalize text encoding, handle line breaks1102. **Regex Engine**: Pattern matching for structured identifiers (SSN, phone, email, MRN)1113. **NLP Pipeline**: spaCy NER for names, organizations, locations1124. **Context Filter**: Remove false positives (e.g., "Dr. Smith" vs. "smith fracture")1135. **Replacement Engine**: Sequential replacement with semantic tokens1146. **Validation**: Ensure no original PII remains in output115116## Dependencies117118- Python 3.9+119- spaCy (en_core_web_trf or en_core_web_lg)120- regex (for advanced pattern matching)121- Presidio (optional, for enhanced PII detection)122123See `references/requirements.txt` for full dependency list.124125## Limitations & Warnings126127⚠️ **CRITICAL**: This tool is designed as a helper, not a replacement for human review.128129- Context-dependent PII (e.g., rare disease names + location) may not be fully detected130- Unstructured narrative text may contain identifying information not caught by patterns131- Always perform manual QA on output before HIPAA-compliant release132- **AI Autonomous Acceptance Status**: 需人工检查 (Requires Manual Review)133134## References135136- `references/hipaa_safe_harbor_guide.pdf` - HIPAA Safe Harbor de-identification standards137- `references/pii_patterns.json` - Complete regex pattern definitions138- `references/test_cases/` - Sample clinical texts with expected outputs139- `references/requirements.txt` - Python dependencies140141## Technical Difficulty: High142143Complex NLP pipelines, contextual disambiguation, regulatory compliance requirements.144145## Risk Assessment146147| Risk Indicator | Assessment | Level |148|----------------|------------|-------|149| Code Execution | Python/R scripts executed locally | Medium |150| Network Access | No external API calls | Low |151| File System Access | Read input files, write output files | Medium |152| Instruction Tampering | Standard prompt guidelines | Low |153| Data Exposure | Output files saved to workspace | Low |154155## Security Checklist156157- [ ] No hardcoded credentials or API keys158- [ ] No unauthorized file system access (../)159- [ ] Output does not expose sensitive information160- [ ] Prompt injection protections in place161- [ ] Input file paths validated (no ../ traversal)162- [ ] Output directory restricted to workspace163- [ ] Script execution in sandboxed environment164- [ ] Error messages sanitized (no stack traces exposed)165- [ ] Dependencies audited166## Prerequisites167168```bash169# Python dependencies170pip install -r requirements.txt171```172173## Evaluation Criteria174175### Success Metrics176- [ ] Successfully executes main functionality177- [ ] Output meets quality standards178- [ ] Handles edge cases gracefully179- [ ] Performance is acceptable180181### Test Cases1821. **Basic Functionality**: Standard input → Expected output1832. **Edge Case**: Invalid input → Graceful error handling1843. **Performance**: Large dataset → Acceptable processing time185186## Lifecycle Status187188- **Current Stage**: Draft189- **Next Review Date**: 2026-03-06190- **Known Issues**: None191- **Planned Improvements**: 192 - Performance optimization193 - Additional feature support