{"record":{"id":"a7727a68e24dcb6a","repo":"PrefectHQ/fastmcp","slug":"invalid-first-argument-type-name-or-fn-a7727a","errorCode":null,"errorMessage":"Invalid first argument: {type(name_or_fn)}","messagePattern":"Invalid first argument: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py","lineNumber":215,"sourceCode":"            target = fn.__func__ if hasattr(fn, \"__func__\") else fn\n            target.__fastmcp__ = metadata  # type: ignore[attr-defined]  # ty:ignore[unresolved-attribute]\n            self.add_prompt(fn)\n            return fn\n\n        if inspect.isroutine(name_or_fn):\n            return decorate_and_register(name_or_fn, name)\n\n        elif isinstance(name_or_fn, str):\n            if name is not None:\n                raise TypeError(\n                    f\"Cannot specify both a name as first argument and as keyword argument. \"\n                    f\"Use either @prompt('{name_or_fn}') or @prompt(name='{name}'), not both.\"\n                )\n            prompt_name = name_or_fn\n        elif name_or_fn is None:\n            prompt_name = name\n        else:\n            raise TypeError(f\"Invalid first argument: {type(name_or_fn)}\")\n\n        return partial(\n            self.prompt,\n            name=prompt_name,\n            version=version,\n            title=title,\n            description=description,\n            icons=icons,\n            tags=tags,\n            meta=meta,\n            enabled=enabled,\n            auth=auth,\n        )\n","sourceCodeStart":197,"sourceCodeEnd":229,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/local_provider/decorators/prompts.py#L197-L229","documentation":"After checking for a routine, string, and None, any other type for the first positional argument of `@prompt` (e.g. a Prompt instance, class, list) is rejected with this TypeError. The first argument must be a function, a name string, or omitted.","triggerScenarios":"`@prompt(some_prompt_instance)`, `@prompt(MyClass)`, or accidentally calling with a non-str non-callable first argument like `@prompt(123)`.","commonSituations":"Passing a Prompt object where a name string was intended; typos such as forgetting quotes around the name; reusing decorator snippets across tool/prompt APIs with different signatures.","solutions":["Pass a string name: `@prompt('my_name')`, or omit the argument entirely: `@prompt`","If you meant to register an existing Prompt, use `add_prompt(prompt_instance)` instead of the decorator","Quote the name if you wrote `@prompt(my_name)` where `my_name` is an unresolved variable"],"exampleFix":"// before\n@provider.prompt(my_prompt_name)  # variable is undefined/None\nasync def p(): ...\n// after\n@provider.prompt('my_prompt_name')\nasync def p(): ...","handlingStrategy":"type-guard","validationCode":"assert isinstance(name_or_fn, (str, type(None))) or callable(name_or_fn), 'first arg must be str, callable, or omitted'","typeGuard":"def valid_prompt_arg(x) -> bool:\n    import inspect\n    return x is None or isinstance(x, str) or inspect.isroutine(x)","tryCatchPattern":"try:\n    deco = provider.prompt(name_or_fn)\nexcept TypeError as e:\n    if 'Invalid first argument' in str(e): fix_signature()","preventionTips":["Quote name strings in decorators","Only pass functions, name strings, or nothing to @prompt","Use add_prompt for registering existing Prompt instances, not the decorator"],"tags":["python","type-error","decorators","prompts"],"backgroundTag":"invalid-decorator-argument","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}