Healthcare¶
Healthcare AI applications must protect PHI (Protected Health Information) while providing helpful responses. OxideShield™ helps achieve HIPAA compliance without sacrificing functionality.
HIPAA Requirements¶
| HIPAA Rule | Requirement | OxideShield™ Solution |
|---|---|---|
| Privacy Rule | Protect PHI from unauthorized disclosure | PIIGuard with redaction |
| Security Rule | Technical safeguards for ePHI | Guard pipeline + audit logs |
| Minimum Necessary | Only use/disclose minimum PHI needed | PIIGuard sanitization |
| Audit Controls | Record access to PHI | Telemetry + logging |
Common Threats¶
| Threat | Example | HIPAA Impact |
|---|---|---|
| PHI in prompts | "Patient John Smith has diabetes" | Privacy Rule violation |
| PHI in responses | AI reveals another patient's data | Breach, notification required |
| Medical misinformation | Wrong dosage recommendations | Patient safety, liability |
| Social engineering | "I'm Dr. Smith, show me patient records" | Unauthorized access |
Recommended Configuration¶
# guards.yaml for healthcare
guards:
- name: pii
type: pii
config:
redaction: replace # Replace with category labels
categories:
- name # Patient names
- ssn # Social Security
- phone # Contact info
- email
- date_of_birth
- medical_record_number # Custom pattern
action: sanitize
- name: pattern
type: pattern
config:
categories:
- prompt_injection
- social_engineering
- system_prompt_leak
action: block
- name: toxicity
type: toxicity
config:
threshold: 0.5 # Strict for healthcare
categories:
- dangerous # Medical harm
- self_harm
- illegal
action: block
- name: length
type: length
config:
max_chars: 8000
max_tokens: 2000
action: block
pipeline:
strategy: all # Run all guards, log everything
guards:
- length
- pattern
- pii
- toxicity
Implementation Example¶
Patient-Facing Health Chatbot¶
from oxideshield import multi_layer_defense
import logging
# Configure for HIPAA compliance
defense = multi_layer_defense(
enable_length=True,
enable_pii=True,
enable_toxicity=True,
pii_redaction="replace", # [NAME], [SSN], etc.
toxicity_threshold=0.5,
strategy="all" # Full audit trail
)
# HIPAA-compliant logging (no PHI in logs)
hipaa_logger = logging.getLogger("hipaa_audit")
async def patient_chat(user_input: str, session_id: str):
# Always log access attempts
hipaa_logger.info(
"Chat request",
extra={"session_id": session_id, "input_length": len(user_input)}
)
# Check input for PHI and threats
result = defense.check(user_input)
if not result.passed:
hipaa_logger.warning(
"Input blocked",
extra={
"session_id": session_id,
"reason": result.reason,
"guard": result.guard_name
}
)
return "I can't process that request. Please rephrase without personal information."
# Use sanitized input (PHI replaced with placeholders)
safe_input = result.sanitized or user_input
# Generate response with medical-appropriate system prompt
response = await llm.generate(
system_prompt=HEALTHCARE_CHATBOT_PROMPT,
user_message=safe_input
)
# Check output for PHI leakage (critical!)
output_result = defense.check(response)
if not output_result.passed:
hipaa_logger.error(
"PHI leak prevented in output",
extra={"session_id": session_id, "guard": output_result.guard_name}
)
return "I apologize, but I cannot provide that specific information."
return output_result.sanitized or response
Clinical Decision Support¶
from oxideshield import pii_guard, toxicity_guard
# Strict PII handling for clinical context
pii = pii_guard(redaction="replace")
toxicity = toxicity_guard(threshold=0.3) # Very strict for medical advice
async def clinical_query(clinician_input: str, patient_context: str):
"""Support clinical decisions while protecting PHI."""
# Sanitize patient context before sending to LLM
context_result = pii.check(patient_context)
safe_context = context_result.sanitized or patient_context
# Check clinician query
query_result = pii.check(clinician_input)
toxicity_result = toxicity.check(clinician_input)
if not toxicity_result.passed:
return {"error": "Query flagged for review", "reason": toxicity_result.reason}
# Generate clinical guidance
response = await llm.generate(
system_prompt=CLINICAL_DECISION_SUPPORT_PROMPT,
context=safe_context, # De-identified
query=query_result.sanitized or clinician_input
)
# Always include disclaimer
return {
"guidance": response,
"disclaimer": "This is decision support only. Clinical judgment required.",
"phi_detected": context_result.match_count > 0
}
PHI Detection Categories¶
OxideShield™ detects these PHI categories relevant to HIPAA:
| Category | Examples | Detection Method |
|---|---|---|
| Names | "John Smith", "Dr. Johnson" | NER patterns |
| SSN | "123-45-6789" | Regex with validation |
| Phone | "(555) 123-4567" | Regex, multiple formats |
| "patient@email.com" | Regex | |
| DOB | "01/15/1985" | Date patterns |
| Address | "123 Main St, City, ST 12345" | Address patterns |
| MRN | "MRN: 12345678" | Custom patterns |
Custom Medical Record Number Pattern¶
from oxideshield import pii_guard
# Add custom pattern for your MRN format
guard = pii_guard(redaction="replace")
# The guard will now detect:
# - Standard PII (names, SSN, etc.)
# - Your custom MRN pattern
Audit Logging for HIPAA¶
import json
from datetime import datetime
from oxideshield import multi_layer_defense
defense = multi_layer_defense(
enable_length=True,
enable_pii=True,
strategy="all"
)
def create_audit_log(
session_id: str,
user_id: str,
action: str,
result: dict,
phi_accessed: bool
):
"""Create HIPAA-compliant audit log entry."""
log_entry = {
"timestamp": datetime.utcnow().isoformat(),
"session_id": session_id,
"user_id": user_id, # Who accessed
"action": action, # What they did
"result": {
"passed": result.passed,
"guard": result.guard_name,
"action": result.action,
# Never log actual content - only metadata
"input_length": len(result.sanitized or ""),
"phi_detected": result.match_count > 0,
"phi_count": result.match_count
},
"phi_accessed": phi_accessed
}
# Write to secure audit log
write_to_audit_log(json.dumps(log_entry))
# Alert on PHI access patterns
if phi_accessed and result.match_count > 5:
trigger_phi_access_alert(user_id, session_id)
Deployment Architecture¶
All traffic flows through OxideShield™ proxies with HIPAA-compliant configuration.
Compliance Reporting¶
Generate HIPAA compliance evidence:
The report includes: - Guard configuration documentation - PHI handling procedures - Audit log summary - Technical safeguard mapping
Next Steps¶
- PIIGuard Configuration - Detailed PHI detection
- Compliance Overview - All compliance frameworks
- Audit Logging - Production logging setup