{"record":{"id":"3d33a2b5329419b8","repo":"PrefectHQ/fastmcp","slug":"expected-number-got-raw-r","errorCode":null,"errorMessage":"Expected number, got {raw!r}","messagePattern":"Expected number, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/cli/client.py","lineNumber":279,"sourceCode":"# ---------------------------------------------------------------------------\n\n\ndef coerce_value(raw: str, schema: dict[str, Any]) -> Any:\n    \"\"\"Coerce a string CLI value according to a JSON-Schema type hint.\"\"\"\n\n    schema_type = schema.get(\"type\", \"string\")\n\n    if schema_type == \"integer\":\n        try:\n            return int(raw)\n        except ValueError:\n            raise ValueError(f\"Expected integer, got {raw!r}\") from None\n\n    if schema_type == \"number\":\n        try:\n            return float(raw)\n        except ValueError:\n            raise ValueError(f\"Expected number, got {raw!r}\") from None\n\n    if schema_type == \"boolean\":\n        if raw.lower() in (\"true\", \"1\", \"yes\"):\n            return True\n        if raw.lower() in (\"false\", \"0\", \"no\"):\n            return False\n        raise ValueError(f\"Expected boolean, got {raw!r}\")\n\n    if schema_type in (\"array\", \"object\"):\n        try:\n            return json.loads(raw)\n        except json.JSONDecodeError:\n            raise ValueError(f\"Expected JSON {schema_type}, got {raw!r}\") from None\n\n    # Default: treat as string\n    return raw\n\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/cli/client.py#L261-L297","documentation":"coerce_value handles schema type number by calling float(raw); on ValueError it raises this message including the raw input. Float parsing is stricter than the integer branch — '1.5' works but 'abc', empty strings, or locale-formatted numbers ('1,5') fail.","triggerScenarios":"Supplying a non-numeric string for a number-typed tool parameter via parse_tool_arguments or the terminal elicitation handler.","commonSituations":"Locale decimal commas from international users; unit-suffixed input like '3.5kg'; empty prompt submissions.","solutions":["Provide a plain numeric string such as 3.14 or -0.5","Strip units/formatting from input before passing it","Pre-convert with float() in scripts to fail early with your own message"],"exampleFix":"# before\n--price '3,50'   # ValueError\n# after\n--price 3.50","handlingStrategy":"validation","validationCode":"def is_number_str(raw: str) -> bool:\n    try:\n        float(raw); return True\n    except ValueError:\n        return False","typeGuard":"def coerce_float(raw: str) -> float | None:\n    try:\n        return float(raw)\n    except ValueError:\n        return None","tryCatchPattern":"try:\n    value = coerce_value(schema, raw)\nexcept ValueError as exc:\n    print(f'Invalid input: {exc}; expected a number')\n    raw = input('> ')","preventionTips":["Strip units/locale formatting (e.g. '3,5' -> 3.5) before passing numbers","Convert with float() in scripts to fail with your own message","Reject empty input at the prompt level"],"tags":["validation","cli","input-parsing","number"],"backgroundTag":"input-type-mismatch","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}