OpenBB-finance/OpenBB · warning · ValueError

Requested start_date '{start_date}' is after the latest avai

Error message

Requested start_date '{start_date}' is after the latest available data '{time_end}'. Available date range: {time_start} to {time_end}

What it means

build_url validates requested dates against the dataflow's TIME_PERIOD content constraints (annotations time_period_start/time_period_end). If start_date >= time_end (end is exclusive-ish: it marks the end of the last period), the request is entirely outside available data and ValueError is raised with the true range.

Source

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

                    # Fall back to dataConstraints if not found
                    if not (time_start and time_end):
                        data_constraints = data.get("dataConstraints", [])
                        for constraint in data_constraints:
                            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,

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Set start_date to (or before) the time_end shown in the message, or omit start_date.
  2. For 'latest data' semantics, request a generous historical window and take the last rows of the result.
  3. Check the dataflow's coverage on the IMF data catalog page before hardcoding dates.

Example fix

# before
url = qb.build_url('DATAFLOW', start_date='2025-01-01')  # range ends 2025-01-01

# after
url = qb.build_url('DATAFLOW', start_date='2000-01-01')  # covers all available history
Defensive patterns

Strategy: validation

Validate before calling

def clamp_start_date(qb, dataflow: str, start_date: str) -> str:
    rng = get_time_period_range(qb, dataflow)  # from time_period_* annotations
    if rng and start_date >= rng[1]:
        return rng[0]
    return start_date

Try / catch

try:
    url = qb.build_url(dataflow, start_date=start_date)
except ValueError as e:
    m = re.search(r'range: (.+) to (.+)', str(e))
    if m and 'after the latest' in str(e):
        url = qb.build_url(dataflow, start_date=m.group(1))
    else:
        raise

Prevention

When it happens

Trigger: Asking for start_date='2025-01-01' when the dataflow's latest available period ends 2025-01-01 (i.e. data through 2024), or any start beyond the published time_end.

Common situations: Assuming data is more current than IMF has published; hardcoded 'current year' scripts in January before annual data lands; lagging quarterly releases.

Related errors


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