Query EIA Dataframes
eia_dataframe_queryRun a single-statement SELECT against canvas dataframes registered by eia_query_route calls that passed stage: true — a query that staged nothing leaves no table to select from. Standard DuckDB SQL — joins, aggregates, window functions, CTEs all supported. Reference dataframes by the df_ handles returned by eia_query_route or listed by eia_dataframe_describe. Read-only: writes, DDL, DROP, COPY, PRAGMA, ATTACH, file reads (read_* functions or a quoted file path), engine-setting functions (current_setting), and SQL built from a string (query_table) are rejected. System catalogs are denied: information_schema, pg_catalog, and the DuckDB internal metadata views (duckdb_tables, duckdb_columns, and the other duckdb_ views; sqlite_master and the other sqlite_ views; pragma_database_list; pg_class, pg_tables, and the other pg_ views) are refused as whole words anywhere in the statement outside string literals and comments, column aliases and CTE names included, as is any duckdb_() call. A register_as name spelled like one of them is refused, since no statement could select from a table so named. EIA data values are VARCHAR — use CAST(col AS DOUBLE) for arithmetic and aggregation. Optional register_as chains results as a new dataframe with a fresh expiry. Every dataframe named in the statement has its expiry extended by the query. Inline rows stop at preview; a result cut short says how to reach the rest, including paging a register_as table with LIMIT/OFFSET and no ORDER BY, which keeps the order the preview showed.
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": {
"sql": "<sql>"
},
"name": "eia_dataframe_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes | Single-statement SELECT against df_<id> tables. EIA data columns are VARCHAR — use CAST(col AS DOUBLE) for arithmetic. Example: SELECT period, CAST(value AS DOUBLE) AS val FROM df_XXXXX ORDER BY period | |
| preview | No | Rows to include in the immediate response. Default 25; a larger value returns at most row_limit and says so. 0 returns none, useful when chaining via register_as. | |
| row_limit | No | Hard cap on rows materialized. Default 1,000; a larger value returns at most 10,000 and says so. Rows past the cap are dropped without being counted — the response then carries truncated: true and a totalRows equal to the cap rather than a true total. Pass register_as to materialize the whole result instead and get an exact count. | |
| register_as | No | When set, persist the result as a new dataframe with a fresh expiry. Use to chain analyses without re-running upstream queries. The name must be unused — reusing a staged name is rejected, and the fix is a different name, not dropping the existing dataframe. eia_dataframe_describe lists the names already taken. A name spelled like a denied system catalog (information_schema, pg_tables, duckdb_tables, sqlite_master, and the rest the tool description lists), in any case, is refused as system_catalog_access; a longer name that only contains one, such as pg_tables_2024, is accepted. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | Inline rows, bounded by preview and row_limit. | |
| error | No | Present when the call failed. Absent on success. | |
| notice | No | Discloses requested/effective row_limit and preview when clamped, including on short or empty results. When row_limit or preview ended the inline rows, names each bound and how to reach the rows it withheld (raise a bound below its cap, or page a register_as table with LIMIT/OFFSET and no ORDER BY). | |
| columns | No | Column names in projection order. | |
| totalRows | No | Rows the query materialized. Exact when truncated is false — including on the register_as path, which stages and counts the whole result past row_limit. Equal to row_limit when truncated is true: a floor on the real match count, not a total. | |
| truncated | No | True when row_limit cut the result: more rows matched than the cap and the remainder was dropped without being counted. False when every matching row was materialized, including on the register_as path, which counts the new dataframe exactly. | |
| expires_at | No | ISO 8601 expiry for the newly registered dataframe, when applicable. Extended each time a later query references it. | |
| executedSql | No | Echo of the SQL statement that was executed — confirms the exact query that ran. | |
| returnedRows | No | Rows included in this response. Below totalRows when preview ended the inline rows; the notice names how to reach the rest. | |
| registered_as | No | Set when register_as was supplied and the new dataframe was materialized. |