HKUDS/Vibe-Trading · error · ValueError
invalid date: {date!r}; expected YYYY-MM-DD
Error message
invalid date: {date!r}; expected YYYY-MM-DD What it means
The `date` argument must reduce to exactly 8 digits (optionally with dashes), i.e. YYYY-MM-DD or YYYYMMDD. After stripping dashes the string must be 8 characters of digits; otherwise the tool refuses to normalize it to the canonical dashed form.
Source
Thrown at agent/src/tools/dragon_tiger_tool.py:53
def _compact_date(date: str) -> str:
"""Normalize a ``YYYY-MM-DD`` (or already-compact) date for the API filter.
Args:
date: A trade date such as ``"2024-01-02"`` or ``"20240102"``.
Returns:
The date in dashed ``YYYY-MM-DD`` form expected by the datacenter
``TRADE_DATE`` filter.
Raises:
ValueError: The string is not a recognizable 8-digit / dashed date.
"""
cleaned = date.strip()
digits = cleaned.replace("-", "")
if len(digits) != 8 or not digits.isdigit():
raise ValueError(f"invalid date: {date!r}; expected YYYY-MM-DD")
return f"{digits[:4]}-{digits[4:6]}-{digits[6:]}"
def _bare_code(code: str) -> str:
"""Strip any exchange suffix to the bare numeric A-share code.
Args:
code: A symbol such as ``"600519.SH"``, ``"000001.SZ"`` or ``"600519"``.
Returns:
The leading numeric code (e.g. ``"600519"``).
"""
return code.strip().upper().split(".", 1)[0]
def _fetch_report(
report_name: str, *, filter_expr: str, sort_columns: str, sort_types: str
) -> list[dict[str, Any]]:View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass a full 4-digit-year date as 'YYYY-MM-DD' or 'YYYYMMDD'
- If sourcing from datetime objects, format with strftime('%Y-%m-%d') before calling
Example fix
# before execute(date="2024/01/05") # after execute(date="2024-01-05")
Defensive patterns
Strategy: validation
Validate before calling
import re
def valid_date(s: str) -> bool:
d = s.strip().replace("-", "")
return len(d) == 8 and d.isdigit() Type guard
from datetime import date as _d
def to_iso_date(v) -> str:
if isinstance(v, _d):
return v.strftime("%Y-%m-%d")
s = str(v).strip().replace("/", "-")
if not valid_date(s):
raise ValueError(v)
d = s.replace("-", "")
return f"{d[:4]}-{d[4:6]}-{d[6:]}" Try / catch
try:
execute(date=date_str)
except ValueError as exc:
if "invalid date" in str(exc):
from datetime import datetime
execute(date=datetime.strptime(date_str[:10].replace("/", "-"), "%Y-%m-%d").strftime("%Y-%m-%d"))
else:
raise Prevention
- Always format dates with strftime('%Y-%m-%d') at the source
- Convert slashes to dashes and strip time components before passing
- Reject 2-digit years during input normalization
When it happens
Trigger: Passing date='2024-1-5' (only 6 digits), '2024/01/05' (slash separators leave non-digits), '24-01-05' (6 digits), or '2024-01-05extra'.
Common situations: Dates copied from localized UIs using slashes; two-digit years; trailing whitespace is tolerated but embedded junk is not; LLM agents emitting ISO with time suffixes.
Related errors
- alpha_id not found
- invalid alpha_id
- invalid period: {exc}
- too many running benches; wait for one to finish
- invalid job_id
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/81e370740f44d9b7.
Report an issue: GitHub.