{"record":{"id":"594d24289aff14ed","repo":"OpenBB-finance/OpenBB","slug":"invalid-value-s-for-dimension-dim-id-invali","errorCode":null,"errorMessage":"Invalid value(s) for dimension '{dim_id}': {invalid_values}. Given prior selections {prior_selections}, available values are: {all_values}","messagePattern":"Invalid value\\(s\\) for dimension '(.+?)': (.+?)\\. Given prior selections (.+?), available values are: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/imf/openbb_imf/utils/query_builder.py","lineNumber":240,"sourceCode":"\n                    if invalid_values:\n                        # Build helpful error message\n                        prior_selections = {\n                            d: kwargs.get(d)\n                            for d in dimensions_in_order\n                            if d in kwargs\n                            and dimensions_in_order.index(d)\n                            < dimensions_in_order.index(dim_id)\n                        }\n\n                        # Show all available values without truncation\n                        all_values = sorted(available_values)\n                        error_msg = (\n                            f\"Invalid value(s) for dimension '{dim_id}': {invalid_values}. \"\n                            f\"Given prior selections {prior_selections}, \"\n                            f\"available values are: {all_values}\"\n                        )\n                        raise ValueError(error_msg)\n\n                    # Set the valid value to progress the builder\n                    builder.set_dimension((dim_id, user_values[0]))\n\n            # Check time period constraints from the last dimension validation\n            # The _last_constraints_response already contains contentConstraints with TIME_PERIOD info\n            start_date = kwargs.get(\"start_date\")\n            end_date = kwargs.get(\"end_date\")\n\n            if start_date or end_date:\n                constraints = builder._last_constraints_response\n                if constraints:\n                    full_response = constraints.get(\"full_response\", {})\n                    data = full_response.get(\"data\", {})\n\n                    # Time period annotations can be in contentConstraints or dataConstraints\n                    # Check both places\n                    time_start = None","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/imf/openbb_imf/utils/query_builder.py#L222-L258","documentation":"During constraint validation inside build_url, the progressive builder discovered that one or more user-supplied values for a dimension are not among the values the IMF constraints API allows given the previously selected dimensions. The error lists the invalid values, the prior selections, and every available value so the correction is mechanical.","triggerScenarios":"E.g. passing COUNTRY='USA' when the dataflow expects ISO3 codes but the prior FREQUENCY/indicator selection restricts the country codelist; or combining indicator + counterpart_area values that IMF's constraint engine marks incompatible.","commonSituations":"Mixing code conventions (USA vs US vs 842), reusing parameter sets across dataflows, or assuming all codelist values are valid in every combination — SDMX cube constraints prune options as earlier dimensions are fixed.","solutions":["Read the message: replace each invalid value with one from the 'available values' list given the same prior selections.","Adjust the earlier selections (order matters) if you need a value that is pruned by them.","Verify code conventions on the IMF data catalog (ISO3 for country, A/Q/M for frequency).","Build queries interactively with ImfParamsBuilder.get_dimension_options to only ever choose allowed values."],"exampleFix":"# before\nurl = qb.build_url('BOP', FREQUENCY='A', REF_AREA='US', INDICATOR='...')  # US invalid\n\n# after\nurl = qb.build_url('BOP', FREQUENCY='A', REF_AREA='USA', INDICATOR='...')  # ISO3 code","handlingStrategy":"validation","validationCode":"def validate_dimension_values(builder, dim_id: str, values: list[str]) -> list[str]:\n    available = {o['value'] for o in builder.get_dimension_options(dim_id)}\n    invalid = [v for v in values if v not in available]\n    if invalid:\n        raise ValueError(f'{dim_id}: invalid {invalid}; allowed (given selections): {sorted(available)}')\n    return values","typeGuard":"def values_are_valid(builder, dim_id: str, values: list[str]) -> bool:\n    available = {o['value'] for o in builder.get_dimension_options(dim_id)}\n    return all(v in available for v in values)","tryCatchPattern":"try:\n    url = qb.build_url(dataflow, **kwargs)\nexcept ValueError as e:\n    m = re.search(r'available values are: \\[(.*)\\]', str(e))\n    if m:\n        kwargs[dim] = pick_from(ast.literal_eval('[' + m.group(1) + ']'))\n        url = qb.build_url(dataflow, **kwargs)\n    else:\n        raise","preventionTips":["Use ImfParamsBuilder.get_dimension_options to enumerate allowed values per selection state.","Set dimensions in order — earlier selections prune later codelists.","Standardize on IMF code conventions (ISO3 country codes, A/Q/M frequency)."],"tags":["validation","imf","sdmx","dimension-values","constraints"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}