{"record":{"id":"a0b78e37b419cf8f","repo":"PrefectHQ/fastmcp","slug":"invalid-boolean-value-for-param-name-param-val","errorCode":null,"errorMessage":"Invalid boolean value for {param_name}: {param_value!r}","messagePattern":"Invalid boolean value for (.+?): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/resources/template.py","lineNumber":414,"sourceCode":"                param = sig.parameters[param_name]\n                annotation = param.annotation\n\n                if annotation is inspect.Parameter.empty or annotation is str:\n                    continue\n\n                try:\n                    if annotation is int:\n                        kwargs[param_name] = int(param_value)\n                    elif annotation is float:\n                        kwargs[param_name] = float(param_value)\n                    elif annotation is bool:\n                        lower = param_value.lower()\n                        if lower in (\"true\", \"1\", \"yes\"):\n                            kwargs[param_name] = True\n                        elif lower in (\"false\", \"0\", \"no\"):\n                            kwargs[param_name] = False\n                        else:\n                            raise ValueError(\n                                f\"Invalid boolean value for {param_name}: {param_value!r}\"\n                            )\n                except (ValueError, AttributeError):\n                    raise\n\n        # self.fn is wrapped by without_injected_parameters which handles\n        # dependency resolution internally, so we call it directly\n        result = self.fn(**kwargs)\n        if inspect.isawaitable(result):\n            result = await result\n\n        return result\n\n    @classmethod\n    def from_function(\n        cls,\n        fn: Callable[..., Any],\n        uri_template: str,","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/resources/template.py#L396-L432","documentation":"FunctionResourceTemplate converts URI-template path parameters into typed Python values based on annotations. When a {param} is annotated as bool and the URI segment string is not a recognized boolean literal (true/1/yes or false/0/no, case-insensitive), the conversion raises this ValueError.","triggerScenarios":"Template 'data://flag/{enabled}' with enabled: bool and a request to data://flag/maybe; URIs with unexpected segment values like 'on', 'off', 'yes!' or empty-ish strings not in the accepted lists.","commonSituations":"Client-generated URIs with free-form boolean-ish words; localized or shorthand values (Y/N, oui/non) not covered by the accepted literals.","solutions":["Use one of true/1/yes or false/0/no (any case) in the URI segment","Change the template parameter annotation to str and convert manually in the function with explicit accepted values","Validate/normalize the URI before requesting the resource"],"exampleFix":"// before\nGET data://flag/on   # {enabled: bool}\n// after\nGET data://flag/yes  # accepted: true/1/yes, false/0/no\n// or change annotation:\n@mcp.resource(\"data://flag/{enabled}\")\ndef get(enabled: str): ...","handlingStrategy":"validation","validationCode":"BOOL_WORDS = {\"true\", \"1\", \"yes\", \"false\", \"0\", \"no\"}\ndef valid_bool_param(value: str) -> bool:\n    return value.lower() in BOOL_WORDS","typeGuard":"def as_bool(value: str) -> bool | None:\n    if value.lower() in (\"true\", \"1\", \"yes\"):\n        return True\n    if value.lower() in (\"false\", \"0\", \"no\"):\n        return False\n    return None","tryCatchPattern":"try:\n    content = await template.read({\"enabled\": segment})\nexcept ValueError as e:\n    if str(e).startswith(\"Invalid boolean value\"):\n        segment = \"true\" if segment not in (\"false\", \"0\", \"no\") else \"false\"","preventionTips":["Only use annotated bool template params when clients control the URI format","Annotate ambiguous params as str and convert with explicit accepted values","Document accepted boolean literals (true/1/yes, false/0/no) for URI consumers"],"tags":["python","resource-templates","value-error","uri-parameters"],"backgroundTag":"uri-parameter-conversion-failed","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}