{"record":{"id":"0296f6f759100288","repo":"crewAIInc/crewAI","slug":"agent-alias-id-must-be-a-string","errorCode":null,"errorMessage":"agent_alias_id must be a string","messagePattern":"agent_alias_id must be a string","errorType":"validation","errorClass":"BedrockValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py","lineNumber":84,"sourceCode":"        self.end_session = end_session\n\n        if description:\n            self.description = description\n\n        self._validate_parameters()\n\n    def _validate_parameters(self) -> None:\n        \"\"\"Validate the parameters according to AWS API requirements.\"\"\"\n        try:\n            if not self.agent_id:\n                raise BedrockValidationError(\"agent_id cannot be empty\")\n            if not isinstance(self.agent_id, str):\n                raise BedrockValidationError(\"agent_id must be a string\")\n\n            if not self.agent_alias_id:\n                raise BedrockValidationError(\"agent_alias_id cannot be empty\")\n            if not isinstance(self.agent_alias_id, str):\n                raise BedrockValidationError(\"agent_alias_id must be a string\")\n\n            if self.session_id and not isinstance(self.session_id, str):\n                raise BedrockValidationError(\"session_id must be a string\")\n\n        except BedrockValidationError as e:\n            raise BedrockValidationError(f\"Parameter validation failed: {e!s}\") from e\n\n    def _run(self, query: str) -> str:\n        try:\n            import boto3\n            from botocore.exceptions import ClientError\n        except ImportError as e:\n            raise ImportError(\n                \"`boto3` package not found, please run `uv add boto3`\"\n            ) from e\n\n        try:\n            # Initialize the Bedrock Agent Runtime client","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py#L66-L102","documentation":"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\".","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the string field: response['agentAlias']['agentAliasId'] if using boto3 responses.","Coerce with str() at the boundary when the config source is not typed.","Type your config with pydantic (agent_alias_id: str) so bad values fail at config load, not tool init."],"exampleFix":"# before\nalias = boto3.client(\"bedrock-agent\").create_agent_alias(...)  # dict\ntool = BedrockAgentTools(agent_id=\"ABCD123456\", agent_alias_id=alias)\n\n# after\ntool = BedrockAgentTools(agent_id=\"ABCD123456\", agent_alias_id=alias[\"agentAlias\"][\"agentAliasId\"])","handlingStrategy":"type-guard","validationCode":"if alias is not None and not isinstance(alias, str):\n    alias = str(alias)","typeGuard":"def is_agent_alias_id(v) -> bool:\n    return isinstance(v, str) and len(v) > 0","tryCatchPattern":"try:\n    tool = BedrockAgentTools(agent_id=aid, agent_alias_id=alias)\nexcept BedrockValidationError as e:\n    if \"agent_alias_id must be a string\" in str(e):\n        tool = BedrockAgentTools(agent_id=aid, agent_alias_id=str(alias))\n    else:\n        raise","preventionTips":["Extract string fields from boto3 responses (['agentAlias']['agentAliasId']).","Coerce non-str IDs with str() at the call site.","Keep config typed with pydantic strings."],"tags":["aws","bedrock","validation","type-error"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}