crewAIInc/crewAI · error · BedrockValidationError
knowledge_base_id cannot be empty
Error message
knowledge_base_id cannot be empty
What it means
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.
Source
Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py:93
def _build_retrieval_configuration(self) -> dict[str, Any]:
"""Build the retrieval configuration based on provided parameters.
Returns:
Dict[str, Any]: The constructed retrieval configuration
"""
vector_search_config = {}
if self.number_of_results is not None:
vector_search_config["numberOfResults"] = self.number_of_results
return {"vectorSearchConfiguration": vector_search_config}
def _validate_parameters(self) -> None:
"""Validate the parameters according to AWS API requirements."""
try:
if not self.knowledge_base_id:
raise BedrockValidationError("knowledge_base_id cannot be empty")
if not isinstance(self.knowledge_base_id, str):
raise BedrockValidationError("knowledge_base_id must be a string")
if len(self.knowledge_base_id) > 10:
raise BedrockValidationError(
"knowledge_base_id must be 10 characters or less"
)
if not all(c.isalnum() for c in self.knowledge_base_id):
raise BedrockValidationError(
"knowledge_base_id must contain only alphanumeric characters"
)
if self.next_token:
if not isinstance(self.next_token, str):
raise BedrockValidationError("next_token must be a string")
if len(self.next_token) < 1 or len(self.next_token) > 2048:
raise BedrockValidationError(
"next_token must be between 1 and 2048 characters"
)View on GitHub (pinned to 754d7323be)
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.
Example fix
# before
tool = BedrockKBRetrieverTool(knowledge_base_id=os.environ.get("BEDROCK_KB_ID", ""))
# after
tool = BedrockKBRetrieverTool(knowledge_base_id=os.environ["BEDROCK_KB_ID"]) # KeyError tells you the var is missing Defensive patterns
Strategy: validation
Validate before calling
import os, re
kb_id = os.environ.get("BEDROCK_KB_ID", "")
if not kb_id:
raise SystemExit("BEDROCK_KB_ID not set — copy the Knowledge base ID from the Bedrock console") Type guard
def is_kb_id(v) -> bool:
return isinstance(v, str) and bool(v) Try / catch
try:
tool = BedrockKBRetrieverTool(knowledge_base_id=kb_id)
except BedrockValidationError as e:
raise ValueError(f"Bad KB config: {e}") from e Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- agent_id cannot be empty
- agent_alias_id cannot be empty
- knowledge_base_id must be a string
- knowledge_base_id must be 10 characters or less
- knowledge_base_id must contain only alphanumeric characters
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/fb3d5df6d0020cdb.
Report an issue: GitHub.