huggingface/smolagents · error · ValueError

Amazon Bedrock does not support response_format

Error message

Amazon Bedrock does not support response_format

What it means

Raised by BedrockModel.generate when a response_format argument is passed. Amazon Bedrock's Converse API does not support OpenAI-style structured output (response_format), so smolagents explicitly rejects it instead of silently ignoring it.

Source

Thrown at src/smolagents/models.py:2029

        try:
            import boto3  # type: ignore
        except ModuleNotFoundError as e:
            raise ModuleNotFoundError(
                "Please install 'bedrock' extra to use AmazonBedrockServerModel: `pip install 'smolagents[bedrock]'`"
            ) from e

        return boto3.client("bedrock-runtime", **self.client_kwargs)

    def generate(
        self,
        messages: list[ChatMessage | dict],
        stop_sequences: list[str] | None = None,
        response_format: dict[str, str] | None = None,
        tools_to_call_from: list[Tool] | None = None,
        **kwargs,
    ) -> ChatMessage:
        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

View on GitHub (pinned to 30bb116109)

Solutions

  1. Remove response_format / disable structured output for Bedrock models
  2. Switch to an agent/model that supports response_format (OpenAI, Gemini, etc.)
  3. Have the model emit JSON via prompt instructions and parse the text yourself

Example fix

# before
model = BedrockModel(model_id="...")
agent = CodeAgent(tools=[], model=model, output_chat_format=dict)

# after
model = BedrockModel(model_id="...")
agent = CodeAgent(tools=[], model=model)  # no response_format
Defensive patterns

Strategy: validation

Validate before calling

from smmolagents.models import BedrockModel

def supports_response_format(model) -> bool:
    return not isinstance(model, BedrockModel)

if not supports_response_format(model):
    kwargs.pop("response_format", None)  # strip before calling

Try / catch

try:
    result = model.generate(messages, tools_to_call_from=tools)
except ValueError as e:
    if "does not support response_format" in str(e):
        result = model.generate(messages, tools_to_call_from=tools)  # retry without format

Prevention

When it happens

Trigger: Calling agent.run or model.generate with structured output enabled, e.g. StructuredChatCodeGen or output_chat_format / response_format={'type':'json_object'} while using AmazonBedrock as the model.

Common situations: Switching a CodeAgent/ToolSearchAgent configured for structured JSON output from OpenAI to Bedrock; enabling structured code generation without checking the model's capability matrix.

Related errors


AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28). Data as JSON: /api/errors/610ba15127c4e37b. Report an issue: GitHub.