crewAIInc/crewAI · error · BedrockValidationError
session_id must be a string
Error message
session_id must be a string
What it means
A BedrockValidationError raised when an optional session_id is provided but is not a string. session_id is optional (the check is `if self.session_id and not isinstance(...)`), so the error only fires when a truthy non-string value is supplied.
Source
Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py:87
self.description = description
self._validate_parameters()
def _validate_parameters(self) -> None:
"""Validate the parameters according to AWS API requirements."""
try:
if not self.agent_id:
raise BedrockValidationError("agent_id cannot be empty")
if not isinstance(self.agent_id, str):
raise BedrockValidationError("agent_id must be a string")
if not self.agent_alias_id:
raise BedrockValidationError("agent_alias_id cannot be empty")
if not isinstance(self.agent_alias_id, str):
raise BedrockValidationError("agent_alias_id must be a string")
if self.session_id and not isinstance(self.session_id, str):
raise BedrockValidationError("session_id must be a string")
except BedrockValidationError as e:
raise BedrockValidationError(f"Parameter validation failed: {e!s}") from e
def _run(self, query: str) -> str:
try:
import boto3
from botocore.exceptions import ClientError
except ImportError as e:
raise ImportError(
"`boto3` package not found, please run `uv add boto3`"
) from e
try:
# Initialize the Bedrock Agent Runtime client
bedrock_agent = boto3.client(
"bedrock-agent-runtime",
region_name=os.getenv(View on GitHub (pinned to 754d7323be)
Solutions
- Convert: `session_id=str(uuid.uuid4())`.
- If reusing an AWS-returned sessionId from a previous InvokeAgent response, take the raw string field.
- Omit session_id entirely if you do not need cross-invocation memory.
Example fix
# before tool = BedrockAgentTools(agent_id="ABCD123456", agent_alias_id="TSTALIASID", session_id=uuid.uuid4()) # after tool = BedrockAgentTools(agent_id="ABCD123456", agent_alias_id="TSTALIASID", session_id=str(uuid.uuid4()))
Defensive patterns
Strategy: type-guard
Validate before calling
if session_id is not None and not isinstance(session_id, str):
session_id = str(session_id) Type guard
def is_session_id(v) -> bool:
return v is None or isinstance(v, str) Try / catch
try:
tool = BedrockAgentTools(agent_id=aid, agent_alias_id=alias, session_id=sid)
except BedrockValidationError as e:
if "session_id must be a string" in str(e):
tool = BedrockAgentTools(agent_id=aid, agent_alias_id=alias, session_id=str(sid))
else:
raise Prevention
- Always wrap generated IDs: str(uuid.uuid4()).
- Omit session_id when session continuity is not needed.
- Reuse AWS-returned sessionId strings verbatim, not re-wrapped objects.
When it happens
Trigger: Constructing the tool with session_id as an int/UUID object/list — e.g. `session_id=uuid.uuid4()` (UUID object, not str) or a numeric session key from a database.
Common situations: Generating session IDs with uuid.uuid4() and forgetting str(); passing a pandas/numpy integer session key; reusing an internal session object instead of its string identifier.
Related errors
- agent_id must be a string
- agent_alias_id must be a string
- knowledge_base_id must be a string
- number_of_results must be an integer
- agent_id cannot be empty
AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15).
Data as JSON: /api/errors/092319b11c18df94.
Report an issue: GitHub.