OpenFDA AI Wrapper avatar
OpenFDA AI Wrapper
Under maintenance

Pricing

Pay per usage

Go to Apify Store
OpenFDA AI Wrapper

OpenFDA AI Wrapper

Under maintenance

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

David Connor

Maintained by Community

Actor stats

0

Bookmarked

1

Total users

0

Monthly active users

a day ago

Last modified

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 repository
git clone https://github.com/yourusername/fda-api-ai.git
cd fda-api-ai
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .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 Configuration
LLM_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 query
python query_fda.py "Find Tylenol products"
# Get adverse events
python query_fda.py "Show me adverse events for aspirin"
# Verbose output with query details
python query_fda.py "Medical devices recalled in 2023" -v
# JSON output
python query_fda.py "Drug shortages for antibiotics" --json
# Limit results
python query_fda.py "Recent drug recalls" --limit 5
# Use advanced LLM mode
python query_fda.py "Complex multi-part query" --mode advanced

Programmatic Usage

from src.services import QueryService
# Initialize service
service = QueryService(llm_mode='fast')
# Generate and execute query
result = 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_python package
  • Configuration: Environment-based settings management

Flow

  1. User provides natural language input
  2. LLM analyzes request and selects appropriate FDA database
  3. LLM constructs search query with proper openFDA syntax
  4. Query is validated and executed against FDA API
  5. Results are returned in structured format

Supported FDA Databases

Drugs

  • drug_ndc: Product information (NDC codes, brand/generic names)
  • drug_event: Adverse event reports
  • drug_label: Product labeling and package inserts
  • drug_fda: Drugs@FDA approval data
  • drug_shortage: Drug shortage information
  • drug_enforcement: Recall and enforcement actions

Devices

  • device_event: Medical device adverse events
  • device_510k: 510(k) clearances
  • device_class: Device classifications
  • device_pma: Premarket approval applications
  • device_registration: Establishment registrations
  • device_udi: Unique device identifiers
  • device_covid: COVID-19 testing evaluations

Food & Other

  • food_event: Food adverse events
  • food_enforcement: Food recalls
  • animal_event: Veterinary adverse events
  • cosmetic_event: Cosmetic adverse events
  • tobacco_problem: Tobacco problem reports
  • transparency_crls: Clinical Research Listing System
  • other_substance: Substance data reports
  • other_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 tests
pytest
# Run with verbose output
pytest -v -s
# Run specific test
pytest tests/test_integration.py::test_basic_query

Adding New Features

To extend functionality:

  1. Add new tools in src/services/tools.py using the @tool_registry.register() decorator
  2. Add new LLM providers by extending BaseLLMClient in src/llm_client/llm_clients.py
  3. Add new query types by updating QUERY_CLASSES mapping in src/services/tools.py

Dependencies

  • anthropic: Claude API client
  • pydantic: Data validation and settings management
  • python-dotenv: Environment variable management
  • requests: HTTP client
  • openfda_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 Dockerfile for Apify actor
  • Create actor.json with 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.