OpenBB-finance/OpenBB · error · ValueError
Agency ID not found for dataflow '{dataflow_id}'.
Error message
Agency ID not found for dataflow '{dataflow_id}'. What it means
Raised in the constraints fetcher after the dataflow ID was found in the catalog but its entry has no 'agencyID' field, which is required to build the SDMX availability URL (.../availability/dataflow/{agency_id}/{dataflow_id}/...). This indicates malformed or incomplete catalog metadata rather than bad user input — the dataflow record exists but is missing a mandatory attribute.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/metadata.py:712
if dataflow_id not in self.dataflows:
raise ValueError(f"Dataflow '{dataflow_id}' not found.")
kwargs_sorted = sorted(kwargs.items())
kwargs_tuple = tuple(kwargs_sorted)
cache_key = (
f"{dataflow_id}:{key}:{component_id}:{mode}:{references}:{kwargs_tuple}"
)
with self._constraints_lock:
if cached_constraints := self._constraints_cache.get(cache_key):
return cached_constraints
df = self.dataflows[dataflow_id]
agency_id = df.get("agencyID")
if not agency_id:
raise ValueError(f"Agency ID not found for dataflow '{dataflow_id}'.")
# Note: URL length is now primarily managed by table_builder.py which limits
# constraint keys to depth 0-1 codes when there are many indicators.
# This fallback is kept as a safety net for edge cases.
processed_key = key
base_url = (
f"https://api.imf.org/external/sdmx/3.0/availability/dataflow/"
f"{agency_id}/{dataflow_id}/%2B/{processed_key}/{component_id or 'all'}"
)
query_params = {
"mode": mode,
"references": references,
}
c_params = {f"c[{k}]": v for k, v in kwargs.items() if v}
query_params.update(c_params)
query_params = {k: v for k, v in query_params.items() if v is not None}View on GitHub (pinned to 3e071fcc2c)
Solutions
- Rebuild the metadata object so the catalog reloads fully from the IMF registry.
- Update the provider package (pip install -U openbb-imf) in case the attribute name changed upstream.
- If using custom/mocked catalogs, ensure every dataflow entry includes agencyID (e.g. 'IMF').
Example fix
# before (malformed catalog entry)
meta.dataflows['IMTS'] = {'id': 'IMTS', 'name': 'Trade'} # no agencyID
meta.fetch_dataflow_constraints('IMTS')
# after
meta.dataflows['IMTS'] = {'id': 'IMTS', 'name': 'Trade', 'agencyID': 'IMF', 'structureRef': {'id': 'IMTS_DSD'}}
meta.fetch_dataflow_constraints('IMTS') Defensive patterns
Strategy: validation
Validate before calling
entry = meta.dataflows.get(df_id)
if not entry or not entry.get('agencyID'):
raise ValueError(f'Dataflow {df_id!r} metadata incomplete; rebuild the catalog.')
constraints = meta.fetch_dataflow_constraints(df_id, **kwargs) Type guard
def is_complete_dataflow_entry(entry: dict | None) -> bool:
return bool(entry) and isinstance(entry.get('agencyID'), str) and bool(entry['agencyID']) Try / catch
try:
c = meta.fetch_dataflow_constraints(df_id, **kwargs)
except ValueError as e:
if 'Agency ID not found' in str(e):
meta = rebuild_metadata() # re-run the catalog load
c = meta.fetch_dataflow_constraints(df_id, **kwargs)
else:
raise Prevention
- Validate catalog entries have agencyID before use, especially in tests with mocked metadata.
- Rebuild metadata objects after failed loads instead of reusing them.
- Keep openbb-imf current with the IMF SDMX registry schema.
When it happens
Trigger: A catalog entry loaded from a truncated/failed metadata fetch where agencyID was never populated; custom or mock dataflows injected without agencyID; a schema change in the IMF SDMX registry that renamed the attribute.
Common situations: Intermittent metadata initialization leaving partial records; pinning the provider to an old version against a changed upstream registry; test fixtures with hand-built dataflow dicts.
Related errors
- Invalid {name}(s): {', '.join(invalid)}
- Invalid indicator code(s) for dataflow '{dataflow}': {'; '.j
- Dataflow '{dataflow_id}' not found.
- Unexpected response format when fetching constraints {datafl
- An error occurred while fetching constraints {dataflow_id}:
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/86182f6f02dcdca8.
Report an issue: GitHub.