A Python Retrieval-Augmented Generation (RAG) pipeline with a Streamlit Web UI for real-time drug safety alerts: side effects, drug-drug interactions, and contraindications — grounded in FDA and NLM data.
Powered by Groq API (Lightning fast Llama 3 models) — 100% Free and open-source models.
- Web UI: Interactive clinical query interface built with Streamlit.
- Fast Extraction: Uses
llama-3.1-8b-instantto instantly parse clinical entities. - Live Database Retrieval: Queries NLM RxNorm, OpenFDA, and RxNav APIs in real-time.
- Clinical Synthesis: Uses
llama-3.3-70b-versatileto synthesize retrieved facts into a comprehensive alert.
Doctor Query (NL via Web UI or CLI)
│
▼
[Stage 2] Entity Extraction ← Groq (Llama 3 8B), temp=0, JSON output
│ proposed_drug, current_meds, conditions
▼
[Stage 3] Drug Normalization ← RxNorm API → RxCUI codes
│
▼
[Stage 4] Parallel Retrieval ← asyncio.gather()
├── OpenFDA (adverse_reactions + contraindications)
└── RxNav DDI API (interaction pairs with severity)
│
▼
[Stage 5] Context Assembly ← build_synthesis_prompt()
│
▼
[Stage 6] LLM Synthesis ← Groq (Llama 3 70B), temp=0, strict system prompt
│
▼
[Stage 7] ClinicalAlert output ← structured Pydantic model (rendered in Streamlit)
| Source | Purpose | API |
|---|---|---|
| RxNorm (NLM) | Drug name normalization | rxnav.nlm.nih.gov/REST |
| OpenFDA | Side effects + contraindications | api.fda.gov/drug/label.json |
| RxNav DDI | Drug-drug interactions | rxnav.nlm.nih.gov/REST/interaction |
All sources are free and require no API key for standard usage.
- Clone and Install:
git clone https://github.com/yourusername/PharmaRAG.git
cd PharmaRAG
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install groq streamlit- API Keys:
Get a free Groq API key at console.groq.com/keys.
Create a
.envfile in the root directory:
GROQ_API_KEY=your_groq_api_key_here
The easiest way to use the system is via the included Streamlit UI:
source venv/bin/activate
streamlit run app.pyThis will open http://localhost:8501 in your browser.
PharmaRAG/
├── app.py # Streamlit Web UI
├── pipeline.py # Main orchestrator (entry point for CLI)
├── requirements.txt # Project dependencies
├── core/
│ └── models.py # Pydantic data models for all stages
├── api/
│ └── medical_db.py # RxNorm, OpenFDA, RxNav API clients
├── prompts/
│ └── templates.py # All prompt templates + context assembly
└── utils/
└── guardrails.py # Post-generation validation layer
- Temperature = 0 (always): Both LLM calls are hardcoded to
temperature=0. Clinical outputs must be deterministic and reproducible. - Retrieval-only system prompt: The synthesis system prompt explicitly forbids drawing on training knowledge. Every claim must cite a retrieved source.
- No dosing data: This pipeline intentionally has no dosing information.
This system is designed as a Clinical Decision Support (CDS) tool. Depending on your jurisdiction and use case, it may be subject to FDA 21 CFR Part 820, CE marking, or equivalent medical device regulations. Consult a regulatory specialist before clinical deployment.