OpenBB-finance/OpenBB · error · ValueError

Invalid bill type: {bill_type}. Must be one of {', '.join(Bi

Error message

Invalid bill type: {bill_type}. Must be one of {', '.join(BillTypes)}.

What it means

get_bills_by_type validates the bill_type argument against the BillTypes constant (['hr','s','hjres','sjres','hconres','sconres','hres','sres']) and raises ValueError on anything else. Note the check is case-sensitive here — the sibling get_all_bills lowercases first, but this path does not, so 'HR' fails as well as 'bill'. The bill type forms the URL path segment, so an invalid value would otherwise 404 at the API.

Source

Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py:195

        The number of results to skip before starting to collect the result set.
        Defaults to 0 if None.
    sort_by : Literal["asc", "desc"]
        The sort order for the results. Defaults to "desc".

    Returns
    -------
    dict
        A dictionary of the raw JSON response from the API.
    """
    # pylint: disable=import-outside-toplevel
    from datetime import (  # noqa
        date as dateType,
        datetime,
    )
    from openbb_core.provider.utils.helpers import amake_request

    if bill_type and bill_type not in BillTypes:
        raise ValueError(
            f"Invalid bill type: {bill_type}. Must be one of {', '.join(BillTypes)}."
        )

    api_key = check_api_key()

    if start_date is None and end_date is None and congress is None:
        congress = year_to_congress(datetime.now().year)
    elif congress is None and start_date is not None:
        congress = year_to_congress(dateType.fromisoformat(start_date).year)
    elif congress is None and end_date is not None and start_date is None:
        congress = year_to_congress(dateType.fromisoformat(end_date).year)
    elif start_date is not None and end_date is not None:
        start_year = dateType.fromisoformat(start_date).year
        end_year = dateType.fromisoformat(end_date).year
        congress_start = year_to_congress(start_year)
        congress_end = year_to_congress(end_year)
        if congress_start != congress_end:
            raise ValueError(

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Normalize input: bill_type = bill_type.strip().lower() before calling
  2. Use only the eight valid codes: hr, s, hjres, sjres, hconres, sconres, hres, sres
  3. Validate against openbb_congress_gov.utils.constants.BillTypes at your boundary for a better error message

Example fix

# before
res = await get_bills_by_type(congress=118, bill_type='HR')

# after
res = await get_bills_by_type(congress=118, bill_type='hr')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_congress_gov.utils.constants import BillTypes

def normalize_bill_type(bt: str | None) -> str | None:
    if bt is None:
        return None
    bt = bt.strip().lower()
    if bt not in BillTypes:
        raise ValueError(f'{bt!r} not in {BillTypes}')
    return bt

Type guard

from openbb_congress_gov.utils.constants import BillTypes

def is_valid_bill_type(bt: str | None) -> bool:
    return bt is None or bt.strip().lower() in BillTypes

Prevention

When it happens

Trigger: Calling get_bills_by_type(bill_type='HR') (uppercase); passing 'hres ' with whitespace; passing a made-up type like 'hrbill' or a law type like 'pub'.

Common situations: User input not normalized to lowercase; confusion with other taxonomies (law types 'pub'/'priv', amendment types); data pipelines passing display labels ('House Report') instead of codes.

Related errors


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