Friend runs small pharmacy. 500 prescriptions monthly. Processing prescriptions manually taking 15 minutes each. Hired pharmacy tech just to handle paperwork. Asked if n8n could help.
Built him prescription verification workflow using the personal assistant agent template as base. Gmail trigger watches for prescription emails. Extracts patient info, prescriber details, medication data, dosage instructions. Logs everything to Google Sheets. Sends Slack alerts for urgent prescriptions.
Working great for 2 months. Then compliance audit happened.
THE PROBLEM:
System approved 47 Schedule II controlled substance prescriptions with refills. Schedule II drugs (oxycodone, hydrocodone, morphine) cannot legally have refills. Federal law. Audit found violations. License at risk.
n8n workflow extracted all data perfectly - medication names, dosage, refill counts at 96% confidence using document extraction node. But never validated against pharmacy regulations.
THE FIX:
Added compliance validation layer to existing n8n template. After document extraction node, built custom function node checking:
Schedule classification - if medication is Schedule II, flag any refill count over zero as violation
Prescription age - calculate days since prescription date, flag Schedule II over 30 days old, III-V over 180 days
DEA format validation - regex check prescriber DEA number follows required pattern (two letters + seven digits)
Required field validation - ensure patient ID and date of birth present
Connected to IF node routing violations to manual review Slack channel. Valid prescriptions continue to auto-approval.
Tested against 200 historical prescriptions. Compliance layer caught 94% of regulatory issues.
RESULT:
Reprocessed 1,500 past prescriptions through updated workflow. Found 73 additional compliance violations. Corrected before final audit report. State board accepted corrective action plan. License maintained.
Now processing 520 prescriptions monthly. 3% flagged for manual compliance review. 97% auto-verified safely. Zero violations in past 4 months.
THE LESSON:
Data extraction and compliance validation are different systems. Your n8n workflow can read prescriptions perfectly and still violate regulations if validation logic missing.
Build compliance checks as separate nodes after extraction. Different expertise. Different failure modes.
Templates in n8n available here What regulatory checks is your document workflow missing?