{"record":{"id":"33495b2b1e683a89","repo":"OpenBB-finance/OpenBB","slug":"dimension-dimension-0-not-valid-for-this-data","errorCode":null,"errorMessage":"Dimension '{dimension[0]}' not valid for this dataflow. Valid dimensions: {list(self._selections.keys())}","messagePattern":"Dimension '(.+?)' not valid for this dataflow\\. Valid dimensions: (.+?)","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/progressive_helper.py","lineNumber":168,"sourceCode":"                codelist_id, agency_id, self.dataflow_id\n            )\n        return {}\n\n    def set_dimension(self, dimension: tuple[str, str]) -> dict:\n        \"\"\"Set a value for a dimension and clear downstream selections.\n\n        Parameters\n        ----------\n        dimension : tuple\n            A tuple of (dimension_id, value) to set.\n\n        Returns\n        -------\n        dict\n            The updated selections after setting the dimension.\n        \"\"\"\n        if dimension[0] not in self._dimensions:\n            raise KeyError(\n                f\"Dimension '{dimension[0]}' not valid for this dataflow.\"\n                f\" Valid dimensions: {list(self._selections.keys())}\"\n            )\n        self._selections[dimension[0]] = dimension[1]\n        # When a selection is made, we clear selections for downstream dimensions\n        # as they might now be invalid.\n        found_dim = False\n        for dim in self._dimensions:\n            if found_dim:\n                self._selections[dim] = None\n            if dim == dimension[0]:\n                found_dim = True\n\n        self.current_dimension = self.get_next_dimension_to_select()\n\n        return self._selections.copy()\n\n    def get_dimensions(self) -> dict[str, str | None]:","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/progressive_helper.py#L150-L186","documentation":"set_dimension raises KeyError when the tuple's dimension ID is not in this dataflow's _dimensions list. Selections are keyed strictly by known dimensions, and downstream selections are cleared on each set, so an unknown key is rejected up front.","triggerScenarios":"Calling builder.set_dimension(('FREQ', 'A')) when the dataflow uses 'FREQUENCY'; mixing dimension IDs from another dataflow; typos in interactive tooling that feed arbitrary keys into set_dimension.","commonSituations":"Porting parameter dictionaries between dataflows, hardcoded scripts written against an older DSD, or building generic UIs that pass user input straight through.","solutions":["Validate the dimension ID against builder._dimensions before calling set_dimension.","Use the IDs returned by get_dimension_options / the dataflow's DSD (e.g. FREQUENCY not FREQ).","In generic front-ends, present only valid dimension IDs and reject others client-side."],"exampleFix":"# before\nbuilder.set_dimension(('FREQ', 'A'))  # KeyError\n\n# after\nif 'FREQ' in builder._dimensions:\n    builder.set_dimension(('FREQ', 'A'))\nelse:\n    builder.set_dimension(('FREQUENCY', 'A'))","handlingStrategy":"validation","validationCode":"def safe_set_dimension(builder, dim: str, value):\n    if dim not in builder._dimensions:\n        raise ValueError(f'Unknown dimension {dim!r}; valid: {builder._dimensions}')\n    return builder.set_dimension((dim, value))","typeGuard":"def is_valid_dimension(builder, dim: str) -> bool:\n    return dim in builder._dimensions","tryCatchPattern":"try:\n    builder.set_dimension((dim, value))\nexcept KeyError as e:\n    if 'not valid for this dataflow' in str(e):\n        closest = difflib.get_close_matches(dim, builder._dimensions, n=1)\n        if closest:\n            builder.set_dimension((closest[0], value))\n        else:\n            raise\n    else:\n        raise","preventionTips":["Validate dimension keys against builder._dimensions before set_dimension.","In UIs, populate the dimension dropdown from _dimensions so users cannot submit invalid keys.","Note set_dimension clears downstream selections — re-select them after changing an upstream dim."],"tags":["validation","imf","sdmx","dimension","api-misuse"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}