OpenBB-finance/OpenBB · error · ValueError
Data structure not found for dataflow '{dataflow}'.
Error message
Data structure not found for dataflow '{dataflow}'. What it means
build_url raises ValueError when the dataflow exists in metadata but its structureRef.id is missing or that DSD is not in metadata.datastructures. Without the Data Structure Definition the builder cannot map kwargs to dimension positions in the SDMX key, so it aborts.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/query_builder.py:35
def build_url(
self,
dataflow: str,
start_date: str | None = None,
end_date: str | None = None,
limit: int | None = None,
**kwargs,
) -> str:
"""Build the IMF SDMX REST API URL for data retrieval."""
if dataflow not in self.metadata.dataflows:
raise ValueError(f"Dataflow '{dataflow}' not found.")
df = self.metadata.dataflows[dataflow]
agency_id = df.get("agencyID")
dsd_id = df.get("structureRef", {}).get("id")
if not dsd_id or dsd_id not in self.metadata.datastructures:
raise ValueError(f"Data structure not found for dataflow '{dataflow}'.")
dsd = self.metadata.datastructures[dsd_id]
all_dimensions = dsd.get("dimensions", [])
dimension_ids = {d["id"] for d in all_dimensions if d.get("id")}
# Create a map for case-insensitive matching of dimension IDs
dimension_id_map = {d_id.lower(): d_id for d_id in dimension_ids}
final_kwargs: dict = {}
for key, value in kwargs.items():
# Try to match the key (case-insensitive) to a known dimension ID
matched_dim_id = dimension_id_map.get(key.lower())
if matched_dim_id:
final_kwargs[matched_dim_id] = value
else:
# If not a dimension, keep the original key
final_kwargs[key] = value
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Delete the cached IMF metadata so dataflows and datastructures are fetched together, then retry.
- Upgrade openbb-imf; structure parsing for new SDMX shapes is fixed over time.
- Verify the DSD exists by querying the IMF SDMX API for the dataflow's structure.
- If persisting, fall back to a different dataflow covering the same series.
Example fix
# shell: force metadata refresh (location depends on install) rm -rf ~/.cache/openbb/imf_metadata # then retry the same call
Defensive patterns
Strategy: fallback
Validate before calling
def dataflow_has_dsd(qb, dataflow: str) -> bool:
df = qb.metadata.dataflows.get(dataflow, {})
dsd_id = df.get('structureRef', {}).get('id')
return bool(dsd_id) and dsd_id in qb.metadata.datastructures Try / catch
try:
url = qb.build_url(dataflow, **kwargs)
except ValueError as e:
if 'Data structure not found' in str(e):
refresh_imf_metadata_cache()
url = qb.build_url(dataflow, **kwargs)
else:
raise Prevention
- Treat dataflows and datastructures as one atomic metadata unit when caching.
- Refetch metadata on provider upgrade instead of reusing old caches.
- Pre-check structureRef.id presence before build_url in long-running jobs.
When it happens
Trigger: Metadata loaded the dataflow list but not (all) datastructures: partial fetch, truncated cache, or IMF publishing a dataflow whose DSD is referenced but not exposed.
Common situations: Interrupted first-run metadata download writing a partial cache, cache format changes between provider versions, or brand-new dataflows whose DSD has not propagated.
Related errors
- Agency ID not found for dataflow '{dataflow}'.
- Invalid {name}(s): {', '.join(invalid)}
- Invalid indicator code(s) for dataflow '{dataflow}': {'; '.j
- Dataflow '{dataflow_id}' not found.
- Agency ID not found for dataflow '{dataflow_id}'.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/6744a90543be413a.
Report an issue: GitHub.