OpenBB-finance/OpenBB · error · ValueError

Invalid {name}(s): {', '.join(invalid)}

Error message

Invalid {name}(s): {', '.join(invalid)}

What it means

Raised by the inner _validate_selection in imts_query after checking every country/counterpart entry against the IMTS dataflow's allowed SDMX dimension values (fetched from provider metadata). Unlike the friendlier dot_helpers resolver, this layer expects actual dimension codes, and anything not in the dataflow's COUNTRY/COUNTERPART_COUNTRY value set is rejected with the offending items listed. Wildcards ('*') short-circuit and pass.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/utils/dot_helpers.py:207

        # Parse the selection into a list
        if isinstance(selection, str):
            # Check if it contains commas (comma-separated list)
            selection_list = (
                [item.strip() for item in selection.split(",")]
                if "," in selection
                else [selection]
            )
        else:
            selection_list = selection

        # Check if any item is a wildcard
        if "*" in selection_list:
            return "*"

        invalid = [item for item in selection_list if item not in valid_values]
        if invalid:
            raise ValueError(f"Invalid {name}(s): {', '.join(invalid)}")
        return selection_list if len(selection_list) > 1 else selection_list[0]

    validated_country = _validate_selection(country, country_values, "country")
    validated_counterpart = _validate_selection(
        counterpart, counterpart_values, "counterpart"
    )

    # For indicator, handle wildcards and comma-separated values the same way
    if isinstance(indicator, str) and "," in indicator:
        validated_indicator = [item.strip() for item in indicator.split(",")]
    else:
        validated_indicator = indicator if indicator != "*" else "*"  # type: ignore

    return query_builder.fetch_data(
        dataflow=dataflow_id,
        start_date=start_date,
        end_date=end_date,
        FREQUENCY=freq,

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Pass ISO3-style codes ('USA', 'DEU') that exist in the IMTS dimension — check the invalid list in the message for exactly which entries failed.
  2. Pre-resolve friendly names with the dot_helpers country resolver before calling imts_query.
  3. If you meant 'all', pass '*' rather than enumerating names.

Example fix

# before
res = imts_query(country='united_states', counterpart='germany', indicator='TXG_FOB_USD')

# after
from openbb_imf.utils.dot_helpers import transform_country
country = transform_country('united_states')   # 'USA'
counterpart = transform_country('germany')     # 'DEU'
res = imts_query(country=country, counterpart=counterpart, indicator='TXG_FOB_USD')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_imf.utils.query_builder import ImfQueryBuilder
qb = ImfQueryBuilder()
params = qb.metadata.get_dataflow_parameters('IMTS')
valid = {i['value'] for i in params.get('COUNTRY', [])}
selected = [c for c in country_list if c in valid or c == '*']
if not selected:
    raise ValueError(f'No valid IMTS countries; valid set sample: {sorted(valid)[:5]}')

Type guard

def are_valid_imts_selections(values: list[str], valid: set[str]) -> bool:
    return '*' in values or all(v in valid for v in values)

Try / catch

try:
    res = imts_query(country=c, counterpart=cp, indicator=ind)
except ValueError as e:
    if e.args and e.args[0].startswith('Invalid '):
        # re-resolve names via transform_country, then retry
        c = [transform_country(x) for x in c]
        res = imts_query(country=c, counterpart=cp, indicator=ind)
    else:
        raise

Prevention

When it happens

Trigger: Passing snake_case names here when the dimension only contains ISO-style codes (e.g. 'united_states' not in the set but 'USA' is); a valid country that the specific IMTS dataflow does not cover; comma-separated strings where one entry is a typo; deprecated country codes after IMF revisions.

Common situations: Mixing the two country vocabularies (resolver-friendly names vs strict dimension codes) in one code path; dataflows whose coverage differs (small economies missing from IMTS); scripts written against older code lists.

Related errors


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