HKUDS/Vibe-Trading · error · ValueError
start_date must be YYYY-MM-DD
Error message
start_date must be YYYY-MM-DD
What it means
autopilot_tool validates backtest inputs before writing run artifacts; start_date must parse strictly as YYYY-MM-DD via datetime.strptime. Any other format (slashes, month names, YYYYMMDD) fails.
Source
Thrown at agent/src/tools/autopilot_tool.py:241
candidate = (data_sources or ["auto"])[0]
try:
from backtest.loaders.registry import VALID_SOURCES
except Exception: # pragma: no cover - registry import is environment-stable
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 andView on GitHub (pinned to 80ffdda44c)
Solutions
- Format dates as %Y-%m-%D strictly (date.strftime('%Y-%m-%d'))
- Normalize incoming datetimes to .date() then format
- Add a regex pre-check r'^\d{4}-\d{2}-\d{2}$' before calling the tool
Example fix
// before execute(start_date='2023/01/01', ...) // after execute(start_date='2023-01-01', ...)
Defensive patterns
Strategy: validation
Validate before calling
import re
assert re.fullmatch(r'\d{4}-\d{2}-\d{2}', start_date), 'start_date must be YYYY-MM-DD' Type guard
def is_iso_date(s: str) -> bool:
import re, datetime
if not re.fullmatch(r'\d{4}-\d{2}-\d{2}', s or ''):
return False
try:
datetime.date.fromisoformat(s); return True
except ValueError:
return False Try / catch
try:
_validate_backtest_dates(start_date, end_date)
except ValueError as e:
start_date = normalize_date(start_date); retry Prevention
- Emit dates from date objects with strftime, never from user strings
- Centralize date normalization in the API layer
When it happens
Trigger: Calling autopilot execute with start_date='2023/01/01', '01-02-2023', '20230101', or a datetime object stringified with time components.
Common situations: Frontend date pickers emitting locale formats; LLM-supplied dates in natural formats; ISO datetime strings ('2023-01-01T00:00:00') passed untrimmed.
Related errors
- end_date must be YYYY-MM-DD
- alpha_id not found
- period {period!r} must be YYYY-YYYY or YYYY-MM-DD/YYYY-MM-DD
- invalid date: {date!r}; expected YYYY-MM-DD
- invalid date for tushare fallback: {value!r}
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/f3a495309b3c75c9.
Report an issue: GitHub.