{"record":{"id":"884982eb6b5b2521","repo":"sgl-project/sglang","slug":"cosmos3-batched-action-input-requires-one-prompt-p","errorCode":null,"errorMessage":"Cosmos3 batched action input requires one prompt per image, got {len(prompts)} prompt(s) and {batch_size} image(s)","messagePattern":"Cosmos3 batched action input requires one prompt per image, got (.+?) prompt\\(s\\) and (.+?) image\\(s\\)","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py","lineNumber":120,"sourceCode":"                \"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 {})\n    options = {**observation, **parameters}\n    action_mode = str(options.get(\"action_mode\", \"policy\")).strip().lower()\n    if action_mode == \"forward_dynamics\":\n        raise ValueError(\n            \"Cosmos3 forward_dynamics produces video; use /v1/videos instead\"","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py#L102-L138","documentation":"For batched Cosmos3 action requests (multiple observation images), the number of prompts must equal the number of images, except a single prompt which is broadcast. This error fires when the prompt list length (after broadcast attempt) still mismatches the image batch size. It enforces one-prompt-per-image pairing so outputs stay aligned with inputs.","triggerScenarios":"Sending 3 images with a 2-element prompt list; sending batch_size>1 with an empty-ish or wrong-length list (lists of length !=1 and !=batch_size).","commonSituations":"Dropping one image from a batch but not its prompt; concatenating datasets where images and prompts desynchronize; assuming prompts are truncated/padded to image count.","solutions":["Match len(prompt) == len(images), or provide exactly one prompt to broadcast","Trim or extend the prompt list explicitly before the call: prompt = prompt[:len(images)] or pad with prompt[-1]","Audit upstream batching code that zips images and prompts"],"exampleFix":"# before\nprompt = [\"a\", \"b\"]\nimages = [img1, img2, img3]\n# after\nprompt = [\"a\", \"b\", \"a\"]  # len(prompt) == len(images)","handlingStrategy":"validation","validationCode":"if isinstance(prompt, list):\n    if len(prompt) == 1:\n        prompt = prompt * len(images)\n    assert len(prompt) == len(images), f'{len(prompt)} prompts vs {len(images)} images'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build prompt and image lists from the same source records so they stay in lockstep","Pre-broadcast single prompts client-side to make intent explicit"],"tags":["cosmos3","batching","prompt-validation","cardinality-mismatch"],"backgroundTag":"batch-cardinality-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}