sgl-project/sglang · error · ValueError
Image placeholder count does not match image_data
Error message
Image placeholder count does not match image_data
What it means
Raised by _merge_video_media when a rendered image marker is found in the prompt but the iterator over natively supplied image_data is exhausted. The number of image placeholders produced by video rendering must match the count of provided images.
Source
Thrown at python/sglang/srt/multimodal/processors/dots_note_omni.py:335
pattern = re.compile(
f"({native_pattern.pattern}|{_EXPANDED_VIDEO_MEDIA_RE.pattern})"
)
rendered = []
last = 0
for match in pattern.finditer(input_text):
rendered.append(input_text[last : match.start()])
marker = match.group(0)
expanded_media = video_media.get(marker)
if expanded_media is not None:
modality, value = expanded_media
else:
modality = self.mm_tokens.get_modality_of_token(marker)
if modality == Modality.IMAGE:
try:
value = next(native_images)
except StopIteration as exc:
raise ValueError(
"Image placeholder count does not match image_data"
) from exc
elif modality == Modality.AUDIO:
try:
value = next(native_audios)
except StopIteration as exc:
raise ValueError(
"Audio placeholder count does not match audio_data"
) from exc
else:
raise ValueError(f"Unsupported dots omni media marker: {marker}")
if modality == Modality.IMAGE:
ordered_images.append(value)
rendered.append(
self.image_start_token + self.image_token + self.image_end_token
)
else:View on GitHub (pinned to 0132848349)
Solutions
- Align the number of image placeholders in the prompt/video content with len(image_data)
- Pass keyframe images explicitly in image_data when your template references them
- Update sglang — renderer/marker logic is covered by tests and may already be fixed for your template
Example fix
// before image_data = [] # template has 2 image markers // after image_data = [frame1, frame2] # one per marker
Defensive patterns
Strategy: validation
Validate before calling
img_markers = prompt.count(IMAGE_TOKEN) + rendered_video_image_markers
assert img_markers == len(image_data), f'{img_markers} markers vs {len(image_data)} images' Try / catch
try:
await processor.process_mm_data_async(...)
except ValueError as e:
if 'placeholder count does not match' in str(e):
# recount markers vs media and rebuild the request
... Prevention
- Count markers vs media lengths before each request
- Avoid hand-editing prompts containing media tokens
When it happens
Trigger: A video's preprocessed content emits more image markers than there are entries in the request's image_data list — e.g. the prompt/template adds image placeholders while image_data is empty or shorter.
Common situations: Chat template inserts extra image tokens for the video keyframes, but the client sent no image_data; or counts drift after editing the prompt. The bundled tests exercise this exact mismatch path.
Related errors
- Audio placeholder count does not match audio_data
- Video placeholder count does not match video_data: {len(vide
- An exception occurred while loading multimodal data: {e}
- prompt has {num_placeholders} image placeholder token(s) but
- processor image placeholder count mismatch: processor={proce
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/2806fce54aeb168e.
Report an issue: GitHub.