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
- Inspect the code in the message: AccessDeniedException -> fix IAM policy (bedrock:Retrieve on the KB arn); ResourceNotFoundException -> verify knowledge_base_id and region
- Ensure AWS_REGION/AWS_DEFAULT_REGION matches the region where the knowledge base was created
- Refresh credentials (aws sso login / aws sts get-caller-identity to verify)
- 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
- Pre-flight IAM: principal can bedrock:Retrieve on the KB arn
- Set AWS_REGION explicitly to the KB's region
- Verify knowledge_base_id exists via boto3 bedrock-agent list_knowledge_bases before ingestion
- Retry only transient codes (Throttling/5xx); fail fast on 4xx auth/resource errors
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
- Error ({error_code}): {error_message}
- Bedrock requires file_uri for FileReference (S3 URI)
- boto3 is required for Bedrock S3 file uploads. Install with:
- aioboto3 is required for async Bedrock S3 file uploads. Inst
- agent_id cannot be empty
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/3763f875220213c8.
Report an issue: GitHub.