crewAIInc/crewAI · error · BedrockValidationError

agent_alias_id must be a string

Error message

agent_alias_id must be a string

What it means

A BedrockValidationError raised when agent_alias_id is truthy but not a str. It is the type counterpart of the empty check for agent_alias_id and is re-wrapped by the except clause into "Parameter validation failed: agent_alias_id must be a string".

Source

Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py:84

        self.end_session = end_session

        if description:
            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

View on GitHub (pinned to 754d7323be)

Solutions

  1. Pass the string field: response['agentAlias']['agentAliasId'] if using boto3 responses.
  2. Coerce with str() at the boundary when the config source is not typed.
  3. Type your config with pydantic (agent_alias_id: str) so bad values fail at config load, not tool init.

Example fix

# before
alias = boto3.client("bedrock-agent").create_agent_alias(...)  # dict
tool = BedrockAgentTools(agent_id="ABCD123456", agent_alias_id=alias)

# after
tool = BedrockAgentTools(agent_id="ABCD123456", agent_alias_id=alias["agentAlias"]["agentAliasId"])
Defensive patterns

Strategy: type-guard

Validate before calling

if alias is not None and not isinstance(alias, str):
    alias = str(alias)

Type guard

def is_agent_alias_id(v) -> bool:
    return isinstance(v, str) and len(v) > 0

Try / catch

try:
    tool = BedrockAgentTools(agent_id=aid, agent_alias_id=alias)
except BedrockValidationError as e:
    if "agent_alias_id must be a string" in str(e):
        tool = BedrockAgentTools(agent_id=aid, agent_alias_id=str(alias))
    else:
        raise

Prevention

When it happens

Trigger: Passing a non-string truthy agent_alias_id (int, list, dict) to BedrockAgentTools — for example a numeric alias identifier loaded from config without string coercion.

Common situations: Machine-generated configs where IDs stay numeric; passing the whole alias object/dict returned by boto3's create_agent_alias instead of its 'agentAliasId' field.

Related errors


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