sansan0/TrendRadar · error · InvalidParameterError

{param_name} 必须是数字,无法解析: {value}

Error message

{param_name} 必须是数字,无法解析: {value}

What it means

Raised by _parse_string_to_float when a string cannot be parsed as a float. It applies float(value) after a strip(); Python float() accepts scientific notation and inf/nan, so this fires only for genuinely non-numeric text. param_name identifies which numeric parameter (e.g. a threshold like min_score) failed.

Source

Thrown at mcp_server/utils/validators.py:124

    """
    将字符串解析为浮点数

    Args:
        value: 字符串值
        param_name: 参数名(用于错误消息)

    Returns:
        解析后的浮点数

    Raises:
        InvalidParameterError: 解析失败
    """
    value = value.strip()

    try:
        return float(value)
    except ValueError:
        raise InvalidParameterError(
            f"{param_name} 必须是数字,无法解析: {value}",
            suggestion=f"请提供有效的数字值,如: 0.6, 3.0"
        )


def _parse_string_to_bool(value: str) -> bool:
    """
    将字符串解析为布尔值

    Args:
        value: 字符串值

    Returns:
        解析后的布尔值
    """
    value = value.strip().lower()

    if value in ('true', '1', 'yes', 'on'):

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Send a plain decimal number: 0.6 or "0.6" (dot as decimal separator)
  2. Remove units, percent signs, and comparison operators before sending; convert 60% to 0.6 yourself
  3. Use null/omit for empty optional numeric fields rather than ""
  4. Catch InvalidParameterError and re-ask the user/LLM for a bare number

Example fix

// before
{"min_score": "0,6"}
// after
{"min_score": 0.6}
Defensive patterns

Strategy: validation

Validate before calling

function toFloat(v: unknown): number {
  const n = Number(String(v).trim().replace(',', '.')); // locale comma -> dot
  if (!Number.isFinite(n)) throw new Error('not numeric');
  return n;
}

Type guard

const isFloatLike = (v: unknown): boolean =>
  typeof v === 'number' || /^-?\d+(?:\.\d+)?$/.test(String(v).trim());

Try / catch

try { call({ min_score: s }); }
catch (e) {
  if (/必须是数字/.test(e.message)) s = 0.6; // default and retry once
  else throw e;
}

Prevention

When it happens

Trigger: Passing a fractional parameter as "high", "0,6" (comma decimal separator), "60%", or "<0.6". Any float-typed tool argument serialized as a string with formatting or units attached.

Common situations: European locale decimal commas; LLM-generated values with units or comparison operators; percent signs copied from UI; empty strings from optional fields.

Related errors


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