crewAIInc/crewAI · error · BedrockValidationError

knowledge_base_id must be 10 characters or less

Error message

knowledge_base_id must be 10 characters or less

What it means

A BedrockValidationError raised when knowledge_base_id exceeds 10 characters. AWS Bedrock knowledge base IDs are fixed at 10 alphanumeric characters, so the tool enforces len(knowledge_base_id) <= 10 during construction; failures are re-wrapped into "Parameter validation failed: knowledge_base_id must be 10 characters or less".

Source

Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py:97

        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"
                    )
                if " " in self.next_token:
                    raise BedrockValidationError("next_token cannot contain spaces")

            if self.number_of_results is not None:

View on GitHub (pinned to 754d7323be)

Solutions

  1. Use the bare 10-char ID (console > Knowledge bases > Knowledge base ID), not the name or ARN.
  2. Strip whitespace from config-sourced IDs: knowledge_base_id=raw.strip().
  3. If extracting from an ARN, take the segment after the last '/'.

Example fix

# before
tool = BedrockKBRetrieverTool(knowledge_base_id="arn:aws:bedrock:us-east-1:123456789012:knowledge-base/HHTQ7DFZLV")

# after
tool = BedrockKBRetrieverTool(knowledge_base_id="HHTQ7DFZLV")
Defensive patterns

Strategy: validation

Validate before calling

import re

if "/" in kb_id:  # ARN passed by mistake
    kb_id = kb_id.rsplit("/", 1)[-1]
if len(kb_id) > 10:
    raise ValueError(f"'{kb_id}' looks like a name/ARN, not a 10-char KB ID")

Type guard

def is_kb_id(v) -> bool:
    return isinstance(v, str) and len(v) <= 10

Try / catch

try:
    tool = BedrockKBRetrieverTool(knowledge_base_id=kb_id)
except BedrockValidationError as e:
    if "10 characters or less" in str(e):
        raise ValueError("You likely passed a KB name or ARN — use the 10-char ID") from e
    raise

Prevention

When it happens

Trigger: Passing a string longer than 10 chars: a knowledge base name, an ARN ('arn:aws:bedrock:...:knowledge-base/XXXX'), a UUID, or an ID with extra whitespace/paste artifacts.

Common situations: Copying the human-readable KB name or full ARN from the console instead of the short ID; concatenating a prefix like 'kb-' onto the ID; trailing newline from a config file.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/4e85d6fe3a8961a4. Report an issue: GitHub.