OpenBB-finance/OpenBB · error · OpenBBError

Invalid symbol: '{symbol}'. It must have a two-letter countr

Error message

Invalid symbol: '{symbol}'. It must have a two-letter country code.

What it means

OpenBBError during EconDB indicator symbol processing: a symbol like 'CPI~' or 'CPI~xyz' contains '~', the root (e.g. 'CPI') is a multi-country indicator (HAS_COUNTRIES[root] is True), but no two-letter country code was attached. When multiple symbols were requested this degrades to a warning and the symbol is skipped; with a single symbol it raises.

Source

Thrown at openbb_platform/providers/econdb/openbb_econdb/models/economic_indicators.py:239

            # match this defined symbol with any supplied country, and we need to
            # ignore the transform parameter because it has already been dictated by ~.
            # We will check if the transform is valid,
            # and return the symbol as 'level' if it is not.
            # We will also check if the symbol should have a country,
            # and if one was supplied.
            symbol = s.upper()
            if "~" in symbol:
                _symbol = symbol.split("~")[0]
                _transform = symbol.split("~")[1]
                if (
                    helpers.HAS_COUNTRIES.get(_symbol) is True
                    and _symbol in helpers.SYMBOL_TO_INDICATOR.values()
                ):
                    message = f"Invalid symbol: '{symbol}'. It must have a two-letter country code."
                    if len(symbols) > 1:
                        warn(message)
                        continue
                    raise OpenBBError(message)
                if _transform and _transform not in helpers.QUERY_TRANSFORMS:
                    message = f"Invalid transformation, '{_transform}', for symbol: '{_symbol}'."
                    if len(symbols) > 1:
                        warn(message)
                        new_symbols.append(_symbol)
                    else:
                        raise OpenBBError(message)
                elif not _transform:
                    new_symbols.append(symbol.replace("~", ""))
                else:
                    new_symbols.append(symbol)
            # Else we need to wrap each symbol with each country code
            # and check if the country is valid for that indicator.
            elif countries and helpers.HAS_COUNTRIES.get(symbol) is True:
                for country in countries:
                    _country = (
                        helpers.INDICATOR_COUNTRIES.get(symbol, [])
                        if country == "all"

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Append a two-letter country code to the root: 'CPI~us' (transform only) or 'CPI_us' (country form).
  2. Alternatively pass country='us' as a query parameter and keep the bare root.
  3. In multi-symbol batches, scan warnings — malformed symbols are skipped with this same message, shrinking your result set silently.

Example fix

# before
res = obb.economy.indicator(provider="econdb", symbol="cpi~")

# after
res = obb.economy.indicator(provider="econdb", symbol="cpi~us")
# or
res = obb.economy.indicator(provider="econdb", symbol="cpi", country="us")
Defensive patterns

Strategy: validation

Validate before calling

from openbb_econdb.utils import helpers

def symbol_has_country_code(symbol: str) -> bool:
    if "~" not in symbol:
        return True  # different code path
    root = symbol.split("~")[0]
    return not (helpers.HAS_COUNTRIES.get(root) is True and root in helpers.SYMBOL_TO_INDICATOR.values() and not symbol.split("~")[1])

Try / catch

from openbb_core.provider.utils.errors import OpenBBError
try:
    res = obb.economy.indicator(provider="econdb", symbol=s, country=cs)
except OpenBBError as e:
    if "two-letter country code" in str(e):
        res = obb.economy.indicator(provider="econdb", symbol=f"{s}~us")
    else:
        raise

Prevention

When it happens

Trigger: Calling obb.economy.indicator(provider='econdb', symbol='CPI~') or symbol='GDP' style bare roots that require countries (via the '~' path), without using the country parameter and without appending a country code (correct form: 'CPI~us' or 'CPI_us').

Common situations: Misunderstanding the '~transform'/'_country' suffix grammar; passing a country-required indicator while relying on a country parameter that was omitted or invalid; batch requests where one malformed root silently disappears (warning only).

Related errors


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