{"record":{"id":"fbf3f90bca11fd2c","repo":"OpenBB-finance/OpenBB","slug":"invalid-region-region-valid-regions-are","errorCode":null,"errorMessage":"Invalid region: '{region}'. Valid regions are: {\", \".join(FACTOR_REGION_MAP.keys())}","messagePattern":"Invalid region: '(.+?)'\\. Valid regions are: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/famafrench/openbb_famafrench/models/factors.py","lineNumber":127,"sourceCode":"            }\n        },\n    )\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_region_and_factor(cls, values):\n        \"\"\"Validate region and factor combination.\"\"\"\n        region = values.get(\"region\", \"america\")\n        factor = factors_dict.get(values.get(\"factor\", \"3_factors\"), \"\")\n        frequency = values.get(\"frequency\", \"\")\n\n        if factor and factor in [\"st_reversal\", \"lt_reversal\"] and region != \"america\":\n            raise ValueError(\n                f\"Invalid region, '{region}', for factor '{factor}'. Only 'america' is supported.\"\n            )\n\n        if region and region not in list(FACTOR_REGION_MAP):\n            raise ValueError(\n                f\"Invalid region: '{region}'. \"\n                + \"Valid regions are: \"\n                + \", \".join(FACTOR_REGION_MAP.keys())\n            )\n\n        regional_factors = FACTOR_REGION_MAP[region]\n\n        if factor not in regional_factors.get(\"factors\", {}):\n            raise ValueError(\n                f\"Invalid factor: '{factor}' for region: '{region}'. \"\n                + \"Valid factors are: \"\n                + \", \".join(regional_factors.get(\"factors\", {}).keys())\n            )\n\n        if frequency:\n            intervals = regional_factors.get(\"intervals\", {}).get(factor, {})\n            if frequency not in list(intervals):\n                raise ValueError(","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/famafrench/openbb_famafrench/models/factors.py#L109-L145","documentation":"Fama-French factors query-model validator: region must be a key of FACTOR_REGION_MAP (the set of regions the Fama-French library publishes factor files for). Anything else — misspellings, full names like 'Europe' vs the expected key, unsupported regions — raises this ValueError listing the valid keys.","triggerScenarios":"Passing region='eu', 'EM', 'global', or 'Europe' (wrong case) — whatever is not an exact key of FACTOR_REGION_MAP.","commonSituations":"Free-text region inputs instead of the Literal choices; casing mismatches; users guessing region names not realizing the library covers only specific regional datasets.","solutions":["Use one of the regions printed in the error (keys of FACTOR_REGION_MAP), exact case.","If exposing this in an API/UI, restrict the input to the Literal choices on the query params model.","Note the reversal-factor exception: even valid non-america regions reject st/lt_reversal (error 335)."],"exampleFix":"# before\nquery = {'region': 'Europe', 'factor': '5_factors'}\n\n# after\nquery = {'region': 'europe', 'factor': '5_factors'}","handlingStrategy":"validation","validationCode":"from openbb_famafrench.models.factors import FACTOR_REGION_MAP\n\nvalid_regions = list(FACTOR_REGION_MAP)\n\ndef region_ok(region: str) -> bool:\n    return region in valid_regions","typeGuard":"from typing import Literal\nimport typing\nRegion = Literal['america', 'europe', 'japan']  # mirror FACTOR_REGION_MAP keys\n\ndef is_region(value: str) -> typing.TypeGuard[Region]:\n    return value in FACTOR_REGION_MAP","tryCatchPattern":"try:\n    res = await obb.economy.famafrench.factors(region=r, provider='famafrench')\nexcept ValueError as e:\n    if 'Valid regions are' in str(e):\n        r = 'america'\n        res = await obb.economy.famafrench.factors(region=r, provider='famafrench')\n    else:\n        raise","preventionTips":["Restrict region inputs to the Literal choices on the query model","Exact-case match against FACTOR_REGION_MAP keys"],"tags":["famafrench","factors","validation","region"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}