mem0ai/mem0 · error · ImportError

The 'boto3' library is required. Please install it using 'pi

Error message

The 'boto3' library is required. Please install it using 'pip install boto3'.

What it means

Module-level ImportError raised when mem0/llms/aws_bedrock.py is imported without boto3/botocore installed. It fires when the AWSBedrockLLM class is loaded (llm provider 'aws_bedrock'), before any AWS call is attempted.

Source

Thrown at mem0/llms/aws_bedrock.py:10

import json
import logging
import re
from typing import Any, Dict, List, Optional, Union

try:
    import boto3
    from botocore.exceptions import ClientError, NoCredentialsError
except ImportError:
    raise ImportError("The 'boto3' library is required. Please install it using 'pip install boto3'.")

from mem0.configs.llms.aws_bedrock import AWSBedrockConfig
from mem0.configs.llms.base import BaseLlmConfig
from mem0.llms.base import LLMBase
from mem0.memory.utils import extract_json

logger = logging.getLogger(__name__)

PROVIDERS = [
    "ai21", "amazon", "anthropic", "cohere", "meta", "mistral", "stability", "writer",
    "deepseek", "gpt-oss", "perplexity", "snowflake", "titan", "command", "j2", "llama",
    "minimax",
]


def extract_provider(model: str, explicit_provider: Optional[str] = None) -> str:
    """Extract provider from model identifier, or return explicit_provider when set."""
    if explicit_provider:

View on GitHub (pinned to 001c235229)

Solutions

  1. pip install boto3
  2. Add boto3 to the project's dependency list and redeploy
  3. Verify in the runtime environment: python -c "import boto3; print(boto3.__version__)"
  4. If running on AWS, prefer attaching an IAM role and still installing boto3 — the role solves credentials, not the missing library

Example fix

// before
Memory.from_config({"llm": {"provider": "aws_bedrock", "config": {"model": "anthropic.claude-3-5-sonnet-20240620-v1:0"}}})  # ImportError

# after
# pip install boto3
Memory.from_config({"llm": {"provider": "aws_bedrock", "config": {"model": "anthropic.claude-3-5-sonnet-20240620-v1:0", "aws_region": "us-east-1"}}})
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

if importlib.util.find_spec("boto3") is None:
    raise SystemExit("Missing dependency: pip install boto3")

Try / catch

try:
    from mem0.llms.aws_bedrock import AWSBedrockLLM
except ImportError as e:
    raise SystemExit(f"{e}; install with: pip install boto3") from e

Prevention

When it happens

Trigger: Configuring llm.provider: aws_bedrock without pip install boto3; running mem0 in an environment where boto3 was never declared (it is an optional extra); Lambda/container images stripped of boto3 layers.

Common situations: Self-hosted mem0 pointing at Bedrock in a fresh venv; CI jobs missing boto3 in requirements.txt; assuming AWS SDK presence because the workload runs on EC2/ECS (it is not bundled by default in containers).

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/905a773d4ee5dbcd. Report an issue: GitHub.