{"record":{"id":"0483bfb80195266a","repo":"PrefectHQ/fastmcp","slug":"cannot-specify-name-both-as-first-argument-and-key","errorCode":null,"errorMessage":"Cannot specify name both as first argument and keyword","messagePattern":"Cannot specify name both as first argument and keyword","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/prompts/function_prompt.py","lineNumber":440,"sourceCode":"            title=title,\n            description=description,\n            icons=icons,\n            tags=tags,\n            meta=meta,\n            auth=auth,\n        )\n        target = fn.__func__ if isinstance(fn, staticmethod | MethodType) else fn\n        cast(Any, target).__fastmcp__ = metadata\n        return fn\n\n    def decorator(fn: F, prompt_name: str | None) -> F:\n        return attach_metadata(fn, prompt_name)\n\n    if inspect.isroutine(name_or_fn):\n        return decorator(name_or_fn, name)\n    elif isinstance(name_or_fn, str):\n        if name is not None:\n            raise TypeError(\"Cannot specify name both as first argument and keyword\")\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    def wrapper(fn: F) -> F:\n        return decorator(fn, prompt_name)\n\n    return wrapper\n","sourceCodeStart":422,"sourceCodeEnd":451,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/prompts/function_prompt.py#L422-L451","documentation":"The @prompt decorator accepts the prompt name either as the first positional argument (@prompt('my_name')) or as the name keyword (@prompt(name='my_name')), but not both. Supplying a string as name_or_fn while name is also non-None is ambiguous, so prompt() raises TypeError immediately.","triggerScenarios":"Calling @prompt('my_prompt', name='other_name') or @prompt('my_prompt', name='other_name')(fn) — a string first argument plus a non-None name keyword.","commonSituations":"Merging two call styles during a refactor; IDE autocomplete adding name= alongside an existing positional name; copy-paste where one call form was partially converted to the other.","solutions":["Remove the name keyword and keep only the positional string: @prompt('my_prompt')","Or remove the positional string and use only the keyword: @prompt(name='my_prompt')","If you meant to decorate a function directly, pass the function (a routine, not a string) first with an optional name keyword"],"exampleFix":"// before\n@prompt('weather_prompt', name='weather')\ndef weather(): ...\n// after\n@prompt('weather')\ndef weather(): ...","handlingStrategy":"validation","validationCode":"def safe_prompt(first=None, name=None):\n    if isinstance(first, str) and name is not None:\n        raise TypeError('specify name positionally or as keyword, not both')\n    return prompt(first, name=name)","typeGuard":null,"tryCatchPattern":"try:\n    p = prompt('name_a', name='name_b')\nexcept TypeError as e:\n    logger.error('decorator misused: %s', e)\n    p = prompt(name='name_b')  # pick one canonical form","preventionTips":["Pick one style per codebase (positional string or name= keyword) and enforce it in review","Never pass both a positional string and name= keyword","Watch for IDE autocompletes that append name= to an existing positional name"],"tags":["prompts","decorator","arguments","typeerror"],"backgroundTag":"duplicate-argument-specified","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}