Medical Chatbot with Verified Answers
Build an AI chatbot that answers drug safety questions with FDA-verified sources. Ground your LLM in verified knowledge to eliminate hallucinations completely.
The Problem
Traditional AI Systems Cannot Prove Their Sources
Probabilistic retrieval: Vector embeddings return "similar" documents based on cosine similarity, not exact matches. No proof the source actually contains what the AI claims.
Unverifiable citations: Traditional RAG systems cite documents, but can't prove which exact sentences support each claim. Users must trust the AI.
LLM hallucinations: Even with retrieved context, LLMs blend information from their training data with retrieved sources. Impossible to distinguish fact from fabrication.
No audit trail: Citations degrade over time as vector indices change. A citation that worked 6 months ago may return different results today.
The Solution
Use Lemma as Knowledge Layer for Your LLM
Instead of asking the LLM directly, query Lemma first to get verified FDA sources, then send those sources to your LLM as context. The LLM can only generate answers based on verified sources — no hallucinations possible.
Every answer grounded in verified FDA sources
Cryptographic fingerprints prove FDA origin
Natural language responses with verifiable citations
Safe for clinical use and regulatory compliance
How It Works
Complete Integration Flow
User Question
Query Lemma Search API
{
"question": "aspirin side effects adverse reactions",
"top_k": 5
}Lemma Returns Verified FDA Data
{
"results": [
{
"text": "Allergy alert: Aspirin may cause a severe allergic reaction which may include: hives, facial swelling, shock, asthma (wheezing).",
"fingerprint": "01010111100101011101000110011100...",
"drug": {"name": "aspirin"},
"section": "Warnings"
}
]
}Send to Your LLM
User Receives Verified Answer
AI Assistant:
"Based on FDA drug labels, aspirin can cause severe allergic reactions including hives, facial swelling, shock, and asthma symptoms like wheezing."
[Citation: fp:01010111100101011101000110011100...]
✓ Click fingerprint to verify this claim came from official FDA source
Implementation Code
import openai
import requests
import os
LEMMA_API_KEY = os.getenv("LEMMA_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
def answer_with_verified_sources(user_question: str) -> dict:
"""
Answer medical questions using verified FDA sources.
Zero hallucinations - LLM can only use provided sources.
"""
# Step 1: Get verified FDA sources from Lemma
lemma_response = requests.post(
"https://api.lemma.la/v1/search",
headers={
"x-api-key": LEMMA_API_KEY,
"Content-Type": "application/json"
},
json={
"question": user_question,
"top_k": 5
}
)
response_data = lemma_response.json()
sources = response_data.get('data', {}).get('results', [])
# Step 2: Build context from verified sources only
context = "Verified FDA Sources:\n\n"
for i, source in enumerate(sources, 1):
context += f"{i}. {source['text']}\n"
context += f" [Citation: fp:{source['fingerprint'][:30]}...]\n\n"
# Step 3: Send to LLM with strict instructions
system_prompt = """You are a medical AI assistant. You must answer using ONLY
the verified FDA sources provided. Do NOT use your training data or general knowledge.
Include [Citation: fp:...] after each claim."""
user_prompt = f"""User Question: "{user_question}"
{context}
Answer the question using ONLY the sources above. If the sources don't contain
enough information, say so."""
llm_response = openai.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
temperature=0.2 # Low temperature for factual accuracy
)
answer = llm_response.choices[0].message.content
# Step 4: Return answer with verification data
return {
"answer": answer,
"sources": sources,
"verified": True
}
# Example usage
result = answer_with_verified_sources("What are the side effects of aspirin?")
print(result['answer'])
print(f"\nBacked by {len(result['sources'])} verified FDA sources")Why This Works
Ready to Build?
Get your API key and start building your medical chatbot with verified answers in minutes.