Openfda Count Values
openfda_count_valuesAggregate and tally unique values for any field across any openFDA endpoint. Returns ranked term-count pairs sorted by count descending; a date field tallies one term per distinct YYYYMMDD date, ranked the same way. Pair with openfda_search_adverse_events, openfda_search_drug_approvals, openfda_search_device_clearances, openfda_search_recalls, openfda_get_drug_label, or openfda_lookup_ndc when sample records help interpret the aggregates.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"endpoint": "<endpoint>",
"count": "<count>"
},
"name": "openfda_count_values"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | Yes | Field to count. openfda_describe_fields gives the verified expression per field as countAs (null = not countable in any form). Otherwise: append .exact for whole-phrase counting of free-text fields (e.g. "patient.reaction.reactionmeddrapt.exact"); count identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) bare — .exact on those is rejected as not countable. A date field (receivedate, report_date, decision_date) is counted bare and yields one term per distinct YYYYMMDD date. | |
| limit | No | Number of top terms to return. truncated reports whether more distinct terms exist beyond it, except at 1000 — openFDA's own count maximum — where openFDA offers no way to tell. A date field is the exception: openFDA sends every date, so the tool ranks them all and truncated is exact at any limit; scope search to at most limit dates to list each one. Default 100; a larger value returns at most 1000 and says so. | |
| search | No | Filter query to scope the count (e.g. patient.drug.medicinalproduct:"metformin"). Omit to count across every record in the endpoint. A "+" between clauses reads as a space; inside a quoted phrase it is a literal plus. | |
| endpoint | Yes | Full openFDA endpoint path (e.g. "drug/event", "device/classification") |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cap | No | The limit applied to the term list. | |
| meta | No | Response metadata | |
| error | No | Present when the call failed. Absent on success. | |
| shown | No | Number of terms returned in this response. | |
| notice | No | Guidance for this tally: why it is empty and how to widen it, how to reach terms past limit, the 1000-term maximum, count rows left out, limit clamp, SQL for AND-ed clauses on one array entry. Absent when nothing needs saying. | |
| results | No | Term-count pairs sorted by count descending | |
| termCount | No | Number of distinct terms returned | |
| truncated | No | True when at least one more distinct term exists beyond the limit. Absent when the list is complete, and at the 1000-term maximum, where openFDA cannot show whether more exist (notice says so). Exact at any limit on a date field, where every date arrives. | |
| truncationCeiling | No | Count of the lowest-ranked term returned — omitted terms fall at or below it. |