OpenBB-finance/OpenBB · error · ValueError
Invalid region: '{region}'. Valid regions are: {", ".join(FA
Error message
Invalid region: '{region}'. Valid regions are: {", ".join(FACTOR_REGION_MAP.keys())} What it means
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.
Source
Thrown at openbb_platform/providers/famafrench/openbb_famafrench/models/factors.py:127
}
},
)
@model_validator(mode="before")
@classmethod
def validate_region_and_factor(cls, values):
"""Validate region and factor combination."""
region = values.get("region", "america")
factor = factors_dict.get(values.get("factor", "3_factors"), "")
frequency = values.get("frequency", "")
if factor and factor in ["st_reversal", "lt_reversal"] and region != "america":
raise ValueError(
f"Invalid region, '{region}', for factor '{factor}'. Only 'america' is supported."
)
if region and region not in list(FACTOR_REGION_MAP):
raise ValueError(
f"Invalid region: '{region}'. "
+ "Valid regions are: "
+ ", ".join(FACTOR_REGION_MAP.keys())
)
regional_factors = FACTOR_REGION_MAP[region]
if factor not in regional_factors.get("factors", {}):
raise ValueError(
f"Invalid factor: '{factor}' for region: '{region}'. "
+ "Valid factors are: "
+ ", ".join(regional_factors.get("factors", {}).keys())
)
if frequency:
intervals = regional_factors.get("intervals", {}).get(factor, {})
if frequency not in list(intervals):
raise ValueError(View on GitHub (pinned to 3e071fcc2c)
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).
Example fix
# before
query = {'region': 'Europe', 'factor': '5_factors'}
# after
query = {'region': 'europe', 'factor': '5_factors'} Defensive patterns
Strategy: validation
Validate before calling
from openbb_famafrench.models.factors import FACTOR_REGION_MAP
valid_regions = list(FACTOR_REGION_MAP)
def region_ok(region: str) -> bool:
return region in valid_regions Type guard
from typing import Literal
import typing
Region = Literal['america', 'europe', 'japan'] # mirror FACTOR_REGION_MAP keys
def is_region(value: str) -> typing.TypeGuard[Region]:
return value in FACTOR_REGION_MAP Try / catch
try:
res = await obb.economy.famafrench.factors(region=r, provider='famafrench')
except ValueError as e:
if 'Valid regions are' in str(e):
r = 'america'
res = await obb.economy.famafrench.factors(region=r, provider='famafrench')
else:
raise Prevention
- Restrict region inputs to the Literal choices on the query model
- Exact-case match against FACTOR_REGION_MAP keys
When it happens
Trigger: Passing region='eu', 'EM', 'global', or 'Europe' (wrong case) — whatever is not an exact key of FACTOR_REGION_MAP.
Common situations: Free-text region inputs instead of the Literal choices; casing mismatches; users guessing region names not realizing the library covers only specific regional datasets.
Related errors
- Invalid region, '{region}', for factor '{factor}'. Only 'ame
- Invalid factor: '{factor}' for region: '{region}'. Valid fac
- Invalid frequency: '{frequency}' for factor: '{factor}' in r
- Invalid dataset, {dataset}
- The request was returned empty. This may be due to an invali
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/fbf3f90bca11fd2c.
Report an issue: GitHub.