HKUDS/Vibe-Trading · error · ValueError

end_date must be YYYY-MM-DD

Error message

end_date must be YYYY-MM-DD

What it means

Companion check to the start_date validation: end_date must also parse strictly as YYYY-MM-DD before any run artifacts are written.

Source

Thrown at agent/src/tools/autopilot_tool.py:245

        return candidate, None
    if candidate in VALID_SOURCES:
        return candidate, None
    return "auto", (
        f"hypothesis data_source {candidate!r} is not a known loader source; "
        "fell back to 'auto'"
    )


def _validate_backtest_dates(start_date: str, end_date: str) -> None:
    """Validate backtest dates before writing any run artifacts."""
    try:
        start = datetime.strptime(start_date, "%Y-%m-%d").date()
    except ValueError as exc:
        raise ValueError("start_date must be YYYY-MM-DD") from exc
    try:
        end = datetime.strptime(end_date, "%Y-%m-%d").date()
    except ValueError as exc:
        raise ValueError("end_date must be YYYY-MM-DD") from exc
    if start > end:
        raise ValueError("start_date must be on or before end_date")


def _run_dir_for_hypothesis(hypothesis_id: str) -> Path:
    """Return a path-contained run directory for any persisted hypothesis id."""
    suffix = hashlib.sha256(hypothesis_id.encode("utf-8")).hexdigest()[:12]
    return Path.home() / ".vibe-trading" / "runs" / f"autopilot_{suffix}"


class GenerateBacktestConfigTool(BaseTool):
    """Generate backtest config.json from a research hypothesis.

    Reads a hypothesis, derives config fields from its universe and
    data_sources, and writes a ready-to-run config.json to a run directory.
    The agent should then create signal_engine.py from the signal_definition
    and call the backtest tool.
    """

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Convert to YYYY-MM-DD with strftime('%Y-%m-%d')
  2. Parse flexible input with dateutil then re-format to ISO
  3. Validate both dates with one shared helper before invoking execute

Example fix

// before
execute(end_date='31-12-2023', ...)
// after
execute(end_date='2023-12-31', ...)
Defensive patterns

Strategy: validation

Validate before calling

assert re.fullmatch(r'\d{4}-\d{2}-\d{2}', end_date), 'end_date must be YYYY-MM-DD'

Type guard

def is_iso_end_date(s: str) -> bool:
    import re
    return bool(re.fullmatch(r'\d{4}-\d{2}-\d{2}', s or ''))

Try / catch

try:
    _validate_backtest_dates(start_date, end_date)
except ValueError as e:
    if 'end_date must be' in str(e):
        end_date = normalize_date(end_date)

Prevention

When it happens

Trigger: Calling autopilot execute with end_date in any non-ISO format — 'Dec 31 2023', '31-12-2023', '2023/12/31', or with time/timezone suffixes.

Common situations: Mixed-format date pairs (one valid, one not); user-typed dates; downstream systems returning RFC 3339 timestamps.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/0706567080319c28. Report an issue: GitHub.