crewAIInc/crewAI · error · BedrockKnowledgeBaseError

Error ({error_code}): {error_message}

Error message

Error ({error_code}): {error_message}

What it means

Raised when the boto3 bedrock-agent-runtime retrieve call returns a botocore ClientError (an AWS-side error). The tool extracts response['Error']['Code'] and ['Message'] when present (otherwise 'Unknown' and str(e)) and re-raises as BedrockKnowledgeBaseError with format 'Error (CODE): Message'. This is the umbrella for auth failures, missing resources, throttling, and model/region issues.

Source

Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py:246

            if "nextToken" in response:
                response_object["nextToken"] = response["nextToken"]

            if "guardrailAction" in response:
                response_object["guardrailAction"] = response["guardrailAction"]

            return json.dumps(response_object, indent=2)

        except ClientError as e:
            error_code = "Unknown"
            error_message = str(e)

            # Try to extract error code if available
            if hasattr(e, "response") and "Error" in e.response:
                error_code = e.response["Error"].get("Code", "Unknown")
                error_message = e.response["Error"].get("Message", str(e))

            raise BedrockKnowledgeBaseError(
                f"Error ({error_code}): {error_message}"
            ) from e
        except Exception as e:
            raise BedrockKnowledgeBaseError(f"Unexpected error: {e!s}") from e

View on GitHub (pinned to 754d7323be)

Solutions

  1. Inspect the code in the message: AccessDeniedException -> fix IAM policy (bedrock:Retrieve on the KB arn); ResourceNotFoundException -> verify knowledge_base_id and region
  2. Ensure AWS_REGION/AWS_DEFAULT_REGION matches the region where the knowledge base was created
  3. Refresh credentials (aws sso login / aws sts get-caller-identity to verify)
  4. For ThrottlingException, add exponential backoff and reduce request rate

Example fix

# before
result = tool._run(query)
# after
from crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKnowledgeBaseError
try:
    result = tool._run(query)
except BedrockKnowledgeBaseError as e:
    msg = str(e)
    if 'ThrottlingException' in msg:
        time.sleep(2 ** attempt); result = tool._run(query)
    else:
        raise
Defensive patterns

Strategy: retry

Validate before calling

import boto3
sts = boto3.client('sts')
sts.get_caller_identity()  # verifies credentials+region before running the tool

Try / catch

from crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKnowledgeBaseError
for attempt in range(4):
    try:
        out = tool._run(q); break
    except BedrockKnowledgeBaseError as e:
        msg = str(e)
        if 'ThrottlingException' in msg and attempt < 3:
            time.sleep(2 ** attempt); continue
        raise

Prevention

When it happens

Trigger: HTTP 4xx/5xx from AWS: knowledge_base_id that doesn't exist or isn't accessible (ValidationException/AccessDeniedException), expired or missing AWS credentials (UnrecognizedClientException), wrong region (the client defaults to AWS_REGION/AWS_DEFAULT_REGION or us-east-1), or ThrottlingException under load.

Common situations: IAM role/policy missing bedrock:Retrieve permission; KB created in a different region than the env vars specify; expired SSO token; service quota throttling during bulk retrieval.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/3763f875220213c8. Report an issue: GitHub.