{"record":{"id":"4e2abc99a6b06bf8","repo":"OpenBB-finance/OpenBB","slug":"invalid-law-type-law-type-must-be-one-of","errorCode":null,"errorMessage":"Invalid law type: {law_type}. Must be one of {', '.join(LawTypes)}.","messagePattern":"Invalid law type: (.+?)\\. Must be one of (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py","lineNumber":550,"sourceCode":"        The type of law to fetch. Must be one of: \"pub\", \"priv\".\n        If None, returns all laws for the congress.\n    limit : Optional[int]\n        The maximum number of laws to return. Defaults to 100 if None.\n    offset : Optional[int]\n        The number of results to skip before starting to collect the result set.\n    sort_by : Literal[\"asc\", \"desc\"]\n        The sort order for the results. Defaults to \"desc\".\n\n    Returns\n    -------\n    dict\n        A dictionary of the raw JSON response from the API.\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    from openbb_core.provider.utils.helpers import amake_request\n\n    if law_type is not None and law_type not in LawTypes:\n        raise ValueError(\n            f\"Invalid law type: {law_type}. Must be one of {', '.join(LawTypes)}.\"\n        )\n\n    api_key = check_api_key()\n\n    url = (\n        f\"{base_url}law/{congress}\"\n        + (f\"/{law_type}\" if law_type else \"\")\n        + f\"?limit={limit if limit is not None else 100}\"\n        + (f\"&offset={offset}\" if offset else \"\")\n        + f\"&sort=updateDate+{sort_by}\"\n        + f\"&format=json&api_key={api_key}\"\n    )\n\n    return await amake_request(url)  # type: ignore\n\n\nasync def get_all_laws_by_type(congress: int, law_type: str = \"pub\") -> list:","sourceCodeStart":532,"sourceCodeEnd":568,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/congress_gov/openbb_congress_gov/utils/helpers.py#L532-L568","documentation":"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.","triggerScenarios":"get_laws(congress=118, law_type='public'); law_type='hr' (bill type); law_type='PUB' (uppercase); leading/trailing whitespace.","commonSituations":"Confusing the human-readable 'public/private' with the API codes; reusing bill-type enums for laws; unnormalized user input.","solutions":["Use exactly 'pub' or 'priv', or None to fetch both","Normalize input: law_type.strip().lower() at the call site","Expose only the two codes in your UI instead of free text"],"exampleFix":"# before\nlaws = await get_laws(congress=118, law_type='public')\n\n# after\nlaws = await get_laws(congress=118, law_type='pub')","handlingStrategy":"validation","validationCode":"from openbb_congress_gov.utils.constants import LawTypes\n\ndef normalize_law_type(lt: str | None) -> str | None:\n    if lt is None:\n        return None\n    lt = lt.strip().lower()\n    assert lt in LawTypes, f'Invalid law type {lt!r}; use {LawTypes}'\n    return lt","typeGuard":"def is_valid_law_type(lt: str | None) -> bool:\n    return lt is None or lt.strip().lower() in ('pub', 'priv')","tryCatchPattern":null,"preventionTips":["Map 'public'->'pub', 'private'->'priv' in your adapter","Remember None is valid here (fetches both types)","Case-sensitive check — lowercase your input"],"tags":["congress-gov","validation","law-type","case-sensitivity"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}