sansan0/TrendRadar · error · InvalidParameterError
日期太久远: {date.strftime('%Y-%m-%d')} ({days_ago}天前)
Error message
日期太久远: {date.strftime('%Y-%m-%d')} ({days_ago}天前) What it means
Thrown by DateParser.validate_date_not_too_old when the parsed date is more than max_days (default 365) before today. Together with the not-future check it bounds queries to a rolling one-year window that matches the data retention period.
Source
Thrown at mcp_server/utils/date_parser.py:325
f"不能查询未来的日期: {date.strftime('%Y-%m-%d')}",
suggestion="请使用今天或过去的日期"
)
@staticmethod
def validate_date_not_too_old(date: datetime, max_days: int = 365) -> None:
"""
验证日期不太久远
Args:
date: 待验证的日期
max_days: 最大天数
Raises:
InvalidParameterError: 日期太久远
"""
days_ago = (datetime.now().date() - date.date()).days
if days_ago > max_days:
raise InvalidParameterError(
f"日期太久远: {date.strftime('%Y-%m-%d')} ({days_ago}天前)",
suggestion=f"请查询{max_days}天内的数据"
)
@staticmethod
def resolve_date_range_expression(expression: str) -> Dict:
"""
将自然语言日期表达式解析为标准日期范围
这是专门为 MCP 工具设计的方法,用于在服务器端解析日期表达式,
避免 AI 模型自己计算日期导致的不一致问题。
Args:
expression: 自然语言日期表达式,支持:
- 单日: "今天", "昨天", "today", "yesterday"
- 本周/上周: "本周", "上周", "this week", "last week"
- 本月/上月: "本月", "上月", "this month", "last month"
- 最近N天: "最近7天", "最近30天", "last 7 days", "last 30 days"View on GitHub (pinned to 8ee26026ba)
Solutions
- Query dates within the last 365 days
- If you control the call and retention allows, pass a larger max_days explicitly
- Split older ranges out or accept they are outside the dataset's coverage
Example fix
# before DateParser.validate_date_not_too_old(datetime(2020, 1, 1)) # raises, default 365 # after DateParser.validate_date_not_too_old(datetime(2020, 1, 1), max_days=3650) # if retention allows # or query within the last year: DateParser.validate_date_not_too_old(datetime.now() - timedelta(days=200))
Defensive patterns
Strategy: validation
Validate before calling
from datetime import datetime, timedelta
def within_retention(d: datetime, max_days: int = 365) -> bool:
return (datetime.now().date() - d.date()).days <= max_days Type guard
def is_within_max_days(d, max_days=365) -> bool:
from datetime import datetime
return (datetime.now().date() - d.date()).days <= max_days Try / catch
try:
DateParser.validate_date_not_too_old(d)
except InvalidParameterError as e:
if "太久远" in str(e):
d = datetime.now() - timedelta(days=365) # clamp to retention window
else:
raise Prevention
- Bound query windows to the one-year retention period by default
- Pass max_days explicitly if your deployment retains more history
- Clamp old dates to the window edge instead of dropping the whole query
When it happens
Trigger: Calling the validator (directly or via a tool that enforces the window) with a date more than 365 days in the past; long-horizon historical research queries; archived dates from previous years.
Common situations: Backfill scripts targeting older data; users asking for '去年今天' near the boundary; forgetting the default max_days is 365 when the tool only stores a year.
Related errors
- INVALID_PARAMETER
- 不能查询未来的日期: {date.strftime('%Y-%m-%d')}
- 日期表达式不能为空
- 日期格式错误: {date_str}
- 日期格式错误: {stripped}
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/e2c9616b596c4ec8.
Report an issue: GitHub.