OpenBB-finance/OpenBB · error · ValueError

Invalid value(s) for dimension '{dim_id}': {invalid_values}.

Error message

Invalid value(s) for dimension '{dim_id}': {invalid_values}. Given prior selections {prior_selections}, available values are: {available_values}

What it means

Same 'Invalid value(s) for dimension' contract as error 641, but raised in a later phase: after the hierarchy is applied, when a dimension expected to carry indicator values (from missing_indicator_dims) has values that don't validate against builder.get_options_for_dimension(). It is deliberately re-raised (not suppressed by the progressive-filtering fallback) so validation errors always surface.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/utils/table_builder.py:695

            if missing_indicator_dims and not any(
                d in fetch_kwargs for d in indicator_dims_set
            ):
                # Use the same error format as query_builder validation
                for dim_id in missing_indicator_dims:
                    invalid_values = dimension_codes.get(dim_id, [])
                    # Get available values for this dimension
                    available_options = builder.get_options_for_dimension(dim_id)
                    available_values = sorted(  # type: ignore
                        {opt["value"] for opt in available_options}
                    )
                    # Build prior selections dict
                    prior_selections = {
                        d: normalized_kwargs.get(d)
                        for d in dims_in_order
                        if d in normalized_kwargs
                        and dims_in_order.index(d) < dims_in_order.index(dim_id)
                    }
                    raise ValueError(
                        f"Invalid value(s) for dimension '{dim_id}': {invalid_values}. "
                        f"Given prior selections {prior_selections}, "
                        f"available values are: {available_values}"
                    )

            # Handle any dimension codes not in the standard order
            for dim_id, codes in dimension_codes.items():
                if dim_id not in dims_in_order and dim_id not in fetch_kwargs:
                    # Validate these codes against available options
                    available_options = builder.get_options_for_dimension(dim_id)
                    available_values = {opt["value"] for opt in available_options}
                    filtered_codes = [c for c in codes if c in available_values]

                    # If no exact matches, try prefix matching
                    if not filtered_codes:
                        for hier_code in codes:
                            matching_codes = [
                                av

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Replace the offending value with one from the sorted available_values list printed in the message.
  2. Adjust prior selections (frequency, country) that constrain which indicator values are selectable.
  3. Verify the indicator code against IMF's current SDMX codelist for that dataset.
  4. Update openbb-imf to pick up refreshed hierarchy metadata.
Defensive patterns

Strategy: validation

Validate before calling

# Check indicator codes against current codelist before the fetch
codes = {'INDICATOR': ['EDP', 'XYZ']}
valid_codes = {c.value for c in obb.economy.imf.codelists(dataset='IFS').results}
filtered = {k: [c for c in v if c in valid_codes] for k, v in codes.items()}
assert all(filtered.values()), 'some indicator codes are not selectable for this table'

Type guard

def all_codes_selectable(codes: list[str], available: set[str]) -> bool:
    return bool(codes) and all(c in available or c == '*' for c in codes)

Try / catch

try:
    res = obb.economy.imf.fetch(...)
except ValueError as e:
    if 'Invalid value(s) for dimension' in str(e):
        available = parse_available_from_message(str(e))  # message embeds the valid list
        params[dim] = available[:1]  # degrade gracefully to first valid value
    raise

Prevention

When it happens

Trigger: The user provided a value for an indicator dimension (INDICATOR/SERIES/ITEM/BOP_ACCOUNTING_ENTRY) that passes hierarchy mapping but fails option validation - e.g. a series code that exists in the hierarchy yet is not selectable for this table's current dimension state.

Common situations: Deprecated indicator codes still present in older docs or notebooks; codes valid for annual frequency but not monthly; partial code strings or wrong separators ('+A+B' style multi-values with a bad member).

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/6bebe754f512e34c. Report an issue: GitHub.