{"record":{"id":"3763f875220213c8","repo":"crewAIInc/crewAI","slug":"error-error-code-error-message-3763f8","errorCode":null,"errorMessage":"Error ({error_code}): {error_message}","messagePattern":"Error \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"BedrockKnowledgeBaseError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":246,"sourceCode":"\n            if \"nextToken\" in response:\n                response_object[\"nextToken\"] = response[\"nextToken\"]\n\n            if \"guardrailAction\" in response:\n                response_object[\"guardrailAction\"] = response[\"guardrailAction\"]\n\n            return json.dumps(response_object, indent=2)\n\n        except ClientError as e:\n            error_code = \"Unknown\"\n            error_message = str(e)\n\n            # Try to extract error code if available\n            if hasattr(e, \"response\") and \"Error\" in e.response:\n                error_code = e.response[\"Error\"].get(\"Code\", \"Unknown\")\n                error_message = e.response[\"Error\"].get(\"Message\", str(e))\n\n            raise BedrockKnowledgeBaseError(\n                f\"Error ({error_code}): {error_message}\"\n            ) from e\n        except Exception as e:\n            raise BedrockKnowledgeBaseError(f\"Unexpected error: {e!s}\") from e\n","sourceCodeStart":228,"sourceCodeEnd":251,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L228-L251","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nresult = tool._run(query)\n# after\nfrom crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKnowledgeBaseError\ntry:\n    result = tool._run(query)\nexcept BedrockKnowledgeBaseError as e:\n    msg = str(e)\n    if 'ThrottlingException' in msg:\n        time.sleep(2 ** attempt); result = tool._run(query)\n    else:\n        raise","handlingStrategy":"retry","validationCode":"import boto3\nsts = boto3.client('sts')\nsts.get_caller_identity()  # verifies credentials+region before running the tool","typeGuard":null,"tryCatchPattern":"from crewai_tools.aws.bedrock.knowledge_base.retriever_tool import BedrockKnowledgeBaseError\nfor attempt in range(4):\n    try:\n        out = tool._run(q); break\n    except BedrockKnowledgeBaseError as e:\n        msg = str(e)\n        if 'ThrottlingException' in msg and attempt < 3:\n            time.sleep(2 ** attempt); continue\n        raise","preventionTips":["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"],"tags":["aws","bedrock","client-error","iam"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}