OpenBB-finance/OpenBB · error · ValueError

At least one extension type must be selected.

Error message

At least one extension type must be selected.

What it means

Raised by the CPI query-params field validator when a country token (after spaces become underscores and the string is split on commas) is neither an ISO3 code in `CPI_CODE_SET` nor a snake_case name in `CPI_LABEL_TO_CODE`. The CPI dataset maintains its own country mapping, which is narrower than the full IMF country list, so codes valid elsewhere can still fail here. It is a pydantic `field_validator` on `mode='before'`, so it rejects the model at construction time.

Source

Thrown at cookiecutter/openbb_cookiecutter/cli.py:32

    "router",
    "provider",
    "obbject",
    "on_command_output",
    "charting",
    "all",
]


def _parse_extension_types(value: str) -> list[str]:
    types = [t.strip() for t in value.split(",") if t.strip()]
    invalid = [t for t in types if t not in VALID_EXTENSION_TYPES]
    if invalid:
        raise ValueError(
            f"Invalid extension type(s): {', '.join(invalid)}. "
            f"Valid choices: {', '.join(VALID_EXTENSION_TYPES)}"
        )
    if not types:
        raise ValueError("At least one extension type must be selected.")
    return types


def _prompt_context(preset_extension_types: list[str] | None = None) -> dict:
    context = {}

    context["full_name"] = Prompt.ask("  full_name", default="Hello World")
    context["email"] = Prompt.ask("  email", default="hello@world.com")
    context["project_name"] = Prompt.ask(
        "  project_name", default="OpenBB Python Extension Template"
    )
    default_tag = context["project_name"].lower().replace(" ", "-").replace("_", "-")
    context["project_tag"] = Prompt.ask("  project_tag", default=default_tag)
    default_pkg = context["project_name"].lower().replace(" ", "_").replace("-", "_")
    context["package_name"] = Prompt.ask("  package_name", default=default_pkg)

    if preset_extension_types:
        types = preset_extension_types

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use exact ISO3 codes from the provider's CPI mapping: import `CPI_CODE_SET` from `openbb_imf.models.consumer_price_index` and pick codes from it.
  2. For names, use the snake_case form the mapping expects (check `CPI_LABEL_TO_CODE` keys, e.g. 'united_states').
  3. Split your list and validate each token before the call so one bad country doesn't reject the whole request.
  4. Upgrade the openbb-imf package if the country was added/renamed upstream.

Example fix

# before
res = obb.economy.cpi(provider='imf', country='EUROZONE', expenditure='all')

# after
res = obb.economy.cpi(provider='imf', country='USA', expenditure='all')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_imf.models.consumer_price_index import CPI_CODE_SET, CPI_LABEL_TO_CODE

def normalize_cpi_country(raw: str) -> str:
    tokens = raw.replace(' ', '_').split(',')
    out = []
    for t in tokens:
        u, l = t.upper(), t.lower()
        if u in CPI_CODE_SET:
            out.append(u)
        elif l in CPI_LABEL_TO_CODE:
            out.append(CPI_LABEL_TO_CODE[l])
        else:
            raise ValueError(f'Country {t!r} not in the IMF CPI mapping; pick from CPI_CODE_SET.')
    return ','.join(out)

country = normalize_cpi_country('united_states,deu')

Type guard

from openbb_imf.models.consumer_price_index import CPI_CODE_SET, CPI_LABEL_TO_CODE

def is_valid_cpi_country(raw: str) -> bool:
    t = raw.replace(' ', '_')
    return t.upper() in CPI_CODE_SET or t.lower() in CPI_LABEL_TO_CODE

Prevention

When it happens

Trigger: Passing a country like `country='ZWE'` when ZWE is not in the CPI code set, or `country='cote_divoire'` when the mapping spells it differently, or a comma list containing one bad token (`country='USA,EUROZONE'` where EUROZONE is an area, not a CPI country). Input is uppercased for code lookup and lowercased for name lookup, so case itself is never the issue.

Common situations: Reusing country lists built for other IMF endpoints (DOT, IFS) that accept a wider set; IMF-specific spellings (e.g. 'cote_d_ivoire', 'sao_tome_and_principe') not matching a caller's 'ivory_coast' style; new/renamed countries not present in the provider's pinned CPI mapping (version drift).

Related errors


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