OpenFDA AI Wrapper
Pricing
Pay per usage
OpenFDA AI Wrapper
LLM-powered wrapper for the OpenFDA API. Access all publicly available FDA data using a natural language interface. Submit queries using structured or natural language. Receive results of FDA API search in original json format.
Pricing
Pay per usage
Rating
0.0
(0)
Developer

David Connor
Actor stats
0
Bookmarked
1
Total users
0
Monthly active users
a day ago
Last modified
Categories
Share
FDA API AI
An AI-powered natural language interface for the openFDA API. Ask questions in plain English and get structured FDA data back instantly.
Overview
This tool uses Claude (Anthropic) to convert natural language queries into properly formatted openFDA API requests. It supports all major FDA databases including drugs, medical devices, food, and more.
Key Features
- Natural Language Queries: Ask questions like "Find Tylenol products" or "Show me adverse events for aspirin in 2023"
- Comprehensive Coverage: Access 20+ FDA databases (drug products, adverse events, recalls, device registrations, etc.)
- Smart Query Generation: LLM automatically selects the right database and constructs optimal search parameters
- CLI and Programmatic Access: Use as a command-line tool or integrate into your own applications
- Multi-mode LLM Support: Choose between fast (Haiku) or advanced (Sonnet) models
Quick Start
Installation
# Clone the repositorygit clone https://github.com/yourusername/fda-api-ai.gitcd fda-api-ai# Install dependenciespip install -r requirements.txt# Set up environment variablescp .env.example .env# Edit .env and add your API keys
Configuration
Create a .env file with your API keys:
ANTHROPIC_API_KEY='your-anthropic-key-here'FDA_API_KEY='your-fda-key-here' # Optional but recommended# LLM ConfigurationLLM_MODES='fast,advanced'DEFAULT_LLM_MODE='fast'# Fast mode (Claude Haiku)FAST_LLM_PROVIDER='anthropic'FAST_LLM_MODEL='claude-3-5-haiku-20241022'# Advanced mode (Claude Sonnet)ADVANCED_LLM_PROVIDER='anthropic'ADVANCED_LLM_MODEL='claude-sonnet-4-5-20250929'
Usage
Command Line
# Basic querypython query_fda.py "Find Tylenol products"# Get adverse eventspython query_fda.py "Show me adverse events for aspirin"# Verbose output with query detailspython query_fda.py "Medical devices recalled in 2023" -v# JSON outputpython query_fda.py "Drug shortages for antibiotics" --json# Limit resultspython query_fda.py "Recent drug recalls" --limit 5# Use advanced LLM modepython query_fda.py "Complex multi-part query" --mode advanced
Programmatic Usage
from src.services import QueryService# Initialize serviceservice = QueryService(llm_mode='fast')# Generate and execute queryresult = service.search("Find Tylenol products")if result.success:print(f"Found {result.total_results} results")for record in result.data['results']:print(record)else:print(f"Errors: {result.errors}")
Architecture
Components
- QueryService: Orchestrates LLM interaction and query generation
- LLM Client: Provider-agnostic interface (currently supports Anthropic)
- Tool Registry: FDA-specific tools for the LLM (query type selection, field lookup, etc.)
- FDA Client Helper: Wrapper around the
openfda_pythonpackage - Configuration: Environment-based settings management
Flow
- User provides natural language input
- LLM analyzes request and selects appropriate FDA database
- LLM constructs search query with proper openFDA syntax
- Query is validated and executed against FDA API
- Results are returned in structured format
Supported FDA Databases
Drugs
drug_ndc: Product information (NDC codes, brand/generic names)drug_event: Adverse event reportsdrug_label: Product labeling and package insertsdrug_fda: Drugs@FDA approval datadrug_shortage: Drug shortage informationdrug_enforcement: Recall and enforcement actions
Devices
device_event: Medical device adverse eventsdevice_510k: 510(k) clearancesdevice_class: Device classificationsdevice_pma: Premarket approval applicationsdevice_registration: Establishment registrationsdevice_udi: Unique device identifiersdevice_covid: COVID-19 testing evaluations
Food & Other
food_event: Food adverse eventsfood_enforcement: Food recallsanimal_event: Veterinary adverse eventscosmetic_event: Cosmetic adverse eventstobacco_problem: Tobacco problem reportstransparency_crls: Clinical Research Listing Systemother_substance: Substance data reportsother_historical: Historical documents
Development
Project Structure
fda-api-ai/├── src/│ ├── config/ # Environment and settings management│ ├── llm_client/ # LLM client abstraction and tool registry│ └── services/ # Core business logic (QueryService, FDA tools)├── tests/ # Integration and unit tests├── scripts/ # Development and testing scripts├── query_fda.py # CLI entry point├── requirements.txt # Python dependencies└── pyproject.toml # Package configuration
Running Tests
# Run all testspytest# Run with verbose outputpytest -v -s# Run specific testpytest tests/test_integration.py::test_basic_query
Adding New Features
To extend functionality:
- Add new tools in
src/services/tools.pyusing the@tool_registry.register()decorator - Add new LLM providers by extending
BaseLLMClientinsrc/llm_client/llm_clients.py - Add new query types by updating
QUERY_CLASSESmapping insrc/services/tools.py
Dependencies
anthropic: Claude API clientpydantic: Data validation and settings managementpython-dotenv: Environment variable managementrequests: HTTP clientopenfda_python: OpenFDA API wrapper (external package)pytest: Testing framework
To-Do List
Completed
- Response object with different handling for count results
- Add API rate limitation handling
- Simple test script to test FDA API search
- Package up the API Python wrapper (openfda_python)
Pending
- Add proper error handling for API rate limits
- Expand test coverage (unit tests for each component)
- Add logging configuration for production
- Add input validation and sanitization
- Add CI/CD pipeline configuration
- Add 'interactive' environment variable. Off for apify.
Deployment (Apify)
- Add Apify actor configuration files
- Create
Dockerfilefor Apify actor - Create
actor.jsonwith actor metadata - Add input schema for Apify actor
- Add output schema for results
- Test actor locally with Apify CLI
- Add README for Apify store listing
License
[Your chosen license]
Contributing
Contributions welcome! Please feel free to submit a Pull Request.
Support
For issues or questions, please open an issue on GitHub.