{"record":{"id":"6dadd133892a4bff","repo":"sansan0/TrendRadar","slug":"param-name-min-value-max-value","errorCode":null,"errorMessage":"{param_name} 必须在 {min_value} 到 {max_value} 之间，当前值: {threshold}","messagePattern":"(.+?) 必须在 (.+?) 到 (.+?) 之间，当前值: (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"warning","filePath":"mcp_server/utils/validators.py","lineNumber":620,"sourceCode":"    if threshold is None:\n        return default\n\n    # 支持字符串形式的数字（某些 MCP 客户端会将数字序列化为字符串）\n    if isinstance(threshold, str):\n        threshold = _parse_string_to_float(threshold, param_name)\n\n    # 整数转浮点数\n    if isinstance(threshold, int):\n        threshold = float(threshold)\n\n    if not isinstance(threshold, float):\n        raise InvalidParameterError(\n            f\"{param_name} 必须是数字类型\",\n            suggestion=f\"请提供 {min_value} 到 {max_value} 之间的数字\"\n        )\n\n    if threshold < min_value or threshold > max_value:\n        raise InvalidParameterError(\n            f\"{param_name} 必须在 {min_value} 到 {max_value} 之间，当前值: {threshold}\",\n            suggestion=f\"推荐值: {default}\"\n        )\n\n    return threshold\n\n\ndef validate_date_query(\n    date_query: str,\n    allow_future: bool = False,\n    max_days_ago: int = 365\n) -> datetime:\n    \"\"\"\n    验证并解析日期查询字符串\n\n    Args:\n        date_query: 日期查询字符串\n        allow_future: 是否允许未来日期","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L602-L638","documentation":"Raised by the threshold validator when the value is numeric but outside [min_value, max_value]. This is a range check after type coercion succeeded (int→float, numeric string→float). The message shows the offending value and suggests the recommended default.","triggerScenarios":"Passing threshold=5.0 when the parameter is bounded to 0.0–1.0; passing a percentage (80) where a fraction (0.8) is expected; negative values for a positive-only parameter.","commonSituations":"Unit confusion (percent vs fraction) is the most common cause — the API expects 0.8 but the user sends 80. Also copying a value tuned for one parameter into another with a different range.","solutions":["Rescale the value into [min_value, max_value] as shown in the message (e.g. 80 → 0.8).","Pass null/omit the parameter to accept the recommended default.","Check the tool's parameter schema or docstring for the documented bounds before choosing a value."],"exampleFix":"# before\nthreshold = 80  # percent, out of 0.0-1.0 range\n\n# after\nthreshold = 0.8  # fraction within range","handlingStrategy":"validation","validationCode":"def clamp_threshold(v, lo, hi, default):\n    if v is None:\n        return default\n    v = float(v)\n    return max(lo, min(hi, v))  # or reject instead of clamping\ntool_call(threshold=clamp_threshold(t, 0.0, 1.0, 0.8))","typeGuard":"def in_range(v, lo, hi) -> bool:\n    return v is not None and isinstance(v, (int, float)) and lo <= v <= hi","tryCatchPattern":"try:\n    tool_call(threshold=t)\nexcept InvalidParameterError as e:\n    if \"之间\" in str(e):\n        t = 0.8  # recommended default from suggestion\n        tool_call(threshold=t)","preventionTips":["Read the tool schema's minimum/maximum before choosing threshold values.","Standardize on fractions (0-1) in your client; never send percentages."],"tags":["validation","mcp","range","numeric"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}