sansan0/TrendRadar · warning · InvalidParameterError

日期查询字符串不能为空

Error message

日期查询字符串不能为空

What it means

Raised by validate_date_query when the date query argument is empty (empty string or equivalent falsy value). The validator accepts natural-language Chinese dates ('今天', '昨天') and standard date strings ('2025-10-10'); before any parsing it requires a non-empty query.

Source

Thrown at mcp_server/utils/validators.py:654

    Args:
        date_query: 日期查询字符串
        allow_future: 是否允许未来日期
        max_days_ago: 允许查询的最大天数

    Returns:
        解析后的datetime对象

    Raises:
        InvalidParameterError: 日期查询无效

    Examples:
        >>> validate_date_query("昨天")
        datetime(2025, 10, 10)
        >>> validate_date_query("2025-10-10")
        datetime(2025, 10, 10)
    """
    if not date_query:
        raise InvalidParameterError(
            "日期查询字符串不能为空",
            suggestion="请提供日期查询,如:今天、昨天、2025-10-10"
        )

    # 使用DateParser解析日期
    parsed_date = DateParser.parse_date_query(date_query)

    # 验证日期不在未来
    if not allow_future:
        DateParser.validate_date_not_future(parsed_date)

    # 验证日期不太久远
    DateParser.validate_date_not_too_old(parsed_date, max_days=max_days_ago)

    return parsed_date

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Provide a concrete query: natural language ('昨天') or a date string ('2025-10-10').
  2. If the filter is optional on your side, omit the parameter entirely instead of sending an empty string.
  3. In client wrappers, convert empty user input into parameter omission.

Example fix

# before
tool_call(date_query="")

# after
tool_call(date_query="昨天")
# or omit date_query entirely if not needed
Defensive patterns

Strategy: validation

Validate before calling

if not date_query or not date_query.strip():
    # omit the filter entirely rather than sending ""
    tool_call(...)
else:
    tool_call(date_query=date_query.strip())

Type guard

def is_nonempty_date_query(v) -> bool:
    return isinstance(v, str) and bool(v.strip())

Try / catch

try:
    tool_call(date_query=q)
except InvalidParameterError as e:
    if "不能为空" in str(e):
        tool_call()  # retry without the date filter

Prevention

When it happens

Trigger: Calling a date-filtered MCP tool with date_query="", date_query=None-like empty string, or omitting the value in a way that the client fills with "".

Common situations: An MCP client builds a date filter from an optional template variable that resolves to empty; LLM tool-call omits the argument and a wrapper substitutes "" instead of dropping the parameter.

Related errors


AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15). Data as JSON: /api/errors/96be755e44a2e7ed. Report an issue: GitHub.