sansan0/TrendRadar · error · InvalidParameterError

keyword 不能为空

Error message

keyword 不能为空

What it means

Raised by validate_keyword on the very first check: if not keyword. This catches None and '' (empty string) before any type or content checks. A keyword search requires a non-empty term; there is no 'match all' via empty keyword.

Source

Thrown at mcp_server/utils/validators.py:496

    return (start_date, end_date)


def validate_keyword(keyword: str) -> str:
    """
    验证关键词

    Args:
        keyword: 搜索关键词

    Returns:
        处理后的关键词

    Raises:
        InvalidParameterError: 关键词无效
    """
    if not keyword:
        raise InvalidParameterError("keyword 不能为空")

    if not isinstance(keyword, str):
        raise InvalidParameterError("keyword 必须是字符串类型")

    keyword = keyword.strip()

    if not keyword:
        raise InvalidParameterError("keyword 不能为空白字符")

    if len(keyword) > 100:
        raise InvalidParameterError(
            "keyword 长度不能超过100个字符",
            suggestion="请使用更简洁的关键词"
        )

    return keyword

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Require the user/LLM to provide an actual term before calling; skip the call if keyword is empty
  2. Default to a meaningful term or use a list-all tool (if available) instead of empty-keyword search
  3. Guard client-side: if (!keyword?.trim()) return early
  4. If the field is genuinely optional in your flow, check the tool schema — keyword here is mandatory

Example fix

// before
tool.search({ keyword: "" })
// after
if (!keyword || !keyword.trim()) throw new Error("keyword required");
tool.search({ keyword })
Defensive patterns

Strategy: validation

Validate before calling

if (keyword == null || keyword === '') {
  throw new Error('keyword is required'); // or skip the call
}

Type guard

const isNonEmptyKeyword = (v: unknown): v is string => typeof v === 'string' && v.length > 0;

Try / catch

try { call({ keyword }); }
catch (e) {
  if (/keyword 不能为空/.test(e.message)) { /* prompt user, do not blind-retry */ throw e; }
  else throw e;
}

Prevention

When it happens

Trigger: Calling a search tool with keyword: "" or keyword: null; optional search fields forwarded verbatim when the user typed nothing; destructured objects with missing keyword key (undefined → None at the Python boundary).

Common situations: Forms submitted with empty search box; pipelines passing an empty default ''; LLM omitting the argument where the schema marked it required; conditional expressions collapsing to empty string.

Related errors


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