Dibya Sarothi
Dibya Sarothi
AI ApplicationsProduction ReadyOctober 2026

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 overview
MediGuard AI preview 1
Project Overview

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.

Problem Statement

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.

Engineering Rationale

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

Establish a comprehensive, indexed database of verified generic and brand pharmaceuticals.
Implement deterministic barcode/QR code verification matching national drug registers.
Architect a gated RAG (Retrieval-Augmented Generation) pipeline where AI can only explain verified formulary facts.
Provide accessible localized search supporting both Bengali and English brand naming.
Offer offline-first emergency contact and first-aid reference information.
Architecture Blueprint

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.

01

Deterministic Validation Gateway

Incoming queries are checked against normalized pharmaceutical dictionaries before reaching the AI model, eliminating hallucinated brand names.

02

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.

03

Localized Search Indexing

Trigram indexing in PostgreSQL allows fuzzy searching across phonetic English and Bengali brand transliterations.

AI Integration & Validation Philosophy

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.

Implementation Mechanics: RAG pipeline with deterministic Pydantic schema validation. If the LLM generates a claim unsupported by the retrieved database entity, the output is discarded and the raw clinical data sheet is rendered directly.

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

Engine / Tier: PostgreSQL with Trigram similarity and Full-Text Search

Normalized database schema modeling the relationship between active generic molecules, commercial brands, dosages, and contraindications.

Core Models & Entities
GenericMedicine & DrugClassBrandMedicine & ManufacturerDrugInteraction & DosageFormCounterfeitReport & VerificationAudit

Authentication & Security Controls

Auth Model: Role-based JWT authentication with rate-limiting on medical search endpoints
  • 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

Challenge: Handling inconsistent spelling and phonetic brand queries from users.
Engineering Solution: Configured PostgreSQL pg_trgm extension with custom similarity thresholds, indexing both phonetic pronunciation tokens and official generic names.
Challenge: Preventing dangerous prompt injections asking for illegal prescription dosage calculations.
Engineering Solution: Implemented an input classifier and hard system prompts paired with deterministic Pydantic output validation that automatically rejects unsafe prompts.

Trade-Off Decisions

Decision: Relational Database as Primary Truth Source
Architectural Rationale: Vector embeddings alone are prone to semantic drift; exact generic matching requires relational integrity and exact foreign keys.
Decision: Zero-Trust Schema Enforcing on AI Outputs
Architectural Rationale: Direct string generation from LLMs is unsafe for healthcare; structured JSON schemas ensure every output attribute is validated.

Testing & Verification Methodology

Frameworks & Approach: Pytest, Django Test Suite, Vitest
  • 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.

Results & Engineering Takeaways

Proved that combining deterministic relational verification with constrained AI yields exponentially safer products than standalone AI chatbots.
Mastered PostgreSQL full-text search and phonetic string matching techniques.
Learned to architect software around societal trust and human safety.