{"record":{"id":"09276bc9cdca62c5","repo":"PrefectHQ/fastmcp","slug":"no-text-content-in-response-from-anthropic-type","errorCode":null,"errorMessage":"No text content in response from Anthropic: {[type(b).__name__ for b in message.content]}","messagePattern":"No text content in response from Anthropic: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py","lineNumber":353,"sourceCode":"    @staticmethod\n    def _message_to_create_message_result(\n        message: Message,\n    ) -> CreateMessageResult:\n        if len(message.content) == 0:\n            raise ValueError(\"No content in response from Anthropic\")\n\n        # Join all text blocks to avoid dropping content\n        text = \"\".join(\n            block.text for block in message.content if isinstance(block, TextBlock)\n        )\n        if text:\n            return CreateMessageResult(\n                content=TextContent(type=\"text\", text=text),\n                role=\"assistant\",\n                model=message.model,\n            )\n\n        raise ValueError(\n            f\"No text content in response from Anthropic: {[type(b).__name__ for b in message.content]}\"\n        )\n\n    def _select_model_from_preferences(\n        self, model_preferences: ModelPreferences | str | list[str] | None\n    ) -> ModelParam:\n        for model_option in self._iter_models_from_preferences(model_preferences):\n            # Accept any model that starts with \"claude\"\n            if model_option.startswith(\"claude\"):\n                return model_option\n\n        return self.default_model\n\n    @staticmethod\n    def _convert_tools_to_anthropic(tools: list[Tool]) -> list[ToolParam]:\n        \"\"\"Convert MCP tools to Anthropic tool format.\"\"\"\n        anthropic_tools: list[ToolParam] = []\n        for tool in tools:","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py#L335-L371","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Disable tool use in the sampling request (or use AnthropicSamplingHandler's tool-aware path) so the model returns text.","Use _message_to_result_with_tools / a tool-capable handler path if your sampling flow supports tools.","Catch ValueError and fall back to a text result instructing the model to respond in text.","Check the model/parameters: force text output via system prompt or tool_choice settings."],"exampleFix":"// before\nresult = await AnthropicSamplingHandler(api_key=key)(messages, params, context)\n// after\ntry:\n    result = await handler(messages, params, context)\nexcept ValueError as e:\n    if \"No text content\" in str(e):\n        params.tool_choice = None\n        params.messages = [*params.messages, SamplingMessage(role=\"user\", content=TextContent(type=\"text\", text=\"Please reply with plain text.\"))]\n        result = await handler(messages, params, context)\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    result = await handler(messages, params, context)\nexcept ValueError as e:\n    if \"No text content\" in str(e):\n        return CreateMessageResult(content=TextContent(type=\"text\", text=\"Model returned non-text content; please retry with a text request.\"), role=\"assistant\", model=\"unknown\")\n    raise","preventionTips":["Don't enable tool use with the plain text-only sampling path","Check for thinking-only responses when extended thinking is on","Verify model output settings force text replies","Log response block types when debugging"],"tags":["anthropic","sampling","text-content","tool-use"],"backgroundTag":"empty-model-response","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}