src/agent/skills/fda/SKILL.md
Query openFDA API for drugs, devices, adverse events, recalls, regulatory submissions (510k, PMA), substance identification (UNII), for FDA regulatory data analysis and safety research.
npx skillsauth add ai4protein/VenusFactory fda-databaseInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Access comprehensive FDA regulatory data through openFDA, the FDA's initiative to provide open APIs for public datasets. Query information about drugs, medical devices, foods, animal/veterinary products, and substances using Python with standardized interfaces.
Key capabilities:
This skill should be used when working with:
Scripts live in src/tools/search/deepsearch/fda/. Each module is runnable with python -m src.tools.search.deepsearch.fda.<module>.
| Script | Purpose | Main |
|--------|---------|------|
| fda_query.py | Full FDAQuery class: all categories (drug, device, food, animal, substance), rate limit, cache | Yes |
| fda_examples.py | Comprehensive examples: drug safety, device surveillance, food recalls, substance, comparative, veterinary | Yes |
| fda_drug.py | Drug-only demo: events, label, recalls | Yes |
| fda_device.py | Device-only demo: events, 510k, classification | Yes |
| fda_substance.py | Substance demo: by name, by UNII | Yes |
Import the client:
from src.tools.search.deepsearch.fda import FDAQuery
# Initialize (API key optional but recommended)
fda = FDAQuery(api_key="YOUR_API_KEY")
# Query drug adverse events
events = fda.query_drug_events("aspirin", limit=100)
# Get drug labeling
label = fda.query_drug_label("Lipitor", brand=True)
# Search device recalls
recalls = fda.query("device", "enforcement",
search="classification:Class+I",
limit=50)
While the API works without a key, registering provides higher rate limits:
Register at: https://open.fda.gov/apis/authentication/
Set as environment variable:
export FDA_API_KEY="your_key_here"
if __name__ == "__main__")# Full query module (minimal drug/label examples)
python -m src.tools.search.deepsearch.fda.fda_query
# Comprehensive examples (drug, device, food, substance, comparative, veterinary)
python -m src.tools.search.deepsearch.fda.fda_examples
# Domain-specific demos
python -m src.tools.search.deepsearch.fda.fda_drug
python -m src.tools.search.deepsearch.fda.fda_device
python -m src.tools.search.deepsearch.fda.fda_substance
Access 6 drug-related endpoints covering the full drug lifecycle from approval to post-market surveillance.
Endpoints:
Common use cases:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
# Safety signal detection
fda.count_by_field("drug", "event",
search="patient.drug.medicinalproduct:metformin",
field="patient.reaction.reactionmeddrapt")
# Get prescribing information
label = fda.query_drug_label("Keytruda", brand=True)
# Check for recalls
recalls = fda.query_drug_recalls(drug_name="metformin")
# Monitor shortages
shortages = fda.query("drug", "drugshortages",
search="status:Currently+in+Shortage")
Reference: See references/drugs.md for detailed documentation
Access 9 device-related endpoints covering medical device safety, approvals, and registrations.
Endpoints:
Common use cases:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
# Monitor device safety
events = fda.query_device_events("pacemaker", limit=100)
# Look up device classification
classification = fda.query_device_classification("DQY")
# Find 510(k) clearances
clearances = fda.query_device_510k(applicant="Medtronic")
# Search by UDI
device_info = fda.query("device", "udi",
search="identifiers.id:00884838003019")
Reference: See references/devices.md for detailed documentation
Access 2 food-related endpoints for safety monitoring and recalls.
Endpoints:
Common use cases:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
# Monitor allergen recalls
recalls = fda.query_food_recalls(reason="undeclared peanut")
# Track dietary supplement events
events = fda.query_food_events(industry="Dietary Supplements")
# Find contamination recalls
listeria = fda.query_food_recalls(reason="listeria", classification="I")
Reference: See references/foods.md for detailed documentation
Access veterinary drug adverse event data with species-specific information.
Endpoint:
Common use cases:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
# Species-specific events
dog_events = fda.query_animal_events(species="Dog", drug_name="flea collar")
# Breed predisposition analysis
breed_query = fda.query("animalandveterinary", "event",
search="reaction.veddra_term_name:*seizure*+AND+"
"animal.breed.breed_component:*Labrador*")
Reference: See references/animal_veterinary.md for detailed documentation
Access molecular-level substance data with UNII codes, chemical structures, and relationships.
Endpoints:
Common use cases:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
# UNII to CAS mapping
substance = fda.query_substance_by_unii("R16CO5Y76E")
# Search by name
results = fda.query_substance_by_name("acetaminophen")
# Get chemical structure
structure = fda.query("other", "substance",
search="names.name:ibuprofen+AND+substanceClass:chemical")
Reference: See references/other.md for detailed documentation
Create comprehensive safety profiles combining multiple data sources:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
def drug_safety_profile(fda, drug_name):
"""Generate complete safety profile."""
# 1. Total adverse events
events = fda.query_drug_events(drug_name, limit=1)
total = events.get("meta", {}).get("results", {}).get("total", 0)
# 2. Most common reactions
reactions = fda.count_by_field(
"drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*",
field="patient.reaction.reactionmeddrapt",
exact=True
)
# 3. Serious events
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug_name}*+AND+serious:1",
limit=1)
# 4. Recent recalls
recalls = fda.query_drug_recalls(drug_name=drug_name)
return {
"total_events": total,
"top_reactions": (reactions.get("results") or [])[:10],
"serious_events": serious.get("meta", {}).get("results", {}).get("total", 0),
"recalls": recalls.get("results", []),
}
Analyze trends over time using date ranges:
from datetime import datetime, timedelta
def get_monthly_trends(fda, drug_name, months=12):
"""Get monthly adverse event trends."""
trends = []
for i in range(months):
end = datetime.now() - timedelta(days=30*i)
start = end - timedelta(days=30)
date_range = f"[{start.strftime('%Y%m%d')}+TO+{end.strftime('%Y%m%d')}]"
search = f"patient.drug.medicinalproduct:*{drug_name}*+AND+receivedate:{date_range}"
result = fda.query("drug", "event", search=search, limit=1)
count = result["meta"]["results"]["total"] if "meta" in result else 0
trends.append({
"month": start.strftime("%Y-%m"),
"events": count
})
return trends
Compare multiple products side-by-side:
def compare_drugs(fda, drug_list):
"""Compare safety profiles of multiple drugs."""
comparison = {}
for drug in drug_list:
# Total events
events = fda.query_drug_events(drug, limit=1)
total = events["meta"]["results"]["total"] if "meta" in events else 0
# Serious events
serious = fda.query("drug", "event",
search=f"patient.drug.medicinalproduct:*{drug}*+AND+serious:1",
limit=1)
serious_count = serious["meta"]["results"]["total"] if "meta" in serious else 0
comparison[drug] = {
"total_events": total,
"serious_events": serious_count,
"serious_rate": (serious_count/total*100) if total > 0 else 0
}
return comparison
Link data across multiple endpoints:
def comprehensive_device_lookup(fda, device_name):
"""Look up device across all relevant databases."""
return {
"adverse_events": fda.query_device_events(device_name, limit=10),
"510k_clearances": fda.query_device_510k(device_name=device_name),
"recalls": fda.query("device", "enforcement",
search=f"product_description:*{device_name}*"),
"udi_info": fda.query("device", "udi",
search=f"brand_name:*{device_name}*")
}
All API responses follow this structure:
{
"meta": {
"disclaimer": "...",
"results": {
"skip": 0,
"limit": 100,
"total": 15234
}
},
"results": [
# Array of result objects
]
}
Always handle potential errors:
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key="YOUR_API_KEY")
result = fda.query_drug_events("aspirin", limit=10)
if "error" in result:
print(f"Error: {result['error']}")
elif "results" not in result or len(result["results"]) == 0:
print("No results found")
else:
# Process results
for event in result["results"]:
# Handle event data
pass
For large result sets, use pagination:
# Automatic pagination
all_results = fda.query_all(
"drug", "event",
search="patient.drug.medicinalproduct:aspirin",
max_results=5000
)
# Manual pagination
for skip in range(0, 1000, 100):
batch = fda.query("drug", "event",
search="...",
limit=100,
skip=skip)
# Process batch
DO:
# Specific field search
search="patient.drug.medicinalproduct:aspirin"
DON'T:
# Overly broad wildcard
search="*aspirin*"
The FDAQuery class handles rate limiting automatically, but be aware of limits:
The FDAQuery class includes built-in caching (enabled by default):
from src.tools.search.deepsearch.fda import FDAQuery
fda = FDAQuery(api_key=api_key, use_cache=True, cache_ttl=3600)
When counting/aggregating, use .exact suffix:
# Count exact phrases
fda.count_by_field("drug", "event",
search="...",
field="patient.reaction.reactionmeddrapt",
exact=True) # Adds .exact automatically
Clean and validate search terms:
def clean_drug_name(name):
"""Clean drug name for query."""
return name.strip().replace('"', '\\"')
drug_name = clean_drug_name(user_input)
For detailed information about:
references/api_basics.mdreferences/drugs.mdreferences/devices.mdreferences/foods.mdreferences/animal_veterinary.mdreferences/other.mdAll under src/tools/search/deepsearch/fda/; each file has if __name__ == "__main__" and can be run with python -m src.tools.search.deepsearch.fda.<module>.
fda_query.pyMain query module with FDAQuery class: unified interface to all openFDA endpoints, rate limiting, caching, error handling. Run: python -m src.tools.search.deepsearch.fda.fda_query
fda_examples.pyComprehensive examples: drug safety profile, device surveillance, food recall, substance lookup, comparative drug analysis, veterinary. Run: python -m src.tools.search.deepsearch.fda.fda_examples
fda_drug.py / fda_device.py / fda_substance.pyDomain-specific runnable demos (drug events/label/recalls; device events/510k/classification; substance by name/UNII).
Issue: Rate limit exceeded
Issue: No results found
Issue: Invalid query syntax
references/api_basics.mdIssue: Missing fields in results
development
Query STRING API for protein-protein interactions (59M proteins, 20B interactions). Network analysis, GO/KEGG enrichment, interaction discovery, 5000+ species, for systems biology.
development
Statistical visualization with pandas integration. Use for quick exploration of distributions, relationships, and categorical comparisons with attractive defaults. Best for box plots, violin plots, pair plots, heatmaps. Built on matplotlib. For interactive plots use plotly; for publication styling use scientific-visualization.
tools
Cheminformatics toolkit for fine-grained molecular control. SMILES/SDF parsing, descriptors (MW, LogP, TPSA), fingerprints, substructure search, 2D/3D generation, similarity, reactions. For standard workflows with simpler interface, use datamol (wrapper around RDKit). Use rdkit for advanced control, custom sanitization, specialized algorithms.
development
Query NCBI Gene via E-utilities/Datasets API. Search by symbol/ID, retrieve gene info (RefSeqs, GO, locations, phenotypes), batch lookups, for gene annotation and functional analysis.