{"record":{"id":"610ba15127c4e37b","repo":"huggingface/smolagents","slug":"amazon-bedrock-does-not-support-response-format","errorCode":null,"errorMessage":"Amazon Bedrock does not support response_format","messagePattern":"Amazon Bedrock does not support response_format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/models.py","lineNumber":2029,"sourceCode":"        try:\n            import boto3  # type: ignore\n        except ModuleNotFoundError as e:\n            raise ModuleNotFoundError(\n                \"Please install 'bedrock' extra to use AmazonBedrockServerModel: `pip install 'smolagents[bedrock]'`\"\n            ) from e\n\n        return boto3.client(\"bedrock-runtime\", **self.client_kwargs)\n\n    def generate(\n        self,\n        messages: list[ChatMessage | dict],\n        stop_sequences: list[str] | None = None,\n        response_format: dict[str, str] | None = None,\n        tools_to_call_from: list[Tool] | None = None,\n        **kwargs,\n    ) -> ChatMessage:\n        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","sourceCodeStart":2011,"sourceCodeEnd":2047,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/models.py#L2011-L2047","documentation":"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.","triggerScenarios":"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.","commonSituations":"Switching a CodeAgent/ToolSearchAgent configured for structured JSON output from OpenAI to Bedrock; enabling structured code generation without checking the model's capability matrix.","solutions":["Remove response_format / disable structured output for Bedrock models","Switch to an agent/model that supports response_format (OpenAI, Gemini, etc.)","Have the model emit JSON via prompt instructions and parse the text yourself"],"exampleFix":"# before\nmodel = BedrockModel(model_id=\"...\")\nagent = CodeAgent(tools=[], model=model, output_chat_format=dict)\n\n# after\nmodel = BedrockModel(model_id=\"...\")\nagent = CodeAgent(tools=[], model=model)  # no response_format","handlingStrategy":"validation","validationCode":"from smmolagents.models import BedrockModel\n\ndef supports_response_format(model) -> bool:\n    return not isinstance(model, BedrockModel)\n\nif not supports_response_format(model):\n    kwargs.pop(\"response_format\", None)  # strip before calling","typeGuard":null,"tryCatchPattern":"try:\n    result = model.generate(messages, tools_to_call_from=tools)\nexcept ValueError as e:\n    if \"does not support response_format\" in str(e):\n        result = model.generate(messages, tools_to_call_from=tools)  # retry without format","preventionTips":["Check model.supports_response_format / capability flags before enabling structured output","Keep structured-output logic behind a feature check when swapping providers"],"tags":["bedrock","aws","response-format","structured-output","unsupported-feature"],"backgroundTag":"unsupported-api-parameter","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}