{"record":{"id":"2d11ce6cf5c8e523","repo":"sgl-project/sglang","slug":"an-exception-occurred-while-loading-multimodal-dat","errorCode":null,"errorMessage":"An exception occurred while loading multimodal data: {e}","messagePattern":"An exception occurred while loading multimodal data: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/base_processor.py","lineNumber":1386,"sourceCode":"                        new_text_parts += mm_tokens\n                    elif modality == Modality.AUDIO:\n                        # audio\n                        mm_tokens = (\n                            text_part\n                            if is_precomputed\n                            else multimodal_tokens.audio_token\n                        )\n                        new_text_parts += mm_tokens\n                else:\n                    # normal text\n                    new_text_parts += [text_part]\n\n            except StopIteration as e:\n                # when precomputed_input is presented with multi-images, StopIteration is expected\n                if has_precomputed_input:\n                    new_text_parts += [text_part]\n                    continue\n                raise RuntimeError(\n                    f\"An exception occurred while loading multimodal data: {e}\"\n                )\n            except ValueError as e:\n                raise ValueError(\n                    f\"An exception occurred while loading multimodal data: {e}\"\n                ) from e\n            except Exception as e:\n                raise RuntimeError(\n                    f\"An exception occurred while loading multimodal data: {e}\"\n                )\n        return BaseMultiModalProcessorOutput(\n            images=images,\n            audios=audios,\n            videos=videos,\n            input_text=\"\".join(new_text_parts),\n            input_ids=input_ids,\n        )\n","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/base_processor.py#L1368-L1404","documentation":"In the legacy template-based loader, a StopIteration while advancing the media iterator is expected only when a precomputed input is supplied with multi-image prompts; otherwise it means the prompt contained more media placeholders than available media items, re-raised as RuntimeError.","triggerScenarios":"Using legacy_load_mm_data where the prompt's <image>/<audio> placeholder count exceeds the number of supplied media items, and no precomputed input path is active.","commonSituations":"Hand-written prompt templates with extra placeholder tags; chat templates that inject a placeholder per turn while the user attached fewer files; multi-image prompts built by string concatenation.","solutions":["Make placeholder count in the prompt equal the number of media items","Let the model's chat template generate the prompt instead of hand-writing placeholders","If using precomputed embeddings with multi-image, ensure the precomputed input path is correctly detected (has_precomputed_input)"],"exampleFix":"// before\nprompt = '<image> and <image>'  # 2 placeholders, 1 image\n// after\nprompt = '<image>'  # matches len(images)","handlingStrategy":"validation","validationCode":"n_placeholders = prompt.count('<image>') + prompt.count('<audio>') + prompt.count('<video>')\nn_media = sum(len(v) for v in (images or []) + (audios or []) + (videos or []))\nassert n_placeholders == n_media or has_precomputed, (n_placeholders, n_media)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate prompts via the model's chat template rather than hand-writing placeholders","Count placeholders before submitting multi-media requests"],"tags":["multimodal","prompt-template","placeholder-mismatch","legacy"],"backgroundTag":"placeholder-count-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}