OpenBB-finance/OpenBB · warning · ValueError

Requested end_date '{end_date}' is before the earliest avail

Error message

Requested end_date '{end_date}' is before the earliest available data '{time_start}'. Available date range: {time_start} to {time_end}

What it means

Companion to 630: build_url raises ValueError when end_date <= time_start, i.e. the entire requested window precedes the earliest observation the dataflow publishes. The message includes the actual available range.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/utils/query_builder.py:294

                            for annotation in constraint.get("annotations", []):
                                ann_id = annotation.get("id", "")
                                ann_title = annotation.get("title", "")
                                if ann_id == "time_period_start":
                                    time_start = ann_title
                                elif ann_id == "time_period_end":
                                    time_end = ann_title

                    if time_start and time_end:
                        # Use >= because time_end represents the END of the last period
                        # e.g., time_end=2025-01-01 means data up to end of 2024
                        # So start_date=2025-01-01 would be requesting data AFTER the available range
                        if start_date and start_date >= time_end:
                            raise ValueError(
                                f"Requested start_date '{start_date}' is after the latest available data '{time_end}'. "
                                f"Available date range: {time_start} to {time_end}"
                            )
                        if end_date and end_date <= time_start:
                            raise ValueError(
                                f"Requested end_date '{end_date}' is before the earliest available data '{time_start}'. "
                                f"Available date range: {time_start} to {time_end}"
                            )

        except KeyError as e:
            # Dataflow not found or other metadata issue - let it pass through
            warnings.warn(
                f"Could not validate constraints for dataflow '{dataflow}': {e}",
                OpenBBWarning,
            )

    def fetch_data(
        self,
        dataflow: str,
        start_date: str | None = None,
        end_date: str | None = None,
        limit: int | None = None,
        _skip_validation: bool = False,

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Move end_date after the time_start in the message, or drop end_date entirely.
  2. Confirm the series' start date on the IMF catalog.
  3. Skip the call for dataflows whose history does not intersect your required window.

Example fix

# before
url = qb.build_url('DATAFLOW', end_date='1990-12-31')  # data starts 2000

# after
url = qb.build_url('DATAFLOW', end_date='2025-12-31')
Defensive patterns

Strategy: validation

Validate before calling

def clamp_end_date(qb, dataflow: str, end_date: str) -> str:
    rng = get_time_period_range(qb, dataflow)
    if rng and end_date <= rng[0]:
        return rng[1]
    return end_date

Try / catch

try:
    url = qb.build_url(dataflow, end_date=end_date)
except ValueError as e:
    m = re.search(r'range: (.+) to (.+)', str(e))
    if m and 'before the earliest' in str(e):
        url = qb.build_url(dataflow, end_date=m.group(2))
    else:
        raise

Prevention

When it happens

Trigger: Requesting end_date='1990-12-31' for a dataflow whose data starts in 2000; backfill jobs targeting periods before the series existed.

Common situations: Uniform corporate history windows (e.g. 1970+) applied to every dataset, or new dataflows with short histories.

Related errors


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