Prescription Validator Agent
A hybrid neuro-symbolic AI agent that validates pharmacy insurance claims by extracting structured data from free-text prescriptions with deterministic regex, then enforcing composable safety rules that block, flag, or correct violations before they reach the payer.
The Clinical Problem
"Insurance claims with off-label prescriptions cost the healthcare system billions. LLM-only systems might catch some, but a probability distribution is not a safety guarantee — and a hallucination means a paid claim that should have been rejected."
How It Works
1. Prescription Intake
- →Accepts free-text prescription input (English or Arabic)
- →Three demo scenarios: Ozempic approval, safety rejection, copy block
- →Instant feedback: results appear in milliseconds
2. Regex Extraction
- →Deterministic NLP: drug name, frequency, duration, dosage, diagnosis
- →Date parsing with Arabic month name support
- →Insurance provider detection (7 providers with Arabic aliases)
- →Footer text extraction for copy-type classification
3. Guardrail Engine (5 VLM-Guard Rules)
- →OzempicSafetyRule: blocks off-label GLP-1 prescribing for weight loss
- →CopyTypeRule: blocks client copies that shouldn't be processed
- →ExpiryRule: blocks prescriptions past provider-specific validity windows
- →ChronicCoverageRule: blocks chronic drugs under acute-only policies
- →DosageMathRule: enforces quantity limits against policy box sizes
4. LangGraph State Machine
- →Three nodes: extract → guardrail → clinical calculation
- →Conditional routing: first rejection short-circuits the pipeline
- →Each node independently testable with structured Pydantic state
5. Audit Trail & Decision
- →Every rule firing recorded: rule name, action type, message, severity
- →Approved claims show detailed calculation breakdown
- →Rejected claims show first violation reason + full audit trail
Safety & Trust
Every output passes through deterministic, auditable guardrails before reaching the user. No black boxes. No unseen failures.
Blocks Ozempic/Wegovy prescriptions written for weight loss without a Type 2 Diabetes indication. Catches the most common and costly off-label prescribing pattern.
Blocks 'client copy' prescriptions from being processed — these are patient-held copies, not dispensable prescriptions. Supports both English and Arabic footer detection.
Enforces provider-specific prescription validity windows (3–14 days depending on insurer). A 14-day prescription submitted on day 15 is rejected before any clinical processing.
Blocks chronic-condition medications when the patient's insurance policy only covers acute care — preventing coverage mismatches at the point of sale.
Calculates total units from frequency × duration and compares against policy box-size limits. Rejects quantities exceeding the allowed number of boxes.
About This Project
Prescription Validator Agent was built to demonstrate a principle: LLMs are excellent at understanding free text, but safety decisions must be deterministic. The system takes a free-text prescription (e.g., 'Ozempic 0.5 mg SC weekly for weight loss'), passes it through a regex-based extractor that pulls structured fields (drug, dose, diagnosis, date, provider, footer), then routes the structured extract through a VLM-Guard rule engine. Five rules — OzempicSafetyRule, CopyTypeRule, ExpiryRule, ChronicCoverageRule, DosageMathRule — enforce insurance policy constraints with four action types: block, correct, promote, flag. If any rule fires a block action, the claim is rejected immediately with a full audit trail showing exactly why. The LangGraph state machine enables conditional routing: first rejection short-circuits the pipeline, returning results in milliseconds. An optional Gemini 2.5 Flash fallback handles complex extraction cases, but the core system runs fully offline.
Key Features
- Hybrid neuro-symbolic architecture: LLM for understanding, Python for safety decisions
- Composable VLM-Guard rule engine with 5 rules and 4 action types
- LangGraph state machine with conditional short-circuit routing
- Bilingual English/Arabic support for real-world pharmacy workflow
- Fully offline: zero API keys, zero GPU, zero model downloads required
- Deterministic regex extraction: instant, testable, zero dependencies
- Full audit trail: every rule firing recorded with before/after snapshots
- 84 tests across 3 layers with 89% code coverage
- GitHub Actions CI (multi-Python-version) + Docker deployment
- Optional Gemini 2.5 Flash fallback for complex extraction cases
Impact
- →84 deterministic tests (89% coverage) — no API key needed to run the full suite
- →No LLM in the safety decision path: approve, block and correct decisions are deterministic Python rules
- →Bilingual Arabic/English support mirrors real Egyptian pharmacy workflows
- →Time-frozen golden dataset ensures expiry checks are reproducible across any machine
- →Docker + CI pipeline demonstrates production-ready engineering practices
Technology Stack
Related articles
Building a clinical AI system of your own?
The Clinical AI Reliability Audit applies the same kind of evaluation and safety engineering to your system: architecture and risk discovery, evaluation and root cause analysis, and targeted engineering improvements. For a working healthcare app built with AI coding tools, the Clinical Prototype Readiness Review is the smaller starting point.
Related Projects
This project is part of a connected ecosystem. Each piece reinforces the same mission: safe, trustworthy clinical AI.
VLM-Guard
A composable rule-based verification layer that catches physically impossible, biologically inconsis...
HeartSafe RAG
A retrieve-or-refuse Retrieval-Augmented Generation system for heart failure clinical decision suppo...
NTD-Assist
An offline multimodal AI prototype for microscopy-based NTD screening, with 12 rule-based biological...
MedVision Assist
A Clinical Decision Support System for radiologists that drafts 90%-complete preliminary imaging rep...