{"record":{"id":"35b999c994e775f7","repo":"crewAIInc/crewAI","slug":"unexpected-error-e-s-35b999","errorCode":null,"errorMessage":"Unexpected error: {e!s}","messagePattern":"Unexpected error: (.+?)","errorType":"exception","errorClass":"BedrockKnowledgeBaseError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":250,"sourceCode":"            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":232,"sourceCodeEnd":251,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L232-L251","documentation":"The final except in BedrockKnowledgeBaseRetrievalTool._run(): any non-ClientError exception raised during client creation, the retrieve call, or response processing is re-raised as BedrockKnowledgeBaseError('Unexpected error: ...') with the original chained. Typical culprits are credential chain errors, response shape surprises (KeyError/TypeError on the response dict), or region config problems that botocore raises as non-ClientError exceptions.","triggerScenarios":"NoRegionError from botocore when region resolution fails; NoCredentialsError/PartialCredentialsError; a response missing an expected key causing KeyError in result processing; TypeError from unexpected payload shapes.","commonSituations":"Running in containers/CI without an AWS config file or region env var; assuming a credential profile that doesn't exist; AWS API response format changes breaking result parsing.","solutions":["Read the chained exception (e.__cause__) to see the real error: NoRegionError -> set AWS_REGION; NoCredentialsError -> configure credentials/instance role","Wrap the call and log e.__cause__ for diagnosis","For parsing failures, dump the raw boto3 response and compare with the expected shape"],"exampleFix":"# before\ntry:\n    out = tool._run(q)\nexcept BedrockKnowledgeBaseError as e:\n    print(e)\n# after\ntry:\n    out = tool._run(q)\nexcept BedrockKnowledgeBaseError as e:\n    logger.error('KB retrieve failed: %s', e.__cause__ or e)\n    raise","handlingStrategy":"try-catch","validationCode":"import os\nfor var in ('AWS_REGION', 'AWS_DEFAULT_REGION'):\n    if os.getenv(var): break\nelse:\n    os.environ['AWS_REGION'] = 'us-east-1'  # prevent NoRegionError","typeGuard":null,"tryCatchPattern":"except BedrockKnowledgeBaseError as e:\n    cause = e.__cause__\n    logger.error('unexpected KB error: %s', cause or e)\n    if isinstance(cause, (botocore.exceptions.NoCredentialsError, botocore.exceptions.NoRegionError)):\n        raise SystemExit('fix AWS config') from e\n    raise","preventionTips":["Always inspect __cause__ — the wrapper message alone is not diagnostic","Configure region and credentials in env/instance role before runs","Log the raw exception chain in monitoring to classify root causes"],"tags":["aws","bedrock","credentials","unexpected"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}