{"record":{"id":"438337f5fab0dc83","repo":"sgl-project/sglang","slug":"extra-key-should-be-a-list-or-a-string","errorCode":null,"errorMessage":"extra_key should be a list or a string.","messagePattern":"extra_key should be a list or a string\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/managers/io_struct.py","lineNumber":797,"sourceCode":"\n    def _normalize_extra_key(self, num):\n        \"\"\"Normalize extra_key for batch processing.\"\"\"\n        if self.extra_key is None:\n            return\n        if isinstance(self.extra_key, str):\n            value = self.extra_key or None\n            self.extra_key = [value] * num\n        elif isinstance(self.extra_key, list):\n            if len(self.extra_key) != self.batch_size:\n                raise ValueError(\n                    \"The length of extra_key should be equal to the batch size.\"\n                )\n            if any(not isinstance(value, str) for value in self.extra_key):\n                raise ValueError(\"Every extra_key should be a string.\")\n            self.extra_key = [value or None for value in self.extra_key]\n            self.extra_key = self.extra_key * self.parallel_sample_num\n        else:\n            raise ValueError(\"extra_key should be a list or a string.\")\n\n    def _normalize_cache_salt(self, num):\n        \"\"\"Normalize cache_salt for batch processing.\"\"\"\n        if self.cache_salt is None:\n            return\n        if isinstance(self.cache_salt, str):\n            value = self.cache_salt or None\n            self.cache_salt = [value] * num\n        elif isinstance(self.cache_salt, list):\n            if len(self.cache_salt) != self.batch_size:\n                raise ValueError(\n                    \"The length of cache_salt should be equal to the batch size.\"\n                )\n            if any(not isinstance(value, str) for value in self.cache_salt):\n                raise ValueError(\"Every cache_salt should be a string.\")\n            self.cache_salt = [value or None for value in self.cache_salt]\n            self.cache_salt = self.cache_salt * self.parallel_sample_num\n        else:","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/managers/io_struct.py#L779-L815","documentation":"Raised when extra_key is neither a str nor a list. _normalize_extra_key only supports a single string (broadcast to all requests) or a per-request list of strings; any other type (int, dict, tuple) is rejected.","triggerScenarios":"GenerateReqInput(..., extra_key=123) or extra_key={'k':'v'} or a tuple of keys.","commonSituations":"Passing a numeric hash or dict-shaped cache key; refactor changed extra_key from flexible type to str/list only.","solutions":["Pass a single str to use the same key for the whole batch","Pass a list[str] with len == batch_size"],"exampleFix":"// before\nextra_key=12345\n// after\nextra_key='12345'","handlingStrategy":"type-guard","validationCode":"if not isinstance(extra_key, (str, list)):\n    extra_key = str(extra_key)","typeGuard":"def valid_extra_key(k): return k is None or isinstance(k, (str, list))","tryCatchPattern":null,"preventionTips":["Treat extra_key API as str | list[str] | None only"],"tags":["sglang","extra-key","type-error","input-validation"],"backgroundTag":"request-input-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}