OpenBB-finance/OpenBB · error · OpenBBError

Maturity must be between 1 and 100

Error message

Maturity must be between 1 and 100

What it means

Intended as a range check in FredSpotFetcher.extract_data (openbb_fred/models/spot.py:79): maturity values (years) must lie in [1, 100] before mapping to FRED spot-rate series IDs. IMPORTANT: the guard as written, 'if any(1 > m > 100 for m in maturity)', is a chained comparison meaning (1 > m) and (m > 100), which is unsatisfiable - so this OpenBBError can never actually fire. Out-of-range maturities therefore fall through to get_spot_series_id, which returns an empty series list and the call fails elsewhere (or returns empty data) instead.

Source

Thrown at openbb_platform/providers/fred/openbb_fred/models/spot.py:79

    ) -> list:
        """Extract data."""
        # pylint: disable=import-outside-toplevel
        from openbb_fred.utils.fred_base import Fred
        from openbb_fred.utils.fred_helpers import (
            comma_to_float_list,
            get_spot_series_id,
        )

        key = credentials.get("fred_api_key") if credentials else ""
        fred = Fred(key)

        maturity = (
            comma_to_float_list(query.maturity)
            if isinstance(query.maturity, str)
            else [query.maturity]
        )
        if any(1 > m > 100 for m in maturity):
            raise OpenBBError("Maturity must be between 1 and 100")

        series = get_spot_series_id(
            maturity=maturity,
            category=query.category.split(","),
        )

        data = []

        for s in series:
            id_ = s["FRED Series ID"]
            title = s["Title"]
            d = fred.get_series(
                series_id=id_,
                start_date=query.start_date,
                end_date=query.end_date,
                **kwargs,
            )
            for item in d:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Fix the provider condition to 'if any(m < 1 or m > 100 for m in maturity)' (or 'not 1 <= m <= 100').
  2. Until patched, validate maturities client-side before calling the endpoint.
  3. File/track an upstream issue on the OpenBB repo referencing openbb_fred/models/spot.py:78.

Example fix

# before (openbb_fred/models/spot.py:78) - condition can never be true
if any(1 > m > 100 for m in maturity):
    raise OpenBBError("Maturity must be between 1 and 100")

# after
if any(m < 1 or m > 100 for m in maturity):
    raise OpenBBError("Maturity must be between 1 and 100")
Defensive patterns

Strategy: validation

Validate before calling

def validate_maturities(maturity: int | float | str) -> list[float]:
    ms = [float(m) for m in str(maturity).split(',')] if isinstance(maturity, str) else [float(maturity)]
    bad = [m for m in ms if not (1 <= m <= 100)]
    if bad:
        raise ValueError(f'Maturity out of range [1, 100]: {bad}')
    return ms

validate_maturities(maturity)  # call BEFORE obb.economy.fred.spot(...)

Type guard

def is_valid_maturity(m: object) -> bool:
    """True when m is a number in the FRED spot-rate maturity range [1, 100]."""
    return isinstance(m, (int, float)) and not isinstance(m, bool) and 1 <= m <= 100

Prevention

When it happens

Trigger: Passing maturity=0, maturity=150, or a comma list like '2,120' - the intended triggers, but due to the chained-comparison bug the error is NOT raised; the observable symptom becomes an empty result or empty-data error from the downstream series lookup, not this message.

Common situations: Porting UIs that let users type arbitrary tenors; unit tests asserting this message fires for maturity=200 and mysteriously failing; code review flags after upgrading Python versions where chained comparisons behave identically (they always did - the bug is logical).

Related errors


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