{"record":{"id":"baa861c6fee66d4f","repo":"crewAIInc/crewAI","slug":"next-token-cannot-contain-spaces","errorCode":null,"errorMessage":"next_token cannot contain spaces","messagePattern":"next_token cannot contain spaces","errorType":"validation","errorClass":"BedrockValidationError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py","lineNumber":113,"sourceCode":"                raise BedrockValidationError(\"knowledge_base_id must be a string\")\n            if len(self.knowledge_base_id) > 10:\n                raise BedrockValidationError(\n                    \"knowledge_base_id must be 10 characters or less\"\n                )\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","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/aws/bedrock/knowledge_base/retriever_tool.py#L95-L131","documentation":"Raised when the next_token value contains a space character. AWS pagination tokens are opaque single-token strings; embedded whitespace breaks them, so the tool rejects them client-side with BedrockValidationError before calling bedrock-agent-runtime. It is one of the next_token validation chain checks (string, length, no spaces).","triggerScenarios":"A token pasted from logs/terminal with an accidental space, a token wrapped or joined with spaces (' '.join(tokens)), or line-wrapped copies inserting spaces into BedrockKnowledgeBaseRetrievalTool(next_token=...).","commonSituations":"Copy-paste from wrapped terminal output or log lines that soft-wrap; concatenating token fragments; passing user-typed input directly as the token.","solutions":["Strip or remove whitespace: next_token.replace(' ', '') only if you know it was paste corruption; otherwise re-fetch a fresh token","Copy tokens from raw JSON output rather than rendered logs","Pass response['nextToken'] programmatically instead of via copy-paste"],"exampleFix":"# before\ntool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, next_token=copied_token)\n# after\nif copied_token and ' ' not in copied_token:\n    tool = BedrockKnowledgeBaseRetrievalTool(knowledge_base_id=kb_id, next_token=copied_token)","handlingStrategy":"validation","validationCode":"if token and ' ' in token:\n    raise ValueError('next_token contains spaces; re-copy from the raw response JSON')","typeGuard":"def is_space_free_token(t: str) -> bool:\n    return ' ' not in t","tryCatchPattern":"except BedrockValidationError as e:\n    if 'cannot contain spaces' in str(e):\n        tool.next_token = None\n        out = tool._run(q)  # restart from first page\n    else:\n        raise","preventionTips":["Copy tokens from raw JSON (jq/curl output), not rendered logs","Never concatenate or wrap tokens","Programmatically chain pagination instead of copy-paste"],"tags":["aws","bedrock","validation","pagination"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}