{"record":{"id":"c5e4d90bf6b48af5","repo":"BerriAI/litellm","slug":"input-must-be-a-list-of-strings-c5e4d9","errorCode":null,"errorMessage":"Input must be a list of strings","messagePattern":"Input must be a list of strings","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"litellm/llms/sagemaker/embedding/cohere_transformation.py","lineNumber":75,"sourceCode":"\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | Headers) -> BaseLLMException:\n        return SagemakerError(message=error_message, status_code=status_code, headers=headers)\n\n    def transform_embedding_request(\n        self,\n        model: str,\n        input: \"AllEmbeddingInputValues\",\n        optional_params: dict,\n        headers: dict,\n    ) -> dict:\n        \"\"\"\n        Transform embedding request for Cohere models on SageMaker\n        \"\"\"\n        if isinstance(input, str):\n            input_list: list[str] = [input]\n        elif isinstance(input, list):\n            if input and (isinstance(input[0], list) or isinstance(input[0], int)):\n                raise ValueError(\"Input must be a list of strings\")\n            input_list = cast(list[str], input)\n        else:\n            input_list = [str(input)]\n\n        return dict(\n            BedrockCohereEmbeddingConfig()._transform_request(\n                model=model,\n                input=input_list,\n                inference_params=optional_params,\n            )\n        )\n\n    def transform_embedding_response(\n        self,\n        model: str,\n        raw_response: Response,\n        model_response: \"EmbeddingResponse\",\n        logging_obj: Any,","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/sagemaker/embedding/cohere_transformation.py#L57-L93","documentation":"The Cohere-on-SageMaker embedding config validates that input is either a single string or a flat list of strings. If the list's first element is itself a list or an int, it raises ValueError before any request is sent, because the Cohere SageMaker endpoint only accepts an array of strings.","triggerScenarios":"Calling litellm.embedding(model='sagemaker/<cohere-embed-...>', input=[[...tokens...], ...]) with pre-tokenized int lists, or nested batches like input=[['a', 'b'], ['c']].","commonSituations":"Porting code from OpenAI-style token-array inputs (list of int token ids); passing a numpy array converted via .tolist() that yields nested lists; batch helpers that wrap inputs one level too deep.","solutions":["Pass a flat list of strings: input=['doc one', 'doc two'], or a single string.","If inputs arrive nested, flatten one level before calling: input=[t for row in inputs for t in row] or drop the outer list.","If you have token ids, decode them back to text before calling the embedding endpoint."],"exampleFix":"# before\nlitellm.embedding(model='sagemaker/cohere-embed-english-v3', input=[[1, 2, 3], [4, 5, 6]])\n# after\nlitellm.embedding(model='sagemaker/cohere-embed-english-v3', input=['hello world', 'second doc'])","handlingStrategy":"type-guard","validationCode":"def flatten_embedding_inputs(x) -> list[str]:\n    if isinstance(x, str):\n        return [x]\n    if isinstance(x, list):\n        flat = []\n        for item in x:\n            if isinstance(item, list):\n                flat.extend(str(i) for i in item)\n            else:\n                flat.append(str(item))\n        return flat\n    return [str(x)]","typeGuard":"from typing import Any\n\ndef is_flat_str_list(v: Any) -> bool:\n    return isinstance(v, list) and len(v) > 0 and all(isinstance(i, str) for i in v)","tryCatchPattern":null,"preventionTips":["Always build embedding inputs as list[str]; never pass token id lists to sagemaker cohere models.","Normalize inputs through one helper before every embedding call."],"tags":["sagemaker","cohere","embedding","input-validation"],"backgroundTag":"invalid-input-type","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}