{"record":{"id":"d9c5526cdf798fad","repo":"PrefectHQ/fastmcp","slug":"subclasses-must-implement-render","errorCode":null,"errorMessage":"Subclasses must implement render()","messagePattern":"Subclasses must implement render\\(\\)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/prompts/base.py","lineNumber":307,"sourceCode":"            description=description,\n            icons=icons,\n            tags=tags,\n            meta=meta,\n            auth=auth,\n        )\n\n    async def render(\n        self,\n        arguments: dict[str, Any] | None = None,\n    ) -> str | list[Message | str] | PromptResult:\n        \"\"\"Render the prompt with arguments.\n\n        Subclasses must implement this method. Return one of:\n        - str: Wrapped as single user Message\n        - list[Message | str]: Converted to list[Message]\n        - PromptResult: Used directly\n        \"\"\"\n        raise NotImplementedError(\"Subclasses must implement render()\")\n\n    def convert_result(self, raw_value: Any) -> PromptResult:\n        \"\"\"Convert a raw return value to PromptResult.\n\n        Accepts:\n            - PromptResult: passed through\n            - str: wrapped as single Message\n            - list[Message | str]: converted to list[Message]\n\n        Raises:\n            TypeError: for unsupported types\n        \"\"\"\n        if isinstance(raw_value, PromptResult):\n            return raw_value\n\n        if isinstance(raw_value, mcp_types.InputRequiredResult):\n            # The prompt asked the client for input (SEP-2322). Wrap it so the\n            # ask travels the middleware chain as an ordinary result; the wire","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/prompts/base.py#L289-L325","documentation":"The base Prompt class's render() is intentionally abstract: it raises NotImplementedError('Subclasses must implement render()'). Every concrete prompt subclass must supply its own render() returning str, list[Message|str], or PromptResult; calling render on a subclass that forgot to override it produces this error.","triggerScenarios":"Subclassing Prompt (or using a custom prompt class) without defining render(); a rename/typo like renders() or _render() overriding the wrong method; instantiating a half-implemented abstract subclass and sending it to _render via a client prompt call.","commonSituations":"Writing custom dynamic prompts; upgrading fastmcp where a hook method was renamed; copy-pasted subclass missing the render body.","solutions":["Define render() (or an async render) in your Prompt subclass returning str, list[Message|str], or PromptResult","Check the method name is exactly 'render' and the signature matches the base class","If you meant a static prompt, use from_message/factory helpers rather than a bare subclass"],"exampleFix":"// before\nclass MyPrompt(Prompt):\n    pass\n// after\nclass MyPrompt(Prompt):\n    def render(self) -> str:\n        return \"Hello!\"","handlingStrategy":"validation","validationCode":"def check_render_override(cls) -> None:\n    if cls.render is Prompt.render:\n        raise TypeError(f\"{cls.__name__} must implement render()\")","typeGuard":null,"tryCatchPattern":"try:\n    result = await prompt._render()\nexcept NotImplementedError as e:\n    raise RuntimeError(f\"{type(prompt).__name__} forgot render(): {e}\") from e","preventionTips":["Always override render() in Prompt subclasses","Check method spelling and signature match the base class","Add a startup assertion/test that custom prompts can render"],"tags":["prompts","not-implemented","subclassing","python"],"backgroundTag":"not-implemented","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}