OpenBB-finance/OpenBB · error · HTTPException

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

Error message

Invalid bill type: {bill_type}. Must be one of {', '.join([option['value'] for option in bill_type_options])}.

What it means

The bill viewer's dynamic parameter-choices helper validates bill_type against the Workspace UI's bill_type_options list and raises HTTPException(500) when it does not match. This mirrors the BillTypes codes but is driven by the widget's option list, and it fires before any API call. The 500 status is arguably wrong for bad input (422 would be more apt) but the intent is rejecting unknown type codes early.

Source

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

    start_date: str | None = None,
    end_date: str | None = None,
    bill_url: str | None = None,
    is_document_choices: bool | None = None,
) -> list:
    """Fetch a list of bills of a specific type for a given Congress number.

    This function is not intended to be used directly.

    It is used by the OpenBB Workspace Congressional Bills Viewer widget
    to populate dynamic parameter choices based on the widget's state.
    """
    # pylint: disable=import-outside-toplevel
    from datetime import datetime

    bills_state = BillsState()

    if bill_type and bill_type not in [option["value"] for option in bill_type_options]:
        raise HTTPException(
            status_code=500,
            detail=f"Invalid bill type: {bill_type}."
            + f" Must be one of {', '.join([option['value'] for option in bill_type_options])}.",
        )

    if bill_url:
        return await get_bill_text_choices(bill_url=bill_url)

    if is_document_choices is True and not bill_url:
        return [
            {
                "label": "Select a bill to view associated text.",
                "value": "",
            }
        ]

    if not bill_type:
        bill_type = "hr"

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Send an exact value from bill_type_options — lowercase, no extra whitespace
  2. Fetch the options list first and constrain your UI to it rather than free-text input
  3. If calling programmatically, normalize with .strip().lower() before passing

Example fix

# before
choices = await get_bill_viewer_choices(bill_type='HR')

# after
choices = await get_bill_viewer_choices(bill_type='hr')
Defensive patterns

Strategy: validation

Validate before calling

def valid_bill_viewer_type(bt: str, options: list[dict]) -> str:
    values = [o['value'] for o in options]
    if bt not in values:
        raise ValueError(f'{bt!r} not one of {values}')
    return bt

Type guard

def is_valid_viewer_bill_type(bt: str, options: list[dict]) -> bool:
    return bt in [o['value'] for o in options]

Try / catch

from fastapi import HTTPException
try:
    choices = await get_bill_viewer_choices(bill_type=bt, ...)
except HTTPException as e:
    if 'Invalid bill type' in e.detail:
        bt = 'hr'  # reset to default and retry
        choices = await get_bill_viewer_choices(bill_type=bt, ...)
    else:
        raise

Prevention

When it happens

Trigger: Workspace widget or direct call to the bill viewer choices endpoint with bill_type='hr ' or 'HR' (matching is exact, no lowercasing here); a widget state where the type selector was edited manually rather than chosen from the dropdown.

Common situations: Custom dashboards reusing the widget parameter contract; hand-crafted requests to the choices endpoint; state restored from older versions whose option lists differ.

Related errors


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