count_records
Aggregate records across any OpenFDA endpoint to get top values, counts, and percentages. Ideal for statistics, distributions, and top-N lists.
Instructions
Count/aggregate records by field across any OpenFDA endpoint. Returns top values with counts, percentages, and a narrative summary.
When to use: Getting statistics, distributions, or "top N" lists. For individual records, use search_fda instead.
Args: endpoint: One of the 21 OpenFDA endpoint paths (e.g., "drug/event", "device/510k"). Call list_searchable_fields to see valid endpoints. count_field: Field to aggregate on. IMPORTANT: You MUST add .exact suffix for text fields (e.g., "patient.reaction.reactionmeddrapt.exact"). Without .exact, text fields are tokenized and counts will be wrong. Numeric and date fields do NOT need .exact. search: Optional search filter to narrow records before counting. limit: Number of top values to return (default 10, max 1000).
Examples: Top adverse reactions for a drug: endpoint="drug/event", count_field="patient.reaction.reactionmeddrapt.exact", search='patient.drug.openfda.brand_name:"ASPIRIN"' Device recalls by classification: endpoint="device/enforcement", count_field="classification.exact" Food recall reasons: endpoint="food/enforcement", count_field="reason_for_recall.exact", limit=5
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| search | No | ||
| endpoint | Yes | ||
| count_field | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |