Skip to main content
Glama

Openfda Count Values

openfda_count_values
Read-only

Aggregate and tally unique values for any field across any openFDA endpoint. Returns ranked term-count pairs sorted by count descending. 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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYesField 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.
limitNoNumber of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell.
searchNoFilter query to scope the count (e.g. patient.drug.medicinalproduct:"metformin"). Omit to count across every record in the endpoint. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request.
endpointYesFull openFDA endpoint path (e.g. "drug/event", "device/classification")

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
capNoThe limit applied to the term list.
metaNoResponse metadata
errorNoPresent when the call failed. Absent on success.
shownNoNumber of terms returned in this response.
noticeNoWhy the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms; at the 1000-term maximum, that openFDA cannot show whether more distinct values exist. Absent when a complete list is returned.
resultsNoTerm-count pairs sorted by count descending
termCountNoNumber of distinct terms returned
truncatedNoTrue 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).
truncationCeilingNoCount of the lowest-ranked term returned — omitted terms fall at or below it.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changed
    • changedInput schema / properties / count / description
      Previous value: -"Field to count. Append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"). Identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) must be counted bare — .exact on those is rejected as not countable."New value: +"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."
    • changedInput schema / properties / limit / description
      Previous value: -"Number of top terms to return (default 100, max 1000)"New value: +"Number of top terms to return (default 100, max 1000 — openFDA's own count maximum). truncated reports whether more distinct terms exist beyond it, except at the maximum itself, where openFDA offers no way to tell."
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, or .exact on a field already indexed as a keyword. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, .exact on a field already indexed as a keyword, or a field with no countable form. Other values are possible when a failure originates below the handler."
    • changedOutput schema / properties / notice / description
      Previous value: -"Guidance when no terms matched — how to verify the field name or adjust the count expression. Absent when terms are returned."New value: +"Why the tally is empty — the search matched no records, or the matched records carry no value for the field — and how to widen it; when truncated, how to reach the omitted terms; at the 1000-term maximum, that openFDA cannot show whether more distinct values exist. Absent when a complete list is returned."
    • changedOutput schema / properties / truncated / description
      Previous value: -"True when the term list was capped at the limit — more distinct terms may exist."New value: +"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)."
  2. Changed6 schema fields changed
    • changedInput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedInput schema / additionalProperties
      Added value: +false
    • changedOutput schema / $schema
      Previous value: -"http://json-schema.org/draft-07/schema#"New value: +"https://json-schema.org/draft/2020-12/schema"
    • addedOutput schema / anyOf
      Added value: +[
      +  {
      +    "not": {
      +      "required": [
      +        "error"
      +      ]
      +    },
      +    "required": [
      +      "meta",
      +      "results",
      +      "termCount"
      +    ]
      +  },
      +  {
      +    "required": [
      +      "error"
      +    ]
      +  }
      +]
    • addedOutput schema / properties / error
      Added value: +{
      +  "additionalProperties": {},
      +  "description": "Present when the call failed. Absent on success.",
      +  "properties": {
      +    "code": {
      +      "description": "JSON-RPC error code for this failure.",
      +      "maximum": 9007199254740991,
      +      "minimum": -9007199254740991,
      +      "type": "integer"
      +    },
      +    "data": {
      +      "additionalProperties": {},
      +      "properties": {
      +        "reason": {
      +          "description": "Machine-readable failure mode. Declared by this tool: `rate_limited`: The openFDA daily or per-minute request limit is exceeded. `upstream_error`: The openFDA API returned a 5xx server error. `malformed_search`: The search query leaves a double quote, parenthesis, or range bracket unclosed, or ends on a backslash. `query_error`: The search or count query was rejected by openFDA (malformed field name, invalid syntax). `not_aggregatable`: openFDA cannot aggregate the count expression as written — an analyzed text field, or .exact on a field already indexed as a keyword. Other values are possible when a failure originates below the handler.",
      +          "examples": [
      +            "rate_limited",
      +            "upstream_error",
      +            "malformed_search",
      +            "query_error",
      +            "not_aggregatable"
      +          ],
      +          "type": "string"
      +        },
      +        "recovery": {
      +          "additionalProperties": {},
      +          "description": "Actionable next step for the caller.",
      +          "properties": {
      +            "hint": {
      +              "type": "string"
      +            }
      +          },
      +          "required": [
      +            "hint"
      +          ],
      +          "type": "object"
      +        },
      +        "retryable": {
      +          "description": "Whether retrying may succeed.",
      +          "type": "boolean"
      +        }
      +      },
      +      "type": "object"
      +    },
      +    "message": {
      +      "description": "Human-readable description of what went wrong.",
      +      "type": "string"
      +    }
      +  },
      +  "required": [
      +    "code",
      +    "message"
      +  ],
      +  "type": "object"
      +}
    • removedOutput schema / required
      Removed value: -[
      -  "meta",
      -  "results",
      -  "termCount"
      -]
  3. Changed1 schema field changed
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint."New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint. Double quotes, parentheses, and range brackets must balance, and the query must not end on a backslash — each is rejected before the request."
  4. Changed6 schema fields changed
    • changedInput schema / properties / count / description
      Previous value: -"Field to count. Append .exact for whole-phrase counting (e.g. \"patient.reaction.reactionmeddrapt.exact\", \"openfda.brand_name.exact\")"New value: +"Field to count. Append .exact for whole-phrase counting of free-text fields (e.g. \"patient.reaction.reactionmeddrapt.exact\"). Identifier fields openFDA already indexes as keywords (product_ndc, application_number, pma_number) must be counted bare — .exact on those is rejected as not countable."
    • addedInput schema / properties / count / minLength
      Added value: +1
    • addedInput schema / properties / count / pattern
      Added value: +"\\S"
    • changedInput schema / properties / search / description
      Previous value: -"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\")"New value: +"Filter query to scope the count (e.g. patient.drug.medicinalproduct:\"metformin\"). Omit to count across every record in the endpoint."
    • addedInput schema / properties / search / minLength
      Added value: +1
    • addedInput schema / properties / search / pattern
      Added value: +"\\S"
  5. Changed4 schema fields changed
    • addedOutput schema / properties / cap
      Added value: +{
      +  "description": "The limit applied to the term list.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / shown
      Added value: +{
      +  "description": "Number of terms returned in this response.",
      +  "type": "number"
      +}
    • addedOutput schema / properties / truncated
      Added value: +{
      +  "description": "True when the term list was capped at the limit — more distinct terms may exist.",
      +  "type": "boolean"
      +}
    • addedOutput schema / properties / truncationCeiling
      Added value: +{
      +  "description": "Count of the lowest-ranked term returned — omitted terms fall at or below it.",
      +  "type": "number"
      +}
  6. Added

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations provide readOnlyHint=true, so the description does not need to repeat that the tool is read-only. It adds that results are sorted by count descending, which is a behavioral trait beyond the annotation. However, it does not disclose other important behaviors like pagination or truncation, which are mentioned in the schema parameter descriptions but not in the main description. Since annotations cover the safety profile and the description adds a minimal behavioral detail, a 3 is appropriate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences with zero waste. The first sentence delivers the core purpose and output format, and the second provides useful guidance on pairing with search tools. It is appropriately sized and front-loaded with the most important information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has 4 parameters (2 required) with thorough schema descriptions, a readOnly annotation, and an output schema. The description covers the essential purpose and usage context. It does not explicitly describe the return structure, but the presence of an output schema makes that unnecessary. The description, combined with annotations and schema, is sufficiently complete for an agent to call the tool correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters in detail, including patterns, defaults, and examples. The description itself does not add any parameter-specific meaning beyond what the schema provides. Baseline for high coverage is 3, and there is no extra value from the description, so a 3 is accurate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific verb (aggregate and tally), a specific resource (unique values for any field across any endpoint), and the output format (ranked term-count pairs sorted descending). It distinguishes itself from search tools by focusing on counts, though it does not explicitly name a sibling to contrast with. Purpose is clear but sibling differentiation is implicit rather than explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description mentions pairing with search tools when sample records help interpret aggregates, giving context on when to use it alongside others. However, it does not explicitly state when to use this tool instead of alternatives, such as 'use this for counts, not for full records.' Usage context is clear but exclusions are missing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.