huggingface/smolagents · error · KeyError
No message content blocks with 'text' key found in response
Error message
No message content blocks with 'text' key found in response
What it means
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.
Source
Thrown at src/smolagents/models.py:2046
if response_format is not None:
raise ValueError("Amazon Bedrock does not support response_format")
completion_kwargs: dict = self._prepare_completion_kwargs(
messages=messages,
tools_to_call_from=tools_to_call_from,
custom_role_conversions=self.custom_role_conversions,
convert_images_to_image_urls=True,
**kwargs,
)
self._apply_rate_limit()
# self.client is created in ApiModel class
response = self.retryer(self.client.converse, **completion_kwargs)
# Get content blocks with "text" key: in case thinking blocks are present, discard them
message_content_blocks_with_text = [
block for block in response["output"]["message"]["content"] if "text" in block
]
if not message_content_blocks_with_text:
raise KeyError("No message content blocks with 'text' key found in response")
# Keep the last one
content = message_content_blocks_with_text[-1]["text"]
if stop_sequences is not None and not self.supports_stop_parameter:
content = remove_content_after_stop_sequences(content, stop_sequences)
return ChatMessage(
role=response["output"]["message"]["role"],
content=content,
tool_calls=response["output"]["message"]["tool_calls"],
raw=response,
token_usage=TokenUsage(
input_tokens=response["usage"]["inputTokens"],
output_tokens=response["usage"]["outputTokens"],
),
)
AmazonBedrockServerModel = AmazonBedrockModel
View on GitHub (pinned to 30bb116109)
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
Defensive patterns
Strategy: try-catch
Try / catch
from smolagents.models import BedrockModel
try:
msg = model.generate(messages, tools_to_call_from=tools)
except KeyError as e:
if "text" in str(e):
# model returned only tool-use/thinking blocks; inspect raw response or retry
msg = model.generate(messages) # retry without tools Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Please install 'bedrock' extra to use AmazonBedrockServerMod
- Amazon Bedrock does not support response_format
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/ccf6cd2d69012a80.
Report an issue: GitHub.