PrefectHQ/fastmcp · error · ValueError

No text content in response from Anthropic: {[type(b).__name

Error message

No text content in response from Anthropic: {[type(b).__name__ for b in message.content]}

What it means

_message_to_create_message_result raises ValueError when the Anthropic response contains content blocks but none are TextBlock (e.g. only tool_use or thinking blocks). The basic sampling handler can only return text, so it refuses to return an empty/dropped-content result.

Source

Thrown at fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py:353

    @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] | None
    ) -> ModelParam:
        for model_option in self._iter_models_from_preferences(model_preferences):
            # Accept any model that starts with "claude"
            if model_option.startswith("claude"):
                return model_option

        return self.default_model

    @staticmethod
    def _convert_tools_to_anthropic(tools: list[Tool]) -> list[ToolParam]:
        """Convert MCP tools to Anthropic tool format."""
        anthropic_tools: list[ToolParam] = []
        for tool in tools:

View on GitHub (pinned to 1f02114297)

Solutions

  1. Disable tool use in the sampling request (or use AnthropicSamplingHandler's tool-aware path) so the model returns text.
  2. Use _message_to_result_with_tools / a tool-capable handler path if your sampling flow supports tools.
  3. Catch ValueError and fall back to a text result instructing the model to respond in text.
  4. Check the model/parameters: force text output via system prompt or tool_choice settings.

Example fix

// before
result = await AnthropicSamplingHandler(api_key=key)(messages, params, context)
// after
try:
    result = await handler(messages, params, context)
except ValueError as e:
    if "No text content" in str(e):
        params.tool_choice = None
        params.messages = [*params.messages, SamplingMessage(role="user", content=TextContent(type="text", text="Please reply with plain text."))]
        result = await handler(messages, params, context)
    else:
        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 text content" in str(e):
        return CreateMessageResult(content=TextContent(type="text", text="Model returned non-text content; please retry with a text request."), role="assistant", model="unknown")
    raise

Prevention

When it happens

Trigger: Anthropic returns only ToolUseBlock(s) (model chose to call a tool) or only non-text blocks while the client uses the plain AnthropicSamplingHandler without tool support.

Common situations: Server sampling requests that allow tool use against the plain handler; models configured for tool use returning tool calls; response containing only thinking blocks with thinking enabled.

Related errors


AI-assisted analysis of PrefectHQ/fastmcp@1f02114297 (2026-08-29). Data as JSON: /api/errors/09276bc9cdca62c5. Report an issue: GitHub.