OpenBB-finance/OpenBB · error · OpenBBError

Invalid table choice: {table}. Valid choices for {category}:

Error message

Invalid table choice: {table}. Valid choices for {category}: {list(tables)}

What it means

EIA Weekly Petroleum Status Report validator: each comma-separated table name in the table parameter must be a key of WpsrTableMap for the chosen category (or the literal 'all'). An unknown name raises this OpenBBError listing the valid choices for that category.

Source

Thrown at openbb_platform/providers/eia/openbb_us_eia/models/petroleum_status_report.py:103

        if not _table:
            _table = "stocks" if category == "weekly_estimates" else "all"

        _tables = _table.split(",")

        if len(_tables) == 1 and _tables[0] == "all" and category == "weekly_estimates":
            raise OpenBBError(
                ValueError(
                    f"'all' is not a supported choice for {category}. Please choose from: {list(tables)}"
                )
            )

        if "all" in _tables and len(_tables) > 1:
            _tables.remove("all")
            warn("'all' cannot be used with other table choices. Ignoring 'all'.")

        for table in _tables:
            if table != "all" and table not in tables:
                raise OpenBBError(
                    ValueError(
                        f"Invalid table choice: {table}. Valid choices for {category}: {list(tables)}"
                    )
                )

        params["table"] = ",".join(_tables)

        return EiaPetroleumStatusReportQueryParams(**params)

    @staticmethod
    async def aextract_data(
        query: EiaPetroleumStatusReportQueryParams,
        credentials: dict[str, Any] | None,
        **kwargs: Any,
    ) -> dict:
        """Extract the data from the EIA website."""
        # pylint: disable=import-outside-toplevel
        from openbb_us_eia.utils.helpers import download_excel_file

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use a table name from the error message's valid list (keys of WpsrTableMap[category]).
  2. Match the category and table pair — tables are per-category, not global.
  3. Reference openbb_us_eia.utils.helpers.WpsrTableMap at runtime to build dynamic UI choices instead of hard-coding.
  4. Check spelling and case exactly.

Example fix

# before
params = {'category': 'weekly_estimates', 'table': 'inventory'}

# after
from openbb_us_eia.utils.helpers import WpsrTableMap
valid = list(WpsrTableMap['weekly_estimates'])
params = {'category': 'weekly_estimates', 'table': valid[0]}
Defensive patterns

Strategy: validation

Validate before calling

from openbb_us_eia.utils.helpers import WpsrTableMap

def valid_tables(category: str, tables: list[str]) -> bool:
    allowed = set(WpsrTableMap.get(category, {})) | {'all'}
    return all(t in allowed for t in tables)

Try / catch

try:
    res = await obb.energy.petroleum_status_report(category=cat, table=','.join(tbls), provider='eia')
except OpenBBError as e:
    if 'Invalid table choice' in str(e):
        # parse the valid list from the message or re-derive and fix
        tbls = [t for t in tbls if t in WpsrTableMap.get(cat, {})]
        res = await obb.energy.petroleum_status_report(category=cat, table=','.join(tbls), provider='eia')
    else:
        raise

Prevention

When it happens

Trigger: Passing table='inventories' when the category's map has no such key; mixing table names from one category with another category (e.g. a 'balance_sheet' table name while category='weekly_estimates'); typos or renamed tables after a provider update.

Common situations: Hard-coded table names breaking when WpsrTableMap is updated; case mismatch ('Stocks' vs 'stocks'); copying example params from docs for a different category.

Related errors


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