huggingface/smolagents · error · ModuleNotFoundError

Please install 'bedrock' extra to use AmazonBedrockServerMod

Error message

Please install 'bedrock' extra to use AmazonBedrockServerModel: `pip install 'smolagents[bedrock]'`

What it means

AmazonBedrockServerModel.create_client imports boto3 to build a bedrock-runtime client; if boto3 is missing, the ModuleNotFoundError is re-raised with instructions to install the `bedrock` extra. The check happens when the model is constructed, since create_client runs from __init__.

Source

Thrown at src/smolagents/models.py:2014

        completion_kwargs.pop("toolConfig", None)

        # The Bedrock API does not support the `type` key in requests.
        # This block of code modifies the object to meet Bedrock's requirements.
        for message in completion_kwargs.get("messages", []):
            for content in message.get("content", []):
                if "type" in content:
                    del content["type"]

        return {
            "modelId": self.model_id,
            **completion_kwargs,
        }

    def create_client(self):
        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,

View on GitHub (pinned to 30bb116109)

Solutions

  1. Install the extra: `pip install 'smolagents[bedrock]'` (pulls boto3).
  2. Verify in the runtime interpreter: `python -c "import boto3"`.
  3. Ensure AWS credentials (env vars, profile, or IAM role) are configured afterward, since boto3.client will need them at request time.

Example fix

# before
pip install smolagents
model = AmazonBedrockServerModel(model_id="anthropic.claude-3-sonnet-...")  # ModuleNotFoundError

# after
pip install 'smolagents[bedrock]'
Defensive patterns

Strategy: validation

Validate before calling

try:
    import boto3  # noqa
    ok = True
except ModuleNotFoundError:
    ok = False
assert ok, "pip install 'smolagents[bedrock]'"

Type guard

null

Try / catch

try:
    model = AmazonBedrockServerModel(model_id=mid)
except ModuleNotFoundError as e:
    print("Install the extra:", e)
    sys.exit(1)

Prevention

When it happens

Trigger: Instantiating AmazonBedrockServerModel in an environment where boto3 is not installed — i.e. the base smolagents install without the bedrock extra.

Common situations: AWS deployments with slim Lambdas/containers lacking boto3; local venvs created before bedrock support was added; CI environments with cached minimal requirements.

Understand the failure class

Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.

Related errors


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