Components
- Role Filter — Pre-filters context by access level, scans outbound messages for leakage
- PHI Audit — HIPAA-compliant logging of all PHI access events
- Family Editor — Edit-not-write file updates with backup and validation
- Approval Pipeline — Coordinator confirmation for high-risk changes
1. Role Filter
Module:runtime/enforcement/role_filter.py
Two-layer defense:
- PRE-FILTER: Strip sections from
family.mdbefore the AI sees them - POST-CHECK: Scan outbound messages for medication/condition keywords
Access Matrix
runtime/enforcement/role_filter.py:22
Pre-Filter: Context Scoping
Raw
family.md content (full unfiltered file)Member’s access level:
"full", "schedule+meds", "schedule", "provider", or "limited"- Parses
family.mdinto header block + typed sections - Keeps only sections listed in the access matrix
- Reassembles with filtered sections only
- The AI never sees restricted data
runtime/enforcement/role_filter.py:126
If access level is unknown, returns header only with message:
[Access level not recognized. No care data loaded.]Post-Check: Outbound Leakage Detection
SMS text about to be sent
Recipient’s access level
LeakageResult dataclass
Whether the message is safe to send
Detected category violations (e.g.,
["medications", "conditions"])Actual terms found (e.g.,
["lisinopril", "10mg", "diabetes"])runtime/enforcement/role_filter.py:235
Detection Patterns:
Medication patterns (if "medications" not in allowed sections):
- Suffixes:
-pril,-sartan,-statin,-formin,-olol,-pine,-azole,-cycline,-mycin - Dosages:
10mg,500 mg,25mcg,5ml
"care_recipient" not in allowed sections):
- Keywords:
diabetes,hypertension,alzheimer,dementia,diagnosis,prescription - Medical terms:
A1C,blood pressure,blood sugar,cholesterol,insulin
Blocked Response: If leakage is detected, the handler replaces the AI response with:
"I'm sorry, I can't share that information with your access level. Please contact the care coordinator if you need more details."The PHI audit logger records the block event with leaked terms.Helper Functions
["*"] for full access.
Location: runtime/enforcement/role_filter.py:160
"full" returns True.
Location: runtime/enforcement/role_filter.py:169
2. PHI Audit Logger
Module:runtime/enforcement/phi_audit.py
Every interaction that touches Protected Health Information gets logged with WHO/WHAT/WHEN/WHY/WHAT HAPPENED.
Initialization
/logs/{YYYY-MM-DD}/phi_access.log (JSONL format)
Log Context Load
runtime/enforcement/phi_audit.py:41
Log Response Sent
runtime/enforcement/phi_audit.py:62
Log Response Blocked
runtime/enforcement/phi_audit.py:83
Log Unknown Number
phi_disclosed: false (hard rule).
Location: runtime/enforcement/phi_audit.py:119
Event Format
All events are written as JSON lines:3. Family Editor
Module:runtime/enforcement/family_editor.py
Mechanical enforcement of edit-not-write semantics. The family.md file IS the database.
Edit Requirements
Every edit must be:- Atomic — either the whole edit succeeds or nothing changes
- Backed up — timestamped copy before any modification
- Surgical — only the target section changes; everything else untouched
- Validated — the result still parses into valid sections
Apply Updates
Path to
family.md (or schedule.md, medications.md)List of structured updates to apply
Custom backup directory (defaults to
{family_dir}/backups)EditResult dataclass
Whether all updates were applied successfully
Path to timestamped backup file
Number of updates successfully applied
Number of updates that failed (logged in
errors)List of error messages for failed updates
List of section keys that were changed
runtime/enforcement/family_editor.py:203
FileUpdate Structure
runtime/enforcement/family_editor.py:51
Operations
Append:old_content not found.
Resolve Issue:
- [ ] to - [x] for the matching issue line.
File Routing
Some sections target split files instead offamily.md:
runtime/enforcement/family_editor.py:29
runtime/enforcement/family_editor.py:38
Validation
- Has a top-level
# header - Has at least one
## section - All sections parse correctly
- No empty sections
(is_valid, list_of_issues)
If validation fails after edits, NOTHING is written. The backup remains intact.
Location: runtime/enforcement/family_editor.py:163
4. Approval Pipeline
Module:runtime/enforcement/approval_pipeline.py
Mechanical enforcement of coordinator confirmation for high-risk changes.
What Requires Approval
runtime/enforcement/approval_pipeline.py:40
These section+operation pairs ALWAYS require YES/NO confirmation from a member with can_approve access.
Classify Updates
auto_apply— Safe to apply immediatelyneeds_approval— Requires confirmation
ClassifiedUpdates dataclass
Updates that can be applied without confirmation
Updates requiring approval, each with a reason string
runtime/enforcement/approval_pipeline.py:83
Create Pending Approval
{family_dir}/pending_approvals.json and returns the approval object with a unique ID.
Location: runtime/enforcement/approval_pipeline.py:140
Resolve Approval
Family directory path
8-character hex ID from the pending approval
True for approval, False for rejectionPhone number of the approver (must be in
approver_phones)Whether the resolution succeeded
"approved", "rejected", "not_found", "already_resolved", "expired", or "unauthorized"Human-readable description of the change
Result from
family_editor.apply_updates() if approved, otherwise nullruntime/enforcement/approval_pipeline.py:183
Detect Approval Response
(is_approved, approval_id_or_none)
(True, id)→ approved(False, id)→ rejected(None, None)→ not an approval response
runtime/enforcement/approval_pipeline.py:337
Patterns:
- YES:
yes,y,approve,confirm,ok,go ahead,do it - NO:
no,n,reject,deny,cancel,don't,nope
"YES abc123" or "NO abc123" with explicit ID reference.
Format Confirmation SMS
runtime/enforcement/approval_pipeline.py:370
Expiry
Pending approvals expire after 24 hours (configurable viaEXPIRY_HOURS).
runtime/enforcement/approval_pipeline.py:305
Integration
The SMS handler integrates all four components:runtime/scripts/sms_handler.py:958-1172
Related
- SMS Handler — Main pipeline that calls enforcement layer
- Configuration — Paths and settings