{"record":{"id":"6596f7f9344e4275","repo":"crewAIInc/crewAI","slug":"number-of-results-must-be-greater-than-0","errorCode":null,"errorMessage":"number_of_results must be greater than 0","messagePattern":"number_of_results must be greater than 0","errorType":"validation","errorClass":"BedrockValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":119,"sourceCode":"                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\", {})\n        content = content_obj.get(\"text\", \"\")\n        content_type = content_obj.get(\"type\", \"text\")","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L101-L137","documentation":"Raised when number_of_results is an int but is less than 1 (e.g. 0 or negative). Bedrock's retrieve API requires a positive result count; the tool enforces this client-side with BedrockValidationError. Note there is no upper-bound check here, so values above the AWS limit surface later as a ClientError instead.","triggerScenarios":"Passing number_of_results=0 (often as an 'unset' sentinel), a negative value from config arithmetic, or a decrement bug producing 0.","commonSituations":"Using 0 as a default/unset value in config; computing the value as max(0, n) or len(results) - 1 which can go to 0; math rounding down small fractions to 0.","solutions":["Use None instead of 0 to mean 'not set'","Clamp to a sane positive default: max(1, number_of_results)","Fix the arithmetic that can produce 0/negative values"],"exampleFix":"# before\ntool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, number_of_results=max(0, user_limit))\n# after\ntool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, number_of_results=max(1, user_limit))","handlingStrategy":"validation","validationCode":"if number_of_results is not None:\n    number_of_results = max(1, int(number_of_results))","typeGuard":"def is_positive_int(v: object) -> bool:\n    return isinstance(v, int) and v >= 1","tryCatchPattern":"except BedrockValidationError as e:\n    if 'greater than 0' in str(e):\n        tool.number_of_results = 5  # sane default\n        out = tool._run(q)\n    else:\n        raise","preventionTips":["Use None, not 0, as the 'unset' sentinel","Clamp computed limits with max(1, n)","Validate config ranges once at startup"],"tags":["aws","bedrock","validation"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}