PrefectHQ/fastmcp · error · NotImplementedError
Subclasses must implement render()
Error message
Subclasses must implement render()
What it means
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.
Source
Thrown at fastmcp_slim/fastmcp/prompts/base.py:307
description=description,
icons=icons,
tags=tags,
meta=meta,
auth=auth,
)
async def render(
self,
arguments: dict[str, Any] | None = None,
) -> str | list[Message | str] | PromptResult:
"""Render the prompt with arguments.
Subclasses must implement this method. Return one of:
- str: Wrapped as single user Message
- list[Message | str]: Converted to list[Message]
- PromptResult: Used directly
"""
raise NotImplementedError("Subclasses must implement render()")
def convert_result(self, raw_value: Any) -> PromptResult:
"""Convert a raw return value to PromptResult.
Accepts:
- PromptResult: passed through
- str: wrapped as single Message
- list[Message | str]: converted to list[Message]
Raises:
TypeError: for unsupported types
"""
if isinstance(raw_value, PromptResult):
return raw_value
if isinstance(raw_value, mcp_types.InputRequiredResult):
# The prompt asked the client for input (SEP-2322). Wrap it so the
# ask travels the middleware chain as an ordinary result; the wireView on GitHub (pinned to 1f02114297)
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
Example fix
// before
class MyPrompt(Prompt):
pass
// after
class MyPrompt(Prompt):
def render(self) -> str:
return "Hello!" Defensive patterns
Strategy: validation
Validate before calling
def check_render_override(cls) -> None:
if cls.render is Prompt.render:
raise TypeError(f"{cls.__name__} must implement render()") Try / catch
try:
result = await prompt._render()
except NotImplementedError as e:
raise RuntimeError(f"{type(prompt).__name__} forgot render(): {e}") from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: Writing custom dynamic prompts; upgrading fastmcp where a hook method was renamed; copy-pasted subclass missing the render body.
Related errors
- messages[{i}] must be Message, got {type(item).__name__}. Us
- messages must be str or list[Message], got {type(messages)._
- messages[{i}] must be Message or str, got {type(item).__name
- Prompt must return str, list[Message], or PromptResult, got
- Subclasses must implement read()
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/d9c5526cdf798fad.
Report an issue: GitHub.