sansan0/TrendRadar · error · InvalidParameterError
date_range 必须是字典类型、日期字符串或有效的JSON字符串
Error message
date_range 必须是字典类型、日期字符串或有效的JSON字符串
What it means
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.
Source
Thrown at mcp_server/utils/validators.py:429
dr = result["date_range"]
start_date = datetime.strptime(dr["start"], "%Y-%m-%d")
end_date = datetime.strptime(dr["end"], "%Y-%m-%d")
return (start_date, end_date)
else:
raise InvalidParameterError(
f"无法识别的日期表达式: {stripped}",
suggestion="支持格式: YYYY-MM-DD, {\"start\": \"...\", \"end\": \"...\"}, 或自然语言(今天、本周、最近7天等)"
)
except InvalidParameterError:
raise
except Exception:
raise InvalidParameterError(
f"日期解析失败: {stripped}",
suggestion="支持格式: YYYY-MM-DD, {\"start\": \"...\", \"end\": \"...\"}, 或自然语言(今天、本周、最近7天等)"
)
if not isinstance(date_range, dict):
raise InvalidParameterError(
"date_range 必须是字典类型、日期字符串或有效的JSON字符串",
suggestion='例如: {"start": "2025-10-01", "end": "2025-10-11"} 或 "2025-10-01"'
)
start_str = date_range.get("start")
end_str = date_range.get("end")
if not start_str or not end_str:
raise InvalidParameterError(
"date_range 必须包含 start 和 end 字段",
suggestion='例如: {"start": "2025-10-01", "end": "2025-10-11"}'
)
start_date = validate_date(start_str)
end_date = validate_date(end_str)
if start_date > end_date:
raise InvalidParameterError(View on GitHub (pinned to 8ee26026ba)
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
Example fix
// before
{"date_range": ["2025-10-01", "2025-10-11"]}
// after
{"date_range": {"start": "2025-10-01", "end": "2025-10-11"}} Defensive patterns
Strategy: type-guard
Validate before calling
if (Array.isArray(dateRange) && dateRange.length === 2) {
dateRange = { start: dateRange[0], end: dateRange[1] };
} else if (typeof dateRange !== 'object' || dateRange === null) {
dateRange = undefined;
} Type guard
function isDateRangeInput(v: unknown): v is { start: string; end: string } | string {
return typeof v === 'string' ||
(typeof v === 'object' && v !== null && !Array.isArray(v) && 'start' in v && 'end' in v);
} Try / catch
try { call({ date_range }); }
catch (e) {
if (/必须是字典类型/.test(e.message)) call({ date_range: { start, end } });
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Clients assuming tuple/array date ranges from other APIs; spreadsheet-derived arguments; schema-agnostic LLM tool calls that guess the shape.
Related errors
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/045d8870c01b56f7.
Report an issue: GitHub.