PrefectHQ/fastmcp · error · ValueError

Expected boolean, got {raw!r}

Error message

Expected boolean, got {raw!r}

What it means

For boolean schema types, coerce_value accepts only true/1/yes and false/0/no (case-insensitive); anything else raises this ValueError with the raw value. Unlike the integer/number branches there is no leniency — e.g. 'on' or 'True ' with trailing whitespace fails.

Source

Thrown at fastmcp_slim/fastmcp/cli/client.py:286

    if schema_type == "integer":
        try:
            return int(raw)
        except ValueError:
            raise ValueError(f"Expected integer, got {raw!r}") from None

    if schema_type == "number":
        try:
            return float(raw)
        except ValueError:
            raise ValueError(f"Expected number, got {raw!r}") from None

    if schema_type == "boolean":
        if raw.lower() in ("true", "1", "yes"):
            return True
        if raw.lower() in ("false", "0", "no"):
            return False
        raise ValueError(f"Expected boolean, got {raw!r}")

    if schema_type in ("array", "object"):
        try:
            return json.loads(raw)
        except json.JSONDecodeError:
            raise ValueError(f"Expected JSON {schema_type}, got {raw!r}") from None

    # Default: treat as string
    return raw


def parse_tool_arguments(
    raw_args: tuple[str, ...],
    input_json: str | None,
    input_schema: dict[str, Any],
) -> dict[str, Any]:
    """Build a tool-call argument dict from CLI inputs.

View on GitHub (pinned to 1f02114297)

Solutions

  1. Use one of the accepted spellings: true/false, 1/0, or yes/no
  2. Trim whitespace from scripted input before passing it
  3. Normalize booleans in your own code with a small parse helper before invoking the CLI

Example fix

# before
--enabled on   # ValueError
# after
--enabled true
Defensive patterns

Strategy: validation

Validate before calling

def is_bool_str(raw: str) -> bool:
    return raw.strip().lower() in {'true', '1', 'yes', 'false', '0', 'no'}

Type guard

def coerce_bool(raw: str) -> bool | None:
    r = raw.strip().lower()
    if r in ('true', '1', 'yes'):
        return True
    if r in ('false', '0', 'no'):
        return False
    return None

Try / catch

try:
    value = coerce_value(schema, raw)
except ValueError as exc:
    print(f'Invalid input: {exc}; expected true/false, 1/0, or yes/no')
    raw = input('> ')

Prevention

When it happens

Trigger: Answering a boolean elicitation prompt or passing a boolean tool argument with a string outside {true,1,yes,false,0,no}.

Common situations: Using 'on'/'off', 'y'/'n', or values with trailing whitespace at the CLI prompt; scripting prompts with unexpected values.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/1fdc0831adf69e24. Report an issue: GitHub.