MediGuard AI
Evidence-Grounded Pharmaceutical Safety & Clinical Informatics Architecture
Defensive RAG verification across 43,075 normalized DGDA pharmaceutical records and openFDA cross-references — 145/145 automated tests passing.


MediGuard AI is an independent biomedical informatics and full-stack engineering platform (~13k LOC, 145/145 automated tests passing) built to mitigate counterfeit and mislabeled pharmaceutical risks in Bangladesh and globally. Engineered around defensive Retrieval-Augmented Generation, it pairs 43,075 normalized DGDA National Catalogue records with US openFDA cross-references and demotes LLMs into bounded interpreters with zero-trust citation minting.
Counterfeit and improperly dispensed pharmaceuticals cause catastrophic harm in developing regions like Bangladesh. Consumers often lack instant, verified access to generic drug equivalents, dosage precautions, manufacturer authentication, and contraindications. Furthermore, raw LLMs frequently hallucinate medical guidance.
Healthcare is a zero-margin-of-error domain. Generative AI cannot be trusted to invent dosages or medical claims. An evidence-first validation layer must gate and verify every AI generation against structured government-approved pharmaceutical formularies.
Engineering Objectives
System Architecture
MediGuard AI uses a dual-engine architecture. The ground-truth tier comprises a structured PostgreSQL database containing validated drug generics, manufacturers, and interaction matrices. The intelligence tier utilizes an LLM strictly constrained via Pydantic output schemas, instructed to cite verified drug IDs and reject unvalidated user queries.
Deterministic Validation Gateway
Incoming queries are checked against normalized pharmaceutical dictionaries before reaching the AI model, eliminating hallucinated brand names.
Structured Schema Verification
AI responses are parsed into strict Pydantic schemas; if validation fails or assertions are missing, the system falls back to raw clinical formulary data.
Localized Search Indexing
Trigram indexing in PostgreSQL allows fuzzy searching across phonetic English and Bengali brand transliterations.
Evidence First, AI Second.
The AI is treated as an explanatory engine, not a diagnostic authority. All clinical attributes (contraindications, dosage rules, generic equivalents) originate from deterministic database tables. The AI translates these verified attributes into accessible, plain-language patient summaries.
Core & Backend Implementation
- Django REST backend managing structured drug inventories, generic equivalencies, and manufacturer verified batches.
- Pydantic-based schema validation layer intercepting LLM payloads for zero-hallucination guarantees.
- High-speed Redis cache for high-frequency generic lookups and common drug interaction queries.
- Custom authentication for medical professionals to submit batch counterfeit warnings.
- Automated database seeding pipeline parsing open pharmaceutical registries into relational schemas.
Client & Interface Layer
- Next.js application featuring an intuitive search-first mobile-responsive layout.
- Client-side QR and barcode scanner utilizing the HTML5 camera stream API.
- Structured medicine cards highlighting generic composition, manufacturer, indications, and warnings.
- Accessible visual indicators for prescription-only schedules versus over-the-counter medications.
- Multi-lingual interface designed for rapid accessibility under low-bandwidth networks.
Data & Schema Design
Normalized database schema modeling the relationship between active generic molecules, commercial brands, dosages, and contraindications.
Authentication & Security Controls
- Strict rate-limiting preventing automated scraping of medical registries.
- Input sanitization protecting against SQL injection and prompt injection.
- Zero storage of personal user health histories without explicit client-side encryption.
Engineering Challenges & Technical Decisions
Key Challenges Solved
Trade-Off Decisions
Testing & Verification Methodology
- Accuracy benchmark across 500+ generic pharmaceutical names.
- Zero-tolerance hallucination tests where fictitious brand names must return 'Not Found'.
- End-to-end QR code payload validation test suite.