{"record":{"id":"37b17cd0bbbf0dcd","repo":"crewAIInc/crewAI","slug":"number-of-results-must-be-an-integer","errorCode":null,"errorMessage":"number_of_results must be an integer","messagePattern":"number_of_results must be an integer","errorType":"validation","errorClass":"BedrockValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":117,"sourceCode":"                )\n            if not all(c.isalnum() for c in self.knowledge_base_id):\n                raise BedrockValidationError(\n                    \"knowledge_base_id must contain only alphanumeric characters\"\n                )\n\n            if self.next_token:\n                if not isinstance(self.next_token, str):\n                    raise BedrockValidationError(\"next_token must be a string\")\n                if len(self.next_token) < 1 or len(self.next_token) > 2048:\n                    raise BedrockValidationError(\n                        \"next_token must be between 1 and 2048 characters\"\n                    )\n                if \" \" in self.next_token:\n                    raise BedrockValidationError(\"next_token cannot contain spaces\")\n\n            if self.number_of_results is not None:\n                if not isinstance(self.number_of_results, int):\n                    raise BedrockValidationError(\"number_of_results must be an integer\")\n                if self.number_of_results < 1:\n                    raise BedrockValidationError(\n                        \"number_of_results must be greater than 0\"\n                    )\n\n        except BedrockValidationError as e:\n            raise BedrockValidationError(f\"Parameter validation failed: {e!s}\") from e\n\n    def _process_retrieval_result(self, result: dict[str, Any]) -> dict[str, Any]:\n        \"\"\"Process a single retrieval result from Bedrock Knowledge Base.\n\n        Args:\n            result (Dict[str, Any]): Raw result from Bedrock Knowledge Base\n\n        Returns:\n            Dict[str, Any]: Processed result with standardized format\n        \"\"\"\n        content_obj = result.get(\"content\", {})","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L99-L135","documentation":"Raised when number_of_results is provided to BedrockKnowledgeBaseRetrievalTool but is not an int (bool also passes isinstance but e.g. float or str fails). The tool validates the value client-side because the Bedrock Agent Runtime API requires an integer retrievalQueryResultCount. Note that Python bool is a subclass of int, so True/False pass this check.","triggerScenarios":"Passing number_of_results='5' (string from CLI/env var), 5.0 (float), or a numpy int64/float value to the constructor or tool input schema.","commonSituations":"Reading the value from os.environ or argparse without int conversion; loading config from JSON/YAML where the value parsed as float or string; passing results from a numpy computation.","solutions":["Convert to int at the boundary: int(number_of_results)","Validate config values after loading from files/env: number_of_results = int(value) if value else None","Use a Pydantic model for tool config so type coercion happens automatically"],"exampleFix":"# before\ntool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, number_of_results=os.getenv('KB_RESULTS'))\n# after\nresults = os.getenv('KB_RESULTS')\ntool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, number_of_results=int(results) if results else None)","handlingStrategy":"type-guard","validationCode":"if number_of_results is not None and not isinstance(number_of_results, int):\n    number_of_results = int(number_of_results)","typeGuard":"def is_valid_result_count(v: object) -> bool:\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and v >= 1)","tryCatchPattern":"except BedrockValidationError as e:\n    if 'number_of_results must be an integer' in str(e):\n        tool.number_of_results = int(tool.number_of_results)\n        out = tool._run(q)\n    else:\n        raise","preventionTips":["Convert env/CLI/config values with int() at load time","Type tool config with Pydantic so coercion is automatic","Never pass floats or numeric strings from JSON straight into the tool"],"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"}