{"record":{"id":"cec448f7016f1473","repo":"sgl-project/sglang","slug":"invalid-image-data-image-data","errorCode":null,"errorMessage":"Invalid image data: {image_data}","messagePattern":"Invalid image data: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/llava.py","lineNumber":240,"sourceCode":"                        self._process_single_image(\n                            img_data, aspect_ratio, grid_pinpoints\n                        )\n                    )\n\n                res = await asyncio.gather(*res)\n                for pixel_v, image_h, image_s in res:\n                    pixel_values.append(pixel_v)\n                    data_hashes.append(image_h)\n                    image_sizes.append(image_s)\n            else:\n                # A single image\n                pixel_values, image_hash, image_size = await self._process_single_image(\n                    image_data[0], aspect_ratio, grid_pinpoints\n                )\n                pixel_values = [pixel_values]\n                image_sizes = [image_size]\n        else:\n            raise ValueError(f\"Invalid image data: {image_data}\")\n        modality = Modality.IMAGE\n        if isinstance(request_obj.modalities, list):\n            if request_obj.modalities[0] == \"video\":\n                modality = Modality.VIDEO\n\n        # Create one item per image for better cache granularity\n        mm_items = []\n        for pixel_v, image_s in zip(pixel_values, image_sizes):\n            # Ensure ndim=4 so the model forward takes the correct encode branch\n            if isinstance(pixel_v, np.ndarray) and pixel_v.ndim == 3:\n                pixel_v = np.expand_dims(pixel_v, 0)\n            mm_items.append(\n                MultimodalDataItem(\n                    feature=pixel_v,\n                    model_specific_data={\n                        \"image_sizes\": [image_s],\n                        \"image_aspect_ratio\": aspect_ratio,\n                    },","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/llava.py#L222-L258","documentation":"The LLaVA processor dispatches on the type of image_data: a list, a single string/URL, etc. If image_data does not match any known shape (not a list, not a string, not None in the expected branch), the processor rejects it as invalid.","triggerScenarios":"Passing image_data of an unsupported type to process_mm_data_async, e.g. an int, dict, raw bytes, or a numpy array instead of the expected list of images/URLs or a single URL string.","commonSituations":"Client serializes images to base64 bytes or wraps them in a dict like {\"url\": ...} and passes that directly; or passes None through a code path that reaches the else branch.","solutions":["Pass image_data as a list of image URLs / PIL images / base64 strings, or a single URL string","If using bytes, encode to a data URI or base64 string as the API expects","Inspect the type of image_data right before the call and normalize it"],"exampleFix":"# before\nimage_data = {\"url\": \"https://example.com/cat.png\"}  # dict -> error\n# after\nimage_data = [\"https://example.com/cat.png\"]","handlingStrategy":"type-guard","validationCode":"ok = image_data is None or isinstance(image_data, (str, list)) and all(isinstance(i, (str, bytes)) for i in (image_data if isinstance(image_data, list) else []))","typeGuard":"def is_valid_image_data(d) -> bool:\n    if d is None: return True\n    if isinstance(d, str): return True\n    if isinstance(d, list): return all(isinstance(i, (str, bytes)) for i in d)\n    return False","tryCatchPattern":null,"preventionTips":["Normalize all client images to a list of URL/base64 strings before calling the API","Never pass dicts or raw ints as image_data"],"tags":["multimodal","llava","image-input","type-validation"],"backgroundTag":"invalid-multimodal-input-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}