{"record":{"id":"2b08f2781d5f077b","repo":"sgl-project/sglang","slug":"cosmos3-action-prompt-must-be-a-string-or-non-empt","errorCode":null,"errorMessage":"Cosmos3 action prompt must be a string or non-empty list","messagePattern":"Cosmos3 action prompt must be a string or non-empty list","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py","lineNumber":113,"sourceCode":"        if not isinstance(item, np.ndarray):\n            normalized_images.append(item)\n            continue\n        if item.dtype != np.uint8:\n            raise ValueError(\"Cosmos3 observation image arrays must use uint8 dtype\")\n        if item.ndim not in (2, 3):\n            raise ValueError(\n                \"Cosmos3 observation image arrays must have shape [H, W] \"\n                f\"or [H, W, C], got {tuple(item.shape)}\"\n            )\n        normalized_images.append(Image.fromarray(item))\n    return normalized_images\n\n\ndef _action_prompt(prompt: Any, batch_size: int) -> str | list[str]:\n    if isinstance(prompt, str):\n        return prompt if batch_size == 1 else [prompt] * batch_size\n    if not isinstance(prompt, (list, tuple)) or not prompt:\n        raise ValueError(\"Cosmos3 action prompt must be a string or non-empty list\")\n    if not all(isinstance(item, str) for item in prompt):\n        raise ValueError(\"Cosmos3 action prompt list must contain only strings\")\n    prompts = list(prompt)\n    if len(prompts) == 1 and batch_size > 1:\n        prompts *= batch_size\n    if len(prompts) != batch_size:\n        raise ValueError(\n            \"Cosmos3 batched action input requires one prompt per image, got \"\n            f\"{len(prompts)} prompt(s) and {batch_size} image(s)\"\n        )\n    return prompts[0] if batch_size == 1 else prompts\n\n\ndef build_cosmos3_action_sampling_params(\n    payload: dict[str, Any],\n    observation: dict[str, Any],\n    server_args: ServerArgs,\n    sampling_params_cls: type[Cosmos3SamplingParams],","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py#L95-L131","documentation":"_action_prompt requires the Cosmos3 action prompt to be a non-empty string or a non-empty list/tuple. None, empty string lists, empty lists, or non-string non-list types raise this ValueError. List length must also match (or be broadcastable to) the batch size.","triggerScenarios":"Passing prompt=None, prompt=[], prompt=123, or an empty tuple in the action request; a list whose length doesn't match batch_size and can't be broadcast (single-item lists are repeated).","commonSituations":"Omitting the prompt field and letting it default to None; programmatic prompt construction returning an empty list for edge-case inputs.","solutions":["Provide a non-empty prompt string, or a list of strings with length 1 (broadcast) or equal to batch_size","Ensure list items are all strings (a separate error covers mixed types)","Guard upstream: if not prompt: raise/skip before calling the API"],"exampleFix":"# before\nprompt = prompts_cache.get(task_id)  # may be None\n\n# after\nprompt = prompts_cache.get(task_id) or default_prompt","handlingStrategy":"validation","validationCode":"def validate_prompt(prompt, batch_size):\n    if isinstance(prompt, str):\n        return [prompt] * max(1, batch_size)\n    assert isinstance(prompt, (list, tuple)) and len(prompt) > 0, \"prompt must be non-empty str or list\"\n    assert all(isinstance(p, str) for p in prompt)\n    return list(prompt)","typeGuard":"def is_valid_action_prompt(p) -> bool:\n    return isinstance(p, str) and p != \"\" or (isinstance(p, (list, tuple)) and len(p) > 0 and all(isinstance(i, str) for i in p))","tryCatchPattern":null,"preventionTips":["Default missing prompts to a sensible fallback string client-side","Assert prompt truthiness before issuing the request","Keep prompt list length equal to batch size or length 1"],"tags":["cosmos3","prompt","validation"],"backgroundTag":"invalid-prompt-input","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}