PrefectHQ/fastmcp · error · ValueError
No content in response from Anthropic
Error message
No content in response from Anthropic
What it means
_message_to_create_message_result raises ValueError when the Anthropic API returns a Message whose content list is empty. The handler must produce a CreateMessageResult with content, so an empty response cannot be converted and is surfaced as an explicit error.
Source
Thrown at fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py:340
content=[_image_content_to_anthropic_block(content)],
)
)
continue
# Handle AudioContent - not supported by Anthropic
if isinstance(content, AudioContent):
raise ValueError("AudioContent is not supported by the Anthropic API")
raise ValueError(f"Unsupported content type: {type(content)}")
return anthropic_messages
@staticmethod
def _message_to_create_message_result(
message: Message,
) -> CreateMessageResult:
if len(message.content) == 0:
raise ValueError("No content in response from Anthropic")
# Join all text blocks to avoid dropping content
text = "".join(
block.text for block in message.content if isinstance(block, TextBlock)
)
if text:
return CreateMessageResult(
content=TextContent(type="text", text=text),
role="assistant",
model=message.model,
)
raise ValueError(
f"No text content in response from Anthropic: {[type(b).__name__ for b in message.content]}"
)
def _select_model_from_preferences(
self, model_preferences: ModelPreferences | str | list[str] | NoneView on GitHub (pinned to 1f02114297)
Solutions
- Increase max_tokens in the sampling handler config so the model can emit at least one content block.
- Catch ValueError in the sampling callback and return a fallback CreateMessageResult or an error to the server.
- Retry the request once — transient empty responses can occur during API incidents.
- Log message.stop_reason to diagnose why the model returned nothing before retrying.
Example fix
// before
result = await handler(messages, params, context)
// after
try:
result = await handler(messages, params, context)
except ValueError as e:
if "No content" in str(e):
return CreateMessageResult(content=TextContent(type="text", text="Model returned no content"), role="assistant", model=params.modelPreferences.model_hint if params.modelPreferences else "unknown")
raise Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
try:
result = await handler(messages, params, context)
except ValueError as e:
if "No content in response from Anthropic" in str(e):
result = CreateMessageResult(content=TextContent(type="text", text="(empty model response)"), role="assistant", model="unknown")
else:
raise Prevention
- Set a reasonable max_tokens (never 0/1)
- Log stop_reason when responses come back empty
- Retry once on empty responses before failing
- Monitor Anthropic status during incidents
When it happens
Trigger: Anthropic returns a Message with content=[] — e.g. the model produced no blocks (often after a refusal, filtering, or a max_tokens stop with zero output).
Common situations: Hitting max_tokens=1 or very small limits; content filtering by Anthropic; unusual model parameters (temperature/top_p edge settings); API quirks during outages.
Related errors
- No response for completion
- Unsupported image MIME type for Anthropic: {content.mime_typ
- ImageContent is only supported in user messages for Anthropi
- AudioContent is not supported by the Anthropic API
- Unsupported content type for Anthropic: {type(item).__name__
AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29).
Data as JSON: /api/errors/092f2a6956edc1ec.
Report an issue: GitHub.