{"record":{"id":"aef9e859071f7107","repo":"sgl-project/sglang","slug":"cosmos3-action-prompt-list-must-contain-only-strin","errorCode":null,"errorMessage":"Cosmos3 action prompt list must contain only strings","messagePattern":"Cosmos3 action prompt list must contain only strings","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py","lineNumber":115,"sourceCode":"            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],\n) -> Cosmos3SamplingParams:\n    parameters = dict(payload.get(\"parameters\") or {})","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py#L97-L133","documentation":"The Cosmos3 action endpoint validates that when the prompt is provided as a list/tuple, every element must be a string. It is thrown by the _action_prompt helper in build_cosmos3_action_sampling_params before any sampling params are built. Mixed content (e.g. numbers, None, nested lists) in the prompt list is rejected because the model prompt construction requires plain strings.","triggerScenarios":"POSTing to the action endpoint with observation.prompt = [\"do X\", 5] or [\"a\", null]; any list prompt containing a non-str element (int, dict, None).","commonSituations":"Serializing numeric task ids or structured prompt parts into the prompt list; passing a JSON-decoded list that mixed types; reusing an OpenAI-style content array (with {type:'text'} dicts) as the prompt list.","solutions":["Make every element of the prompt list a string, e.g. [str(p) for p in prompt]","If using OpenAI-style content blocks, extract the text fields first: [b['text'] for b in content if b.get('type')=='text']","Pass a single string when all images share the same prompt — it is broadcast to batch_size automatically"],"exampleFix":"# before\nprompt = [\"pick up the cube\", 42]\n# after\nprompt = [\"pick up the cube\", \"42\"]","handlingStrategy":"validation","validationCode":"def is_valid_prompt_list(p):\n    return isinstance(p, (list, tuple)) and len(p) > 0 and all(isinstance(x, str) for x in p)","typeGuard":"def is_string_list(p) -> bool:\n    return isinstance(p, list) and all(isinstance(x, str) for x in p)","tryCatchPattern":null,"preventionTips":["Normalize prompt lists to strings client-side: [str(x) for x in prompt]","Extract text from OpenAI-style content blocks before sending as prompt"],"tags":["cosmos3","action-endpoint","prompt-validation","type-validation"],"backgroundTag":"prompt-type-validation-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}