sgl-project/sglang · error · ValueError
An exception occurred while loading {modality.name} data at
Error message
An exception occurred while loading {modality.name} data at index {idx}: {e} What it means
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.
Source
Thrown at python/sglang/srt/multimodal/processors/base_processor.py:1244
)
logger.debug("[load_mm_data(simple)] total futures submitted: %d", len(futures))
images: List[Any] = [None] * len(image_data) if image_data else []
videos: List[Any] = [None] * len(video_data) if video_data else []
audios: List[Any] = [None] * len(audio_data) if audio_data else []
for modality, idx, future in futures:
try:
result = await asyncio.wrap_future(future)
except ValueError as e:
logger.info(
"[load_mm_data(simple)] invalid %s data at index=%d: %s",
modality.name,
idx,
e,
)
raise ValueError(
f"An exception occurred while loading {modality.name} data "
f"at index {idx}: {e}"
) from e
except Exception as e:
logger.exception(
"[load_mm_data(simple)] error loading %s data at index=%d",
modality.name,
idx,
)
raise RuntimeError(
f"An exception occurred while loading {modality.name} data at index {idx}: {e}"
)
if modality == Modality.IMAGE:
images[idx] = result
elif modality == Modality.VIDEO:
videos[idx] = result
elif modality == Modality.AUDIO:View on GitHub (pinned to 0132848349)
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
Example fix
// before await processor.fast_load_mm_data(mm_data, ...) # one bad item kills batch // after bad = [i for i, it in enumerate(items) if not looks_valid(it)] items = [it for i, it in enumerate(items) if i not in bad] await processor.fast_load_mm_data(mm_data, ...)
Defensive patterns
Strategy: try-catch
Validate before calling
def looks_valid(item):
if isinstance(item, str):
return item.startswith(('http://','https://','data:')) or os.path.exists(item)
return item is not None Try / catch
try:
await processor.fast_load_mm_data(mm_data, ...)
except ValueError as e:
if 'at index' in str(e):
idx = int(re.search(r'index (\d+)', str(e)).group(1))
return per_item_error(idx, str(e))
raise Prevention
- Pre-validate each media item's scheme/format before batching
- Map per-index ValueError to per-item client errors instead of failing whole batches
When it happens
Trigger: 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.
Common situations: Batch inference over user-submitted media where one item is malformed; frontend sending data URLs with typos ('data:image/png;base64!...').
Related errors
- Error while loading data {data_str}: {e}
- Unsupported image type: {type(image)}
- When using multiple prompts with multiple input images, prov
- {key}.position_ids is required
- {key}.{field} is required
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/f2cb30fbc7bd2960.
Report an issue: GitHub.