Imf Query Dataset
imf_query_datasetQuery an IMF SDMX dataflow by dimension key over a time range. Returns observations with time_period, value, and status, plus the unit, scale, and decimals of each series — a key resolving to several series carries one entry per series in series_metadata, since unit and scale differ between them. An index series also carries the reference_period it is based on (e.g. 2010A, 2010=100) exactly as published, on the series and, where the dataflow publishes one per observation, on each observation. Requires imf_get_database first to obtain the correct key_format and valid dimension codes. Country codes are ISO 3-letter (USA, GBR, DEU — not US, GB, DE). Key format: dot-separated codes in DSD keyPosition order (e.g. USA.NGDP_RPCH.A for WEO). Every position must carry a code: use + to combine codes (e.g. USA+GBR.NGDP_RPCH.A) and * to match every code at a position (e.g. *.NGDP_RPCH.A for all countries); * stands alone and cannot join a + list. Codes are matched case-insensitively and checked against each dimension's codelist before the query — an unknown code is rejected with the nearest valid codes. Codelists from imf_get_database enumerate the code universe, not actual coverage — valid codes can still return no_data if the combination has no series. When a + key returns data for some requested series and none for others, missing_series names each empty one with the reason a query for it alone gives (no_data or no_data_in_range). When the extra request that recovers the unit, scale, or decimals a + key suppresses fails, unresolved_attributes names them and how to get them. start_period and end_period must be valid period strings (YYYY, YYYY-SN, YYYY-QN, YYYY-MM, or a calendar-valid YYYY-MM-DD) with start_period no later than end_period; malformed or reversed ranges are rejected. A bound covers the whole period it names, so end_period 2023 includes 2023-M12 and 2023-Q4. last_n_observations keeps each series' last N observations — 1 is each series' latest value, the cheap way to ask many countries for their latest figure. Values are in base units everywhere, staged canvas rows included: scale is the power of ten the IMF publishes a series in (value / 10^scale is the published figure), never a factor still to apply. An inline response is held to 100,000 serialized characters. With DataCanvas enabled (CANVAS_PROVIDER_TYPE=duckdb), a larger result (multi-country, long time range) spills to it and returns a preview, the attributes of its first 20 series and at most 100 observations: call imf_dataframe_describe first to inspect staged tables and columns, then imf_dataframe_query for SQL analysis. Without DataCanvas, or with it at its canvas cap when an auto-mode call omits canvas_id, a larger result returns its earliest observations with truncated=true, and retrieval_guidance names the last period returned and how to narrow the query.
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": {
"dataflow_id": "<dataflow_id>",
"key": "<key>"
},
"name": "imf_query_dataset"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Dot-separated dimension codes in DSD keyPosition order. Call imf_get_database to get key_format and valid codes first. Use + to combine codes at one position (e.g. USA+GBR.NGDP_RPCH.A). Use * to match every code at a position — *.NGDP_RPCH.A returns the indicator for all countries, and CAN.*.A every indicator for Canada. Every position needs a code or a *; an empty segment (USA..A) is rejected. A * stands alone at its position — combined with other codes (USA+*) it is rejected. Codes are trimmed and matched case-insensitively (usa resolves to USA), empty and repeated + members are dropped (USA++GBR+USA is queried as USA+GBR, and notice says so), and the response echoes the canonical key. A code missing from its dimension's codelist is rejected before the query, naming the nearest valid codes. The portal limits the request URL, so a + list of a few hundred codes is rejected as too long — use * there, or split the codes across calls. Country codes are ISO 3-letter: USA not US, GBR not GB, DEU not DE. | |
| version | No | Dataflow version, e.g. 9.0.0. Auto-detected from dataflow list when omitted. | |
| agency_id | No | Agency ID, e.g. IMF.RES or IMF.STA, matched case-insensitively. Auto-detected from dataflow list when omitted. | |
| canvas_id | No | Existing canvas ID to accumulate results into across multiple queries. This selects the destination only; it does not force staging. Use output_mode="canvas" to stage an under-budget result. A canvas_id that has expired fails as canvas_not_found once the result is staged: omit it to stage onto a fresh canvas. At the canvas cap only a canvas_id you hold can stage; omitted there, auto mode returns the result inline and output_mode="canvas" fails as canvas_capacity_exhausted. | |
| end_period | No | End of time range (inclusive). Same formats as start_period, and must not be earlier than it. The bound covers the whole period it names, so end_period 2023 admits 2023-M12 and 2023-Q4. Observations after this period are excluded from the result. | |
| dataflow_id | Yes | Dataflow identifier from imf_list_databases, e.g. WEO, BOP, CPI. Matched case-insensitively; the response echoes the catalog spelling. | |
| output_mode | No | Result placement. auto returns an under-budget result inline and spills only when needed. canvas explicitly stages the full result, using canvas_id when supplied or allocating a fresh canvas. | auto |
| start_period | No | Start of time range (inclusive). Accepts any of YYYY (annual), YYYY-SN (semi-annual, e.g. 2023-S1), YYYY-QN (quarterly, e.g. 2023-Q1), YYYY-MM (monthly), or a calendar-valid YYYY-MM-DD (daily), whatever the dataflow's frequency. The bound covers the whole period it names, so start_period 2023 admits 2023-M01 and 2023-Q1. Observations before this period are excluded from the result. | |
| last_n_observations | No | Keep only each series' last N observations, an integer from 1 to 1,000,000; 1 returns each series' latest value. Latest is per series: series end at different periods, and a WEO series ends in its projection years (e.g. 2031), so set end_period to stop at a past year. With start_period or end_period, the last N inside that range. A series with fewer than N observations is returned whole. Omit to return every observation. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Dimension key used in the query, trimmed and with each code in its codelist spelling, e.g. USA.NGDP_RPCH.A. | |
| error | No | Present when the call failed. Absent on success. | |
| notice | No | Populated when empty or duplicate + members were dropped from key (naming each position and the key queried), or when a period bound was set but some observations carry a time_period label the range filter does not recognize; both texts appear when both apply. Composes with retrieval_guidance, staged or not, when both apply. | |
| source | No | Attribution string required by IMF data terms: "Source: International Monetary Fund, <dataflow name>, <link>". | |
| staged | No | True when the complete observation set is stored on DataCanvas. canvas_id and table_name are present whenever true. | |
| canvas_id | No | DataCanvas session ID — present when staged=true. Pass first to imf_dataframe_describe, then to imf_dataframe_query. | |
| truncated | No | True only when observations is an incomplete preview of observation_count. A staged result is truncated=true when it holds more than 100 observations or more than 20 series, and staged=false and truncated=true when the full result exceeds the response budget and was not staged: DataCanvas is not enabled, or an auto-mode call without canvas_id found it at its canvas cap. | |
| end_period | No | Latest period covered; absent when the full available range was used. | |
| table_name | No | DuckDB table name on the canvas — present when staged=true; reference in SQL via FROM <table_name>. | |
| dataflow_id | No | Dataflow identifier that was queried, in its catalog spelling, e.g. WEO. | |
| observations | No | Inline observations, ordered by the dates each period spans, earliest first: by first date, and on the same first date the shorter period first (2023-M01, 2023-Q1, 2023-S1, 2023). When truncated=true this is a prefix of that order — on a staged result at most the first 100 rows, ending before the first row of a series series_metadata does not list; without DataCanvas the longest prefix that fits the response budget. observation_count remains the full count. | |
| series_count | No | How many distinct series the result holds, present only on a staged result whose series_metadata lists the first 20 of more. SELECT DISTINCT series_key, unit, scale, decimals, series_reference_period FROM <table_name> ORDER BY series_key returns the attributes of every one. | |
| start_period | No | Earliest period covered; absent when the full available range was used. | |
| missing_series | No | Requested series of a + key that returned no observation while others did, in key order, at most 20. A requested series is each combination of the codes listed at every position. Counted over the full result, so a series left out of a truncated preview is not listed. Absent when every requested series returned. | |
| series_metadata | No | Per-series attributes, one entry per distinct series_key in the result, in order of first appearance in observations. Present only when the query resolved to more than one series; a single-series query carries its values in series_attributes instead. A staged result lists its first 20 series only: series_count is then present with the total, and the staged table's rows carry every series' attributes. Unit and scale differ across series in one query — WEO NGDPD is USD published in billions (scale 9) while NGDP_RPCH is PT at scale 0 — so interpret each series against its own entry. | |
| observation_count | No | Total observations in the result, after any last_n_observations selection. | |
| series_attributes | No | Attributes of the first series in the result — the same series as series_metadata[0]. A key with + or * resolves to several series whose scale and unit differ, and this field describes only the first of them: read series_metadata for the rest, and never apply these values to another series_key. | |
| retrieval_guidance | No | Present on every staged result, where it names the imf_dataframe_describe-before-imf_dataframe_query retrieval workflow and, when series_metadata is cut, the SELECT DISTINCT query that returns every series' attributes, and on a result truncated without staging, where it says why (DataCanvas is not enabled, or at its canvas cap) and names the last time_period returned and how to reach the rest. | |
| last_n_observations | No | The last_n_observations input, echoed when set: observations holds each series' last N in the range. Absent when every observation was returned. | |
| missing_series_count | No | How many requested series returned no observation — the full count when missing_series stops at 20. Present with missing_series. | |
| unresolved_attributes | No | Present only when a + key on the dimension an attribute is grouped by made the portal leave unit, scale, or decimals out, and the extra request that recovers them failed. A listed attribute that is null is then unknown, not unpublished. Absent when that request found no value — the dataflow publishes none — or was not needed. |