{"record":{"id":"236abf349ec52242","repo":"sgl-project/sglang","slug":"invalid-modality-modality","errorCode":null,"errorMessage":"Invalid modality: {modality}","messagePattern":"Invalid modality: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/disaggregation/encoder/receiver.py","lineNumber":590,"sourceCode":"            self._set_video_meta_for_part(part_idx, kwargs)\n        if modality == Modality.IMAGE:\n            self._set_image_meta_for_part(part_idx, kwargs)\n\n    def _set_image_meta_for_part(self, part_idx, source):\n        for attr_name in _GENERAL_IMAGE_META_ATTRS:\n            val = (\n                source.get(attr_name)\n                if isinstance(source, dict)\n                else getattr(source, attr_name, None)\n            )\n            if val is not None:\n                getattr(self, attr_name)[part_idx] = val\n\n    def _set_part_grid(self, part_idx, modality, grid):\n        \"\"\"Set the grid for one part according to modality (IMAGE/VIDEO/AUDIO).\"\"\"\n        spec = _MODALITY_GRID_ATTRS.get(modality)\n        if spec is None:\n            raise ValueError(f\"Invalid modality: {modality}\")\n        attr_name, flatten = spec\n        value = grid.flatten() if flatten else grid\n        getattr(self, attr_name)[part_idx] = value\n\n    def _set_video_meta_for_part(self, part_idx, source):\n        \"\"\"Copy video_timestamps and second_per_grid_ts from source (dict or object).\"\"\"\n        for attr_name in self.video_meta_attrs:\n            val = (\n                source.get(attr_name)\n                if isinstance(source, dict)\n                else getattr(source, attr_name, None)\n            )\n            if val is not None:\n                getattr(self, attr_name)[part_idx] = val\n\n    @classmethod\n    def from_embedding_data(\n        cls,","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/disaggregation/encoder/receiver.py#L572-L608","documentation":"Raised by MMReceiver._set_part_grid when the modality passed in is not a key in _MODALITY_GRID_ATTRS (which only maps IMAGE, VIDEO, AUDIO to their grid attribute names). It guards against writing grid data into an attribute that does not exist for the part being assembled.","triggerScenarios":"Calling the receiver's part-grid setter (from __init__ or add) with a modality value that is not Modality.IMAGE/VIDEO/AUDIO — e.g. a raw string like \"image\" vs the enum, None, or a newly added modality that lacks a mapping in _MODALITY_GRID_ATTRS.","commonSituations":"Deserializing grid metadata where modality arrived as a lowercase string instead of the Modality enum; extending the modality set without updating _MODALITY_GRID_ATTRS; corrupted/malformed payloads from an older encoder version.","solutions":["Coerce the value to the Modality enum before calling (e.g. Modality(modality) or a mapping table for legacy string values).","If adding a new modality, add its (attr_name, flatten) entry to _MODALITY_GRID_ATTRS.","Log/inspect the incoming modality value to find where a raw string or None slips through."],"exampleFix":"# before\nreceiver._set_part_grid(idx, part.modality, grid)  # part.modality is \"image\"\n# after\nreceiver._set_part_grid(idx, Modality(part.modality.upper()), grid)","handlingStrategy":"validation","validationCode":"from sglang.srt.disaggregation.encoder.receiver import _MODALITY_GRID_ATTRS\n\ndef is_supported_modality(modality) -> bool:\n    return modality in _MODALITY_GRID_ATTRS\n\nassert is_supported_modality(part.modality), f\"unsupported modality: {part.modality!r}\"","typeGuard":"def is_valid_modality(m) -> bool:\n    from sglang.srt.multimodal import Modality  # adjust import as needed\n    return isinstance(m, Modality) and m in (Modality.IMAGE, Modality.VIDEO, Modality.AUDIO)","tryCatchPattern":"try:\n    receiver._set_part_grid(idx, modality, grid)\nexcept ValueError:\n    logger.warning(\"dropping part with unknown modality %r\", modality)","preventionTips":["Normalize deserialized modality strings through the Modality enum immediately after decode.","When adding a modality, update _MODALITY_GRID_ATTRS in the same change.","Reject unknown modality values at the transport boundary with a clear 400-style error."],"tags":["multimodal","modality","enum-validation","receiver"],"backgroundTag":"invalid-enum-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}