{"record":{"id":"81e370740f44d9b7","repo":"HKUDS/Vibe-Trading","slug":"invalid-date-date-r-expected-yyyy-mm-dd","errorCode":null,"errorMessage":"invalid date: {date!r}; expected YYYY-MM-DD","messagePattern":"invalid date: (.+?); expected YYYY-MM-DD","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/tools/dragon_tiger_tool.py","lineNumber":53,"sourceCode":"\n\ndef _compact_date(date: str) -> str:\n    \"\"\"Normalize a ``YYYY-MM-DD`` (or already-compact) date for the API filter.\n\n    Args:\n        date: A trade date such as ``\"2024-01-02\"`` or ``\"20240102\"``.\n\n    Returns:\n        The date in dashed ``YYYY-MM-DD`` form expected by the datacenter\n        ``TRADE_DATE`` filter.\n\n    Raises:\n        ValueError: The string is not a recognizable 8-digit / dashed date.\n    \"\"\"\n    cleaned = date.strip()\n    digits = cleaned.replace(\"-\", \"\")\n    if len(digits) != 8 or not digits.isdigit():\n        raise ValueError(f\"invalid date: {date!r}; expected YYYY-MM-DD\")\n    return f\"{digits[:4]}-{digits[4:6]}-{digits[6:]}\"\n\n\ndef _bare_code(code: str) -> str:\n    \"\"\"Strip any exchange suffix to the bare numeric A-share code.\n\n    Args:\n        code: A symbol such as ``\"600519.SH\"``, ``\"000001.SZ\"`` or ``\"600519\"``.\n\n    Returns:\n        The leading numeric code (e.g. ``\"600519\"``).\n    \"\"\"\n    return code.strip().upper().split(\".\", 1)[0]\n\n\ndef _fetch_report(\n    report_name: str, *, filter_expr: str, sort_columns: str, sort_types: str\n) -> list[dict[str, Any]]:","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/tools/dragon_tiger_tool.py#L35-L71","documentation":"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.","triggerScenarios":"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'.","commonSituations":"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.","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"],"exampleFix":"# before\nexecute(date=\"2024/01/05\")\n# after\nexecute(date=\"2024-01-05\")","handlingStrategy":"validation","validationCode":"import re\n\ndef valid_date(s: str) -> bool:\n    d = s.strip().replace(\"-\", \"\")\n    return len(d) == 8 and d.isdigit()","typeGuard":"from datetime import date as _d\n\ndef to_iso_date(v) -> str:\n    if isinstance(v, _d):\n        return v.strftime(\"%Y-%m-%d\")\n    s = str(v).strip().replace(\"/\", \"-\")\n    if not valid_date(s):\n        raise ValueError(v)\n    d = s.replace(\"-\", \"\")\n    return f\"{d[:4]}-{d[4:6]}-{d[6:]}\"","tryCatchPattern":"try:\n    execute(date=date_str)\nexcept ValueError as exc:\n    if \"invalid date\" in str(exc):\n        from datetime import datetime\n        execute(date=datetime.strptime(date_str[:10].replace(\"/\", \"-\"), \"%Y-%m-%d\").strftime(\"%Y-%m-%d\"))\n    else:\n        raise","preventionTips":["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"],"tags":["validation","date-format","python"],"backgroundTag":"invalid-date-format","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}