In healthcare, trust is everything. While conversational AI is powerful for engaging patients, it also introduces a serious risk: hallucination. If a chatbot makes up information or provides unsafe medical advice, it can harm patients and erode trust.
To address this, we can extend a voice-enabled patient education chatbot that we discussed in previous article with Retrieval-Augmented Generation (RAG). Instead of letting the model freely generate answers, we ground it in trusted health education websites such as:
- Mayo Clinic
- Health Direct Australia
- Cleveland Clinic
What is RAG (Retrieval-Augmented Generation)?
RAG is a pattern where:
-
The patient asks a question.
-
The system retrieves relevant passages from a knowledge base (vector database).
-
The retrieved content is fed into the LLM prompt.
-
The chatbot generates an answer grounded in those trusted sources.
This prevents hallucination and allows the system to cite sources in responses.
Data Flow Explanation
-
User (ReactApp)
-
Patient asks a health question via text/voice.
-
ReactApp sends the request to the backend.
-
-
LangGraph (Workflow Orchestration Layer)
-
Orchestrates the flow of nodes (e.g., retrieval, validation, LLM).
-
Passes the query into the LangChain pipeline.
-
-
LangChain (Core RAG Logic)
-
Handles embeddings, retrieval, and prompt construction.
-
Calls vector database (Pinecone which is already populated with indexed datasets from trusted sources) for context.
-
Prepares final
prompt = {query + context}
for LLM.
-
-
LangSmith (Observability/Tracing)
-
Logs requests, responses, latency, errors.
-
Helps debug and monitor RAG performance.
-
-
OpenAI (LLM API)
-
Receives grounded prompt.
-
Generates response.
-
Returns text back through LangChain → LangGraph → ReactApp.
For the purpose of this demo, I only extracted the following pages related to Diabetes from the trusted sources i.e. Mayo Clinic, HealthDirect, Cleveland Clinic. No Web Scrapping is done for this. We will only ask the questions related to diabetes to our chatbot.
Sample App Screenshot:
Sample LLM Question & Response:
Question:
What are the common health problems associated with diabetes,
and what can I do to prevent them?
Response:
Common health problems associated with diabetes include
heart disease, stroke, kidney disease, and nerve issues.
To prevent these complications, focus on managing
your blood glucose levels, maintaining a healthy diet,
exercising regularly, and attending regular health check-ups.
Additionally, avoid smoking and ensure proper dental
and foot care to reduce risks.
Source(s):
URL: https://www.mayoclinic.org/diseases-conditions/diabetes/diagnosis-treatment/drc-20371451
Lines: 364 to 366
URL: https://www.healthdirect.gov.au/type-1-diabetes
Lines: 123 to 144
Validating Responses
To make sure the assistant does not hallucinate:
-
🔗 Always cite sources in responses.
-
🛑 Add a fallback: “I don’t know. Please consult your doctor.” if no relevant documents are found.
-
✅ Add a semantic similarity check (Not implemented in this demo) to ensure the generated answer aligns with retrieved documents.
Benefits of RAG in Healthcare
-
Accuracy: Answers come from trusted medical sources.
-
Transparency: Patients see citations.
-
Compliance: Reduces legal and ethical risks.
-
Scalability: Easily update embeddings when new health guidelines are published.