OpenBB-finance/OpenBB · error · ValueError

Invalid factor: '{factor}' for region: '{region}'. Valid fac

Error message

Invalid factor: '{factor}' for region: '{region}'. Valid factors are: {", ".join(regional_factors.get("factors", {}).keys())}

What it means

Fama-French factors query-model validator: after the region resolves, the requested factor must appear in FACTOR_REGION_MAP[region]['factors']. Regions carry different factor sets (e.g. some regional datasets lack momentum or the 5-factor model), so a globally valid factor name can still be invalid for the chosen region.

Source

Thrown at openbb_platform/providers/famafrench/openbb_famafrench/models/factors.py:136

        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(
                    f"Invalid frequency: '{frequency}' for factor: '{factor}'"
                    + f" in region: '{region}'. "
                    + "Valid frequencies are: "
                    + ", ".join(intervals.keys())
                )

        return values

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Pick a factor from the region's list given in the error message (FACTOR_REGION_MAP[region]['factors'].keys()).
  2. Drive choices dynamically from FACTOR_REGION_MAP when region is user-selected.
  3. For the classic 3/5-factor models, 'america' has the widest coverage — switch region if you need a specific factor.

Example fix

# before
query = {'region': 'japan', 'factor': 'momentum'}

# after
from openbb_famafrench.models.factors import FACTOR_REGION_MAP
valid = list(FACTOR_REGION_MAP['japan']['factors'])
query = {'region': 'japan', 'factor': valid[0]}
Defensive patterns

Strategy: validation

Validate before calling

from openbb_famafrench.models.factors import FACTOR_REGION_MAP

factors_for = lambda region: list(FACTOR_REGION_MAP.get(region, {}).get('factors', {}))

def factor_ok(region: str, factor: str) -> bool:
    return factor in factors_for(region)

Try / catch

try:
    res = await obb.economy.famafrench.factors(factor=f, region=r, provider='famafrench')
except ValueError as e:
    if 'Valid factors are' in str(e):
        f = factors_for(r)[0]
        res = await obb.economy.famafrench.factors(factor=f, region=r, provider='famafrench')
    else:
        raise

Prevention

When it happens

Trigger: factor='5_factors' with a region that only publishes 3_factors; factor='momentum' for a regional dataset without momentum files; any factor string not a key of the region's factors dict.

Common situations: Reusing a working (factor, region) pair with a new region; UIs offering a flat factor list; dataset coverage differences between North America, Europe, Japan, Asia-Pacific.

Related errors


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