OpenBB-finance/OpenBB · error · ValueError

Invalid amendment type: {amendment_type}. Must be one of {',

Error message

Invalid amendment type: {amendment_type}. Must be one of {', '.join(AmendmentTypes)}.

What it means

get_amendments validates the optional amendment_type against AmendmentTypes ('hamdt' = House amendment, 'samdt' = Senate amendment, 'suamdt' = Senate unprinted amendment) before building the /amendment URL. None is allowed (fetches all types); any other value raises ValueError. Case-sensitive.

Source

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

    end_date : Optional[str]
        The end date in ISO format (YYYY-MM-DD) for filtering by updateDate.
    limit : Optional[int]
        The maximum number of amendments 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 amendment_type is not None and amendment_type not in AmendmentTypes:
        raise ValueError(
            f"Invalid amendment type: {amendment_type}. Must be one of {', '.join(AmendmentTypes)}."
        )

    api_key = check_api_key()
    url = f"{base_url}amendment"

    if congress is not None:
        url += f"/{congress}"

        if amendment_type is not None:
            url += f"/{amendment_type}"

    url += (f"?fromDateTime={start_date + 'T00:00:00Z'}" if start_date else "") + (
        f"&toDateTime={end_date + 'T23:59:59Z'}" if end_date else ""
    )
    url += (
        f"{'?' if '?' not in url else '&'}"
        + f"limit={limit if limit is not None else 100}"

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use 'hamdt', 'samdt', 'suamdt', or None
  2. Normalize input: amendment_type.strip().lower() at the boundary
  3. Map display labels ('House Amendment' -> 'hamdt') in your adapter layer

Example fix

# before
amds = await get_amendments(congress=118, amendment_type='Senate Amendment')

# after
amds = await get_amendments(congress=118, amendment_type='samdt')
Defensive patterns

Strategy: validation

Validate before calling

from openbb_congress_gov.utils.constants import AmendmentTypes

def normalize_amendment_type(at: str | None) -> str | None:
    if at is None:
        return None
    at = at.strip().lower()
    assert at in AmendmentTypes, f'Invalid amendment type {at!r}; use {AmendmentTypes}'
    return at

Type guard

def is_valid_amendment_type(at: str | None) -> bool:
    return at is None or at.strip().lower() in ('hamdt', 'samdt', 'suamdt')

Prevention

When it happens

Trigger: amendment_type='house'; 'HAMDT' (uppercase); a bill type like 'hres'; whitespace-padded 'samdt '.

Common situations: Users spelling out chamber names instead of codes; mixing bill/law/amendment taxonomies; unnormalized UI input.

Related errors


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