{"record":{"id":"045d8870c01b56f7","repo":"sansan0/TrendRadar","slug":"date-range-json","errorCode":null,"errorMessage":"date_range 必须是字典类型、日期字符串或有效的JSON字符串","messagePattern":"date_range 必须是字典类型、日期字符串或有效的JSON字符串","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":429,"sourceCode":"                    dr = result[\"date_range\"]\n                    start_date = datetime.strptime(dr[\"start\"], \"%Y-%m-%d\")\n                    end_date = datetime.strptime(dr[\"end\"], \"%Y-%m-%d\")\n                    return (start_date, end_date)\n                else:\n                    raise InvalidParameterError(\n                        f\"无法识别的日期表达式: {stripped}\",\n                        suggestion=\"支持格式: YYYY-MM-DD, {\\\"start\\\": \\\"...\\\", \\\"end\\\": \\\"...\\\"}, 或自然语言（今天、本周、最近7天等）\"\n                    )\n            except InvalidParameterError:\n                raise\n            except Exception:\n                raise InvalidParameterError(\n                    f\"日期解析失败: {stripped}\",\n                    suggestion=\"支持格式: YYYY-MM-DD, {\\\"start\\\": \\\"...\\\", \\\"end\\\": \\\"...\\\"}, 或自然语言（今天、本周、最近7天等）\"\n                )\n\n    if not isinstance(date_range, dict):\n        raise InvalidParameterError(\n            \"date_range 必须是字典类型、日期字符串或有效的JSON字符串\",\n            suggestion='例如: {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"} 或 \"2025-10-01\"'\n        )\n\n    start_str = date_range.get(\"start\")\n    end_str = date_range.get(\"end\")\n\n    if not start_str or not end_str:\n        raise InvalidParameterError(\n            \"date_range 必须包含 start 和 end 字段\",\n            suggestion='例如: {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"}'\n        )\n\n    start_date = validate_date(start_str)\n    end_date = validate_date(end_str)\n\n    if start_date > end_date:\n        raise InvalidParameterError(","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L411-L447","documentation":"Raised by normalize_date_range when the input is not None, not a str (all string branches handled above), and not a dict — e.g. a list, int, or bool passed as date_range. The accepted types are strictly: None, str (ISO/JSON/natural language), or dict with start/end.","triggerScenarios":"Passing date_range: [\"2025-10-01\", \"2025-10-11\"] (array of two dates — a common convention), 20251011 (int), or true. LLMs or wrappers guessing the parameter is an array hit this immediately.","commonSituations":"Clients assuming tuple/array date ranges from other APIs; spreadsheet-derived arguments; schema-agnostic LLM tool calls that guess the shape.","solutions":["Use {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"} instead of an array","For a single day, pass the bare \"2025-10-01\" string","Omit date_range entirely if the tool works without it (None is accepted)","Check the tool's input schema and match the object property names exactly"],"exampleFix":"// before\n{\"date_range\": [\"2025-10-01\", \"2025-10-11\"]}\n// after\n{\"date_range\": {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"}}","handlingStrategy":"type-guard","validationCode":"if (Array.isArray(dateRange) && dateRange.length === 2) {\n  dateRange = { start: dateRange[0], end: dateRange[1] };\n} else if (typeof dateRange !== 'object' || dateRange === null) {\n  dateRange = undefined;\n}","typeGuard":"function isDateRangeInput(v: unknown): v is { start: string; end: string } | string {\n  return typeof v === 'string' ||\n    (typeof v === 'object' && v !== null && !Array.isArray(v) && 'start' in v && 'end' in v);\n}","tryCatchPattern":"try { call({ date_range }); }\ncatch (e) {\n  if (/必须是字典类型/.test(e.message)) call({ date_range: { start, end } });\n  else throw e;\n}","preventionTips":["Never send arrays, numbers, or booleans for date_range","Convert [from, to] tuples to {start, end} at your adapter layer","Generate client bindings from the tool's JSON schema"],"tags":["date-range","type-validation","json"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}