OpenBB-finance/OpenBB · error · ValueError

Invalid law type: {law_type}. Must be one of {', '.join(LawT

Error message

Invalid law type: {law_type}. Must be one of {', '.join(LawTypes)}.

What it means

get_laws validates law_type against LawTypes = ['pub', 'priv'] (public vs private laws) before building the /law/{congress} URL. The check only fires when law_type is not None, so omitting it is valid. Values are matched case-sensitively here — 'PUB' fails — and any other taxonomy value (e.g. a bill type) is rejected.

Source

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

        The type of law to fetch. Must be one of: "pub", "priv".
        If None, returns all laws for the congress.
    limit : Optional[int]
        The maximum number of laws to return. Defaults to 100 if None.
    offset : Optional[int]
        The number of results to skip before starting to collect the result set.
    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 openbb_core.provider.utils.helpers import amake_request

    if law_type is not None and law_type not in LawTypes:
        raise ValueError(
            f"Invalid law type: {law_type}. Must be one of {', '.join(LawTypes)}."
        )

    api_key = check_api_key()

    url = (
        f"{base_url}law/{congress}"
        + (f"/{law_type}" if law_type else "")
        + f"?limit={limit if limit is not None else 100}"
        + (f"&offset={offset}" if offset else "")
        + f"&sort=updateDate+{sort_by}"
        + f"&format=json&api_key={api_key}"
    )

    return await amake_request(url)  # type: ignore


async def get_all_laws_by_type(congress: int, law_type: str = "pub") -> list:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use exactly 'pub' or 'priv', or None to fetch both
  2. Normalize input: law_type.strip().lower() at the call site
  3. Expose only the two codes in your UI instead of free text

Example fix

# before
laws = await get_laws(congress=118, law_type='public')

# after
laws = await get_laws(congress=118, law_type='pub')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_congress_gov.utils.constants import LawTypes

def normalize_law_type(lt: str | None) -> str | None:
    if lt is None:
        return None
    lt = lt.strip().lower()
    assert lt in LawTypes, f'Invalid law type {lt!r}; use {LawTypes}'
    return lt

Type guard

def is_valid_law_type(lt: str | None) -> bool:
    return lt is None or lt.strip().lower() in ('pub', 'priv')

Prevention

When it happens

Trigger: get_laws(congress=118, law_type='public'); law_type='hr' (bill type); law_type='PUB' (uppercase); leading/trailing whitespace.

Common situations: Confusing the human-readable 'public/private' with the API codes; reusing bill-type enums for laws; unnormalized user input.

Related errors


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