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: {all_values} What it means
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.
Source
Thrown at openbb_platform/providers/imf/openbb_imf/utils/query_builder.py:240
if invalid_values:
# Build helpful error message
prior_selections = {
d: kwargs.get(d)
for d in dimensions_in_order
if d in kwargs
and dimensions_in_order.index(d)
< dimensions_in_order.index(dim_id)
}
# Show all available values without truncation
all_values = sorted(available_values)
error_msg = (
f"Invalid value(s) for dimension '{dim_id}': {invalid_values}. "
f"Given prior selections {prior_selections}, "
f"available values are: {all_values}"
)
raise ValueError(error_msg)
# Set the valid value to progress the builder
builder.set_dimension((dim_id, user_values[0]))
# Check time period constraints from the last dimension validation
# The _last_constraints_response already contains contentConstraints with TIME_PERIOD info
start_date = kwargs.get("start_date")
end_date = kwargs.get("end_date")
if start_date or end_date:
constraints = builder._last_constraints_response
if constraints:
full_response = constraints.get("full_response", {})
data = full_response.get("data", {})
# Time period annotations can be in contentConstraints or dataConstraints
# Check both places
time_start = NoneView on GitHub (pinned to 3e071fcc2c)
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.
Example fix
# before
url = qb.build_url('BOP', FREQUENCY='A', REF_AREA='US', INDICATOR='...') # US invalid
# after
url = qb.build_url('BOP', FREQUENCY='A', REF_AREA='USA', INDICATOR='...') # ISO3 code Defensive patterns
Strategy: validation
Validate before calling
def validate_dimension_values(builder, dim_id: str, values: list[str]) -> list[str]:
available = {o['value'] for o in builder.get_dimension_options(dim_id)}
invalid = [v for v in values if v not in available]
if invalid:
raise ValueError(f'{dim_id}: invalid {invalid}; allowed (given selections): {sorted(available)}')
return values Type guard
def values_are_valid(builder, dim_id: str, values: list[str]) -> bool:
available = {o['value'] for o in builder.get_dimension_options(dim_id)}
return all(v in available for v in values) Try / catch
try:
url = qb.build_url(dataflow, **kwargs)
except ValueError as e:
m = re.search(r'available values are: \[(.*)\]', str(e))
if m:
kwargs[dim] = pick_from(ast.literal_eval('[' + m.group(1) + ']'))
url = qb.build_url(dataflow, **kwargs)
else:
raise Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Results not found.
- Please install polars: `pip install polars pyarrow` to use
- Chart not found.
- Invalid logging handler
- Extension '{ext_name}' is not installed.
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/594d24289aff14ed.
Report an issue: GitHub.