{"record":{"id":"526c0d891a90c28c","repo":"OpenBB-finance/OpenBB","slug":"dataflow-dataflow-id-not-found-available-data","errorCode":null,"errorMessage":"Dataflow '{dataflow_id}' not found. Available dataflows: {list(self._builder.metadata.dataflows.keys())}","messagePattern":"Dataflow '(.+?)' not found\\. Available dataflows: (.+?)","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/progressive_helper.py","lineNumber":23,"sourceCode":"from openbb_imf.utils.query_builder import ImfQueryBuilder\n\n\nclass ImfParamsBuilder:\n    \"\"\"A helper class to build IMF queries progressively by making sequential dimension selections,\n    for each dimension of a dataflow, filtering the available options at each step based on previous selections.\n    \"\"\"\n\n    def __init__(self, dataflow_id: str):\n        \"\"\"Initialize the ImfParamsBuilder object.\n\n        Parameters\n        ----------\n        dataflow_id : str\n            The ID of the dataflow to build a query for.\n        \"\"\"\n        self._builder = ImfQueryBuilder()\n        if dataflow_id not in self._builder.metadata.dataflows:\n            raise KeyError(\n                f\"Dataflow '{dataflow_id}' not found.\"\n                f\" Available dataflows: {list(self._builder.metadata.dataflows.keys())}\"\n            )\n\n        self.dataflow_id = dataflow_id\n        self.dsd = self._get_dsd()\n        self._dimensions = self._get_dimensions_in_order()\n        self.current_dimension = self._dimensions[0] if self._dimensions else None\n        self._selections: dict = {dim: None for dim in self._dimensions}\n        self._last_constraints_response: dict = {}\n\n    def _get_dsd(self):\n        \"\"\"Get the Data Structure Definition (DSD) for the current dataflow.\"\"\"\n        df_obj = self._builder.metadata.dataflows[self.dataflow_id]\n        dsd_id = df_obj.get(\"structureRef\", {}).get(\"id\")\n        return self._builder.metadata.datastructures.get(dsd_id, {})\n\n    def _get_dimensions_in_order(self) -> list[str]:","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/progressive_helper.py#L5-L41","documentation":"ImfParamsBuilder raises KeyError in __init__ when the requested dataflow_id is not present in the IMF SDMX metadata's dataflows dictionary (fetched/loaded by ImfQueryBuilder). The message lists all known dataflow IDs to help correction.","triggerScenarios":"Constructing ImfParamsBuilder('PGF') style calls with a wrong, renamed, or not-yet-loaded dataflow ID; also case or spelling mistakes (e.g. 'BOP' vs 'BOP_X').","commonSituations":"Using a dataflow ID from an outdated IMF page or older openbb version, stale cached metadata after IMF adds dataflows, or scripts with hardcoded IDs that IMF has retired.","solutions":["Instantiate ImfQueryBuilder().metadata.dataflows and pick the exact ID from the message's available list.","Refresh/clear cached IMF metadata so newly published dataflows appear.","Upgrade the openbb-imf provider if the dataflow was added in a newer release.","Guard interactive flows by validating the ID against metadata before constructing the builder."],"exampleFix":"# before\nbuilder = ImfParamsBuilder(dataflow_id='BOP_AGGS')  # KeyError\n\n# after\nfrom openbb_imf.utils.query_builder import ImfQueryBuilder\nvalid = ImfQueryBuilder().metadata.dataflows\nassert 'BOP' in valid, f'pick from {list(valid)}'\nbuilder = ImfParamsBuilder(dataflow_id='BOP')","handlingStrategy":"validation","validationCode":"from openbb_imf.utils.query_builder import ImfQueryBuilder\n\ndef is_valid_dataflow(dataflow_id: str) -> bool:\n    return dataflow_id in ImfQueryBuilder().metadata.dataflows\n\nassert is_valid_dataflow('BOP')","typeGuard":"def is_valid_dataflow(dataflow_id: str, metadata) -> TypeGuard[str]:\n    return isinstance(dataflow_id, str) and dataflow_id in metadata.dataflows","tryCatchPattern":"try:\n    builder = ImfParamsBuilder(dataflow_id)\nexcept KeyError as e:\n    if 'not found' in str(e):\n        suggest = difflib.get_close_matches(dataflow_id, list(builder_md.dataflows), n=1)\n        raise ValueError(f'Unknown dataflow; did you mean {suggest}?') from e\n    raise","preventionTips":["Resolve dataflow IDs from metadata at runtime instead of hardcoding strings.","Refresh cached IMF metadata when a new dataflow is expected.","Pin the openbb-imf provider version in production and test upgrades against your dataflow list."],"tags":["validation","imf","sdmx","dataflow","metadata"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}