{"record":{"id":"fb3d5df6d0020cdb","repo":"crewAIInc/crewAI","slug":"knowledge-base-id-cannot-be-empty","errorCode":null,"errorMessage":"knowledge_base_id cannot be empty","messagePattern":"knowledge_base_id cannot be empty","errorType":"validation","errorClass":"BedrockValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":93,"sourceCode":"\n    def _build_retrieval_configuration(self) -> dict[str, Any]:\n        \"\"\"Build the retrieval configuration based on provided parameters.\n\n        Returns:\n            Dict[str, Any]: The constructed retrieval configuration\n        \"\"\"\n        vector_search_config = {}\n\n        if self.number_of_results is not None:\n            vector_search_config[\"numberOfResults\"] = self.number_of_results\n\n        return {\"vectorSearchConfiguration\": vector_search_config}\n\n    def _validate_parameters(self) -> None:\n        \"\"\"Validate the parameters according to AWS API requirements.\"\"\"\n        try:\n            if not self.knowledge_base_id:\n                raise BedrockValidationError(\"knowledge_base_id cannot be empty\")\n            if not isinstance(self.knowledge_base_id, str):\n                raise BedrockValidationError(\"knowledge_base_id must be a string\")\n            if len(self.knowledge_base_id) > 10:\n                raise BedrockValidationError(\n                    \"knowledge_base_id must be 10 characters or less\"\n                )\n            if not all(c.isalnum() for c in self.knowledge_base_id):\n                raise BedrockValidationError(\n                    \"knowledge_base_id must contain only alphanumeric characters\"\n                )\n\n            if self.next_token:\n                if not isinstance(self.next_token, str):\n                    raise BedrockValidationError(\"next_token must be a string\")\n                if len(self.next_token) < 1 or len(self.next_token) > 2048:\n                    raise BedrockValidationError(\n                        \"next_token must be between 1 and 2048 characters\"\n                    )","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L75-L111","documentation":"A BedrockValidationError raised in BedrockKBRetrieverTool._validate_parameters when knowledge_base_id is falsy (None or ''). AWS Retrieve requires a knowledge base ID, so the tool refuses to construct without one; like the agent tool, the whole block is re-wrapped as \"Parameter validation failed: ...\" by the caller's except.","triggerScenarios":"Creating the KB retriever tool with knowledge_base_id='' or None — typically the ID was loaded from a missing env var/config and defaulted to empty.","commonSituations":"Env var (e.g. BEDROCK_KB_ID) not exported in the runtime environment; wrong attribute copied from the console (knowledge base name instead of the 10-char alphanumeric ID); multi-stage pipelines where the ID is conditionally set and the branch was skipped.","solutions":["Copy the Knowledge base ID from the Bedrock console (10 alphanumeric characters, e.g. 'HHTQ7DFZLV') and pass it explicitly.","Fail fast on config: knowledge_base_id=os.environ['BEDROCK_KB_ID'] instead of os.environ.get(...) or ''.","Check you are not passing the data source ID or collection ARN — those are different fields."],"exampleFix":"# before\ntool = BedrockKBRetrieverTool(knowledge_base_id=os.environ.get(\"BEDROCK_KB_ID\", \"\"))\n\n# after\ntool = BedrockKBRetrieverTool(knowledge_base_id=os.environ[\"BEDROCK_KB_ID\"])  # KeyError tells you the var is missing","handlingStrategy":"validation","validationCode":"import os, re\n\nkb_id = os.environ.get(\"BEDROCK_KB_ID\", \"\")\nif not kb_id:\n    raise SystemExit(\"BEDROCK_KB_ID not set — copy the Knowledge base ID from the Bedrock console\")","typeGuard":"def is_kb_id(v) -> bool:\n    return isinstance(v, str) and bool(v)","tryCatchPattern":"try:\n    tool = BedrockKBRetrieverTool(knowledge_base_id=kb_id)\nexcept BedrockValidationError as e:\n    raise ValueError(f\"Bad KB config: {e}\") from e","preventionTips":["Use os.environ[...] without defaults so missing config fails at startup.","Copy the 10-char Knowledge base ID from the console — not the name, data source ID, or ARN.","Add a config smoke test that constructs all Bedrock tools at deploy time."],"tags":["aws","bedrock","knowledge-base","validation","configuration"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}