Skip to main content
Glama

Openfda Dataframe Query

openfda_dataframe_query
Read-onlyIdempotent

Run a read-only SQL SELECT against a DataCanvas table staged by an openFDA search tool (call one with stage=true; its response carries canvas_id + canvas_table). Enables GROUP BY, COUNT/SUM/AVG, time-series, and joins across the staged result set without re-paging the API. Call openfda_dataframe_describe first to get the exact table and column names. Results are capped at the canvas row limit — when truncated is true, page the rest with ORDER BY plus LIMIT/OFFSET. Scalar fields are stored as text (CAST for numeric math); nested objects/arrays are JSON columns — read them with DuckDB json functions, e.g. json_extract_string(openfda, '$.brand_name[0]'). Only SELECT is allowed — DDL, DML, COPY, and file-reading functions are blocked.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSQL SELECT against the staged table. Use the table name from openfda_dataframe_describe. Example: "SELECT classification, COUNT(*) AS n FROM spilled_ab12cd34 GROUP BY classification ORDER BY n DESC".
canvas_idYesCanvas ID from the canvas_id field of an openFDA search tool response (openfda_search_* or openfda_lookup_ndc), present when the search ran with stage=true.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
rowsNoRows returned by the query (capped at the canvas row limit).
errorNoPresent when the call failed. Absent on success.
canvas_idNoCanvas ID that was queried — reuse for follow-up queries.
row_countNoNumber of rows in this response. Equals the canvas row limit when truncated is true.
truncatedNoTrue when the result hit the canvas row limit and rows beyond it were dropped. Page the rest with ORDER BY plus LIMIT/OFFSET.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changed
    • changedInput schema / properties / canvas_id / description
      Previous value: -"Canvas ID from an openFDA search tool response (the canvas_id field, present when the search ran with stage=true)."New value: +"Canvas ID from the canvas_id field of an openFDA search tool response (openfda_search_* or openfda_lookup_ndc), present when the search ran with stage=true."
    • removedInput schema / properties / canvas_id / minLength
      Removed value: -1
    • changedInput schema / properties / canvas_id / pattern
      Previous value: -"\\S"New value: +"^[A-Za-z0-9_-]{10}$"
    • changedOutput schema / properties / error / properties / data / properties / reason / description
      Previous value: -"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, or uses a blocked operation. Other values are possible when a failure originates below the handler."New value: +"Machine-readable failure mode. Declared by this tool: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, uses a blocked operation, or fails on a staged value (a CAST that does not convert). Other values are possible when a failure originates below the handler."
  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": [
      +      "rows",
      +      "row_count",
      +      "truncated",
      +      "canvas_id"
      +    ]
      +  },
      +  {
      +    "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: `canvas_disabled`: DataCanvas is disabled — CANVAS_PROVIDER_TYPE is unset. `canvas_not_found`: The canvas_id does not correspond to an active canvas session. `missing_table`: The SQL references a table that is not on the canvas — dropped, expired, or mistyped. `invalid_query`: The SQL is not a valid SELECT, references an unknown column, or uses a blocked operation. Other values are possible when a failure originates below the handler.",
      +          "examples": [
      +            "canvas_disabled",
      +            "canvas_not_found",
      +            "missing_table",
      +            "invalid_query"
      +          ],
      +          "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: -[
      -  "rows",
      -  "row_count",
      -  "truncated",
      -  "canvas_id"
      -]
  3. Changed4 schema fields changed
    • changedInput schema / properties / canvas_id / description
      Previous value: -"Canvas ID from an openFDA search tool response (the canvas_id field)."New value: +"Canvas ID from an openFDA search tool response (the canvas_id field, present when the search ran with stage=true)."
    • changedOutput schema / properties / row_count / description
      Previous value: -"Number of rows in this response."New value: +"Number of rows in this response. Equals the canvas row limit when truncated is true."
    • addedOutput schema / properties / truncated
      Added value: +{
      +  "description": "True when the result hit the canvas row limit and rows beyond it were dropped. Page the rest with ORDER BY plus LIMIT/OFFSET.",
      +  "type": "boolean"
      +}
    • changedOutput schema / required
      Previous value: -[
      -  "rows",
      -  "row_count",
      -  "canvas_id"
      -]New value: +[
      +  "rows",
      +  "row_count",
      +  "truncated",
      +  "canvas_id"
      +]
  4. Changed4 schema fields changed
    • addedInput schema / properties / canvas_id / minLength
      Added value: +1
    • addedInput schema / properties / canvas_id / pattern
      Added value: +"\\S"
    • addedInput schema / properties / query / minLength
      Added value: +1
    • addedInput schema / properties / query / pattern
      Added value: +"\\S"
  5. Added

TDQS

A4.7/5.0
Behavior5/5

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

Annotations already declare readOnlyHint and idempotentHint, and the description reinforces this by explicitly stating 'read-only SQL SELECT' and 'Only SELECT is allowed — DDL, DML, COPY, and file-reading functions are blocked.' It also discloses row-limit truncation and pagination with ORDER BY/LIMIT/OFFSET, and explains data type storage (scalars as text, JSON columns with DuckDB functions). These details go well beyond annotations, providing complete behavioral expectations.

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 dense but well-organized: it front-loads the purpose, then gives prerequisite steps, truncation handling, and data type caveats. Every sentence adds unique value, and there's no fluff or repetition. It's appropriately sized for the tool's complexity.

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

Completeness5/5

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

Given the tool's complexity and that an output schema exists, the description covers all necessary usage aspects: how to obtain canvas_id, the need to consult openfda_dataframe_describe, allowed SQL constructs, row-limit behavior, and data format handling. An agent can confidently invoke this tool correctly without additional clarification.

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

Parameters4/5

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

Schema coverage is 100% with both parameters described, including an example for query and provenance for canvas_id. The description adds extra context about the query parameter (only SELECT allowed, how to handle JSON) and clarifies canvas_id's source (search tool response with stage=true). While the schema already covers basics, the description enriches the semantics with practical guidance.

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

Purpose5/5

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

The description clearly states the tool runs read-only SQL SELECT queries on a staged DataCanvas table from an openFDA search. It names the resource (staged table), the verb (query/select), and differentiates from siblings by focusing on post-staging analysis rather than searching or describing fields. The mention of GROUP BY, aggregations, and joins reinforces its distinct role.

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 gives clear usage context: it must be called after a search tool with stage=true, and openfda_dataframe_describe should be invoked first to get exact table/column names. It also explains when this tool is beneficial (aggregation, time-series, joins without re-paging). It doesn't explicitly list when to avoid it, but the prerequisite and functional scope make the intended usage clear.

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.