{"record":{"id":"f2cb30fbc7bd2960","repo":"sgl-project/sglang","slug":"an-exception-occurred-while-loading-modality-name","errorCode":null,"errorMessage":"An exception occurred while loading {modality.name} data at index {idx}: {e}","messagePattern":"An exception occurred while loading (.+?) data at index (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/base_processor.py","lineNumber":1244,"sourceCode":"            )\n\n        logger.debug(\"[load_mm_data(simple)] total futures submitted: %d\", len(futures))\n\n        images: List[Any] = [None] * len(image_data) if image_data else []\n        videos: List[Any] = [None] * len(video_data) if video_data else []\n        audios: List[Any] = [None] * len(audio_data) if audio_data else []\n\n        for modality, idx, future in futures:\n            try:\n                result = await asyncio.wrap_future(future)\n            except ValueError as e:\n                logger.info(\n                    \"[load_mm_data(simple)] invalid %s data at index=%d: %s\",\n                    modality.name,\n                    idx,\n                    e,\n                )\n                raise ValueError(\n                    f\"An exception occurred while loading {modality.name} data \"\n                    f\"at index {idx}: {e}\"\n                ) from e\n            except Exception as e:\n                logger.exception(\n                    \"[load_mm_data(simple)] error loading %s data at index=%d\",\n                    modality.name,\n                    idx,\n                )\n                raise RuntimeError(\n                    f\"An exception occurred while loading {modality.name} data at index {idx}: {e}\"\n                )\n\n            if modality == Modality.IMAGE:\n                images[idx] = result\n            elif modality == Modality.VIDEO:\n                videos[idx] = result\n            elif modality == Modality.AUDIO:","sourceCodeStart":1226,"sourceCodeEnd":1262,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/base_processor.py#L1226-L1262","documentation":"In fast_load_mm_data, per-item load failures classified as invalid input (ValueError-family) are re-raised as ValueError with the modality name, index, and cause — preserving 'bad request' semantics for callers to map to a 4xx-style error.","triggerScenarios":"fast_load_mm_data encountering an item at index idx that fails validation/decoding with a ValueError-type error, e.g. malformed base64, wrong content type, unsupported scheme.","commonSituations":"Batch inference over user-submitted media where one item is malformed; frontend sending data URLs with typos ('data:image/png;base64!...').","solutions":["Use the index in the message to identify and fix/remove the offending item","Pre-validate each item (scheme, base64 header, file signature) before batching","Catch ValueError at the API layer and return a per-item error to the client rather than failing the batch"],"exampleFix":"// before\nawait processor.fast_load_mm_data(mm_data, ...)  # one bad item kills batch\n// after\nbad = [i for i, it in enumerate(items) if not looks_valid(it)]\nitems = [it for i, it in enumerate(items) if i not in bad]\nawait processor.fast_load_mm_data(mm_data, ...)","handlingStrategy":"try-catch","validationCode":"def looks_valid(item):\n    if isinstance(item, str):\n        return item.startswith(('http://','https://','data:')) or os.path.exists(item)\n    return item is not None","typeGuard":null,"tryCatchPattern":"try:\n    await processor.fast_load_mm_data(mm_data, ...)\nexcept ValueError as e:\n    if 'at index' in str(e):\n        idx = int(re.search(r'index (\\d+)', str(e)).group(1))\n        return per_item_error(idx, str(e))\n    raise","preventionTips":["Pre-validate each media item's scheme/format before batching","Map per-index ValueError to per-item client errors instead of failing whole batches"],"tags":["multimodal","loading","input-validation"],"backgroundTag":"media-load-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}