{"record":{"id":"ccf6cd2d69012a80","repo":"huggingface/smolagents","slug":"no-message-content-blocks-with-text-key-found-in","errorCode":null,"errorMessage":"No message content blocks with 'text' key found in response","messagePattern":"No message content blocks with 'text' key found in response","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"src/smolagents/models.py","lineNumber":2046,"sourceCode":"        if response_format is not None:\n            raise ValueError(\"Amazon Bedrock does not support response_format\")\n        completion_kwargs: dict = self._prepare_completion_kwargs(\n            messages=messages,\n            tools_to_call_from=tools_to_call_from,\n            custom_role_conversions=self.custom_role_conversions,\n            convert_images_to_image_urls=True,\n            **kwargs,\n        )\n        self._apply_rate_limit()\n        # self.client is created in ApiModel class\n        response = self.retryer(self.client.converse, **completion_kwargs)\n\n        # Get content blocks with \"text\" key: in case thinking blocks are present, discard them\n        message_content_blocks_with_text = [\n            block for block in response[\"output\"][\"message\"][\"content\"] if \"text\" in block\n        ]\n        if not message_content_blocks_with_text:\n            raise KeyError(\"No message content blocks with 'text' key found in response\")\n        # Keep the last one\n        content = message_content_blocks_with_text[-1][\"text\"]\n        if stop_sequences is not None and not self.supports_stop_parameter:\n            content = remove_content_after_stop_sequences(content, stop_sequences)\n        return ChatMessage(\n            role=response[\"output\"][\"message\"][\"role\"],\n            content=content,\n            tool_calls=response[\"output\"][\"message\"][\"tool_calls\"],\n            raw=response,\n            token_usage=TokenUsage(\n                input_tokens=response[\"usage\"][\"inputTokens\"],\n                output_tokens=response[\"usage\"][\"outputTokens\"],\n            ),\n        )\n\n\nAmazonBedrockServerModel = AmazonBedrockModel\n","sourceCodeStart":2028,"sourceCodeEnd":2064,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/models.py#L2028-L2064","documentation":"KeyError raised when parsing the Bedrock Converse response: response['output']['message']['content'] contained no content blocks with a 'text' key. This happens when the model only returned non-text blocks (e.g. toolUse, or only reasoning/thinking blocks) or the response shape differs from expectations.","triggerScenarios":"Calling BedrockModel.generate with tools_to_call_from where the model responds solely with a tool call block; or with extended thinking/reasoning enabled so only thinking blocks are returned; or an unexpected/empty response body.","commonSituations":"Using Claude models with tool use on Bedrock; enabling thinking/reasoning configuration; model returning an empty or truncated response; mismatches between Bedrock API versions and response schemas.","solutions":["Check response['output']['message']['content'] and handle toolUse blocks before expecting text (use the model's tool-calling flow rather than plain generate)","If thinking blocks are the cause, adjust model/inference config so a text block is produced","Upgrade smolagents — response parsing for mixed content blocks has been improved across versions","Retry the request: occasional empty completions from Bedrock can produce this"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from smolagents.models import BedrockModel\n\ntry:\n    msg = model.generate(messages, tools_to_call_from=tools)\nexcept KeyError as e:\n    if \"text\" in str(e):\n        # model returned only tool-use/thinking blocks; inspect raw response or retry\n        msg = model.generate(messages)  # retry without tools","preventionTips":["Prefer the agent's tool-calling flow over raw generate with tools on Bedrock","Pin a smolagents version tested with your Bedrock model","Add retry with backoff for occasional empty completions"],"tags":["bedrock","response-parsing","keyerror","tool-use","thinking-blocks"],"backgroundTag":"unexpected-empty-api-response","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}