{"record":{"id":"2e6f1df044d3af39","repo":"PrefectHQ/fastmcp","slug":"expected-integer-got-raw-r","errorCode":null,"errorMessage":"Expected integer, got {raw!r}","messagePattern":"Expected integer, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/cli/client.py","lineNumber":273,"sourceCode":"        elicitation_handler=_terminal_elicitation_handler,\n    )\n\n\n# ---------------------------------------------------------------------------\n# Argument coercion\n# ---------------------------------------------------------------------------\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:","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/cli/client.py#L255-L291","documentation":"coerce_value converts CLI/elicitation string input into JSON-schema-typed values for the fastmcp client tool calls. When the schema declares type integer and Python's int() cannot parse the raw string, it raises ValueError naming the offending raw value. Note int() accepts float-like strings ('3.0') but not arbitrary text.","triggerScenarios":"Calling a tool whose parameter schema is integer and supplying a non-integer string, e.g. 'abc', '' or '1.5', via parse_tool_arguments or an interactive terminal elicitation prompt.","commonSituations":"Typo'd or pasted input at the interactive prompt; shell arguments passed as unquoted text; scripts feeding raw user data straight into client tool calls.","solutions":["Pass a valid integer string (e.g. 42, -7) for integer-typed arguments","Quote and verify values in shell invocations of the CLI client","Pre-validate/convert input in scripts before calling parse_tool_arguments"],"exampleFix":"# before\nfastmcp client call my_tool --count abc\n# after\nfastmcp client call my_tool --count 42","handlingStrategy":"validation","validationCode":"def is_integer_str(raw: str) -> bool:\n    try:\n        int(raw); return True\n    except ValueError:\n        return False","typeGuard":"def coerce_int(raw: str) -> int | None:\n    try:\n        return int(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 an integer')\n    raw = input('> ')","preventionTips":["Validate/convert CLI input with int() before passing it","Quote shell arguments and avoid locale-formatted digits","Prompt with an explicit example of the expected format"],"tags":["validation","cli","input-parsing","integer"],"backgroundTag":"input-type-mismatch","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}