{"record":{"id":"b3466cecba1a6c9d","repo":"PrefectHQ/fastmcp","slug":"error-rendering-prompt-self-name-r-e","errorCode":null,"errorMessage":"Error rendering prompt {self.name!r}: {e}","messagePattern":"Error rendering prompt (.+?): (.+?)","errorType":"exception","errorClass":"PromptError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/prompts/function_prompt.py","lineNumber":363,"sourceCode":"            # self.fn is wrapped by without_injected_parameters which handles\n            # dependency resolution internally\n            if is_coroutine_function(self.fn):\n                result = await type_adapter.validate_python(kwargs)\n            else:\n                # Run sync functions in threadpool to avoid blocking the event loop\n                result = await call_sync_fn_in_threadpool(\n                    type_adapter.validate_python, kwargs\n                )\n                # Handle sync wrappers that return awaitables (e.g., partial(async_fn))\n                if inspect.isawaitable(result):\n                    result = await result\n\n            return self.convert_result(result)\n        except FastMCPError:\n            raise\n        except Exception as e:\n            logger.exception(f\"Error rendering prompt {self.name}\")\n            raise PromptError(f\"Error rendering prompt {self.name!r}: {e}\") from e\n\n\n@overload\ndef prompt(fn: F) -> F: ...\n@overload\ndef prompt(\n    name_or_fn: str,\n    *,\n    version: str | int | None = None,\n    title: str | None = None,\n    description: str | None = None,\n    icons: list[Icon] | None = None,\n    tags: set[str] | None = None,\n    meta: dict[str, Any] | None = None,\n    auth: AuthCheck | list[AuthCheck] | None = None,\n) -> Callable[[F], F]: ...\n@overload\ndef prompt(","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/prompts/function_prompt.py#L345-L381","documentation":"When the prompt's render function raises any exception that is not a FastMCPError, render() logs the full traceback and re-raises it wrapped in a PromptError, chained via 'from e' so the original cause is preserved. This normalizes arbitrary user-function failures (syntax errors, type errors, network failures inside the fn) into a single prompt-domain error type. FastMCPError subclasses pass through unwrapped.","triggerScenarios":"The function decorated with @prompt raises any non-FastMCP exception when invoked with the supplied arguments — e.g. TypeError from wrong argument types after string conversion, KeyError inside the function, API call failures, division by zero.","commonSituations":"The prompt function calls an external LLM/API that is down; argument type conversion produces an unexpected type (e.g. 'None' string) that the fn chokes on; a refactor changed the fn signature so a keyword mismatches; template rendering inside the fn raises.","solutions":["Read the chained original exception in the traceback (the 'caused by' section) to find the real root cause inside your prompt function","Fix the bug in the prompt function itself — PromptError is only a wrapper","Catch PromptError at the call site and fall back to a user-friendly message","If your function intentionally raises a domain error, raise a FastMCPError subclass so it propagates unwrapped"],"exampleFix":"// before\ndef get_weather(city: str) -> str:\n    return api.fetch(city)['temp']  # raises KeyError\n// after\ndef get_weather(city: str) -> str:\n    data = api.fetch(city)\n    return data.get('temp', 'unknown')","handlingStrategy":"try-catch","validationCode":"import inspect\nsig = inspect.signature(prompt_fn)\nsig.bind(**arguments)  # raises TypeError early if args mismatch","typeGuard":null,"tryCatchPattern":"try:\n    result = await prompt.render(arguments)\nexcept PromptError as e:\n    logger.error('prompt failed: %s (cause: %r)', e, e.__cause__)\n    result = fallback_prompt_result\nexcept FastMCPError:\n    raise  # domain errors pass through unwrapped","preventionTips":["Always inspect e.__cause__ / the chained traceback, not just the PromptError message","Keep prompt functions simple and move risky I/O into guarded helpers","Test prompt functions directly with pytest before registering them","Raise FastMCPError subclasses inside prompt fns for errors you want unwrapped"],"tags":["prompts","error-handling","exception-wrapping"],"backgroundTag":"prompt-render-failed","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}