sgl-project/sglang · error · ValueError

Cosmos3 action prompt must be a string or non-empty list

Error message

Cosmos3 action prompt must be a string or non-empty list

What it means

_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.

Source

Thrown at python/sglang/multimodal_gen/runtime/entrypoints/action/cosmos3.py:113

        if not isinstance(item, np.ndarray):
            normalized_images.append(item)
            continue
        if item.dtype != np.uint8:
            raise ValueError("Cosmos3 observation image arrays must use uint8 dtype")
        if item.ndim not in (2, 3):
            raise ValueError(
                "Cosmos3 observation image arrays must have shape [H, W] "
                f"or [H, W, C], got {tuple(item.shape)}"
            )
        normalized_images.append(Image.fromarray(item))
    return normalized_images


def _action_prompt(prompt: Any, batch_size: int) -> str | list[str]:
    if isinstance(prompt, str):
        return prompt if batch_size == 1 else [prompt] * batch_size
    if not isinstance(prompt, (list, tuple)) or not prompt:
        raise ValueError("Cosmos3 action prompt must be a string or non-empty list")
    if not all(isinstance(item, str) for item in prompt):
        raise ValueError("Cosmos3 action prompt list must contain only strings")
    prompts = list(prompt)
    if len(prompts) == 1 and batch_size > 1:
        prompts *= batch_size
    if len(prompts) != batch_size:
        raise ValueError(
            "Cosmos3 batched action input requires one prompt per image, got "
            f"{len(prompts)} prompt(s) and {batch_size} image(s)"
        )
    return prompts[0] if batch_size == 1 else prompts


def build_cosmos3_action_sampling_params(
    payload: dict[str, Any],
    observation: dict[str, Any],
    server_args: ServerArgs,
    sampling_params_cls: type[Cosmos3SamplingParams],

View on GitHub (pinned to 0132848349)

Solutions

  1. Provide a non-empty prompt string, or a list of strings with length 1 (broadcast) or equal to batch_size
  2. Ensure list items are all strings (a separate error covers mixed types)
  3. Guard upstream: if not prompt: raise/skip before calling the API

Example fix

# before
prompt = prompts_cache.get(task_id)  # may be None

# after
prompt = prompts_cache.get(task_id) or default_prompt
Defensive patterns

Strategy: validation

Validate before calling

def validate_prompt(prompt, batch_size):
    if isinstance(prompt, str):
        return [prompt] * max(1, batch_size)
    assert isinstance(prompt, (list, tuple)) and len(prompt) > 0, "prompt must be non-empty str or list"
    assert all(isinstance(p, str) for p in prompt)
    return list(prompt)

Type guard

def is_valid_action_prompt(p) -> bool:
    return isinstance(p, str) and p != "" or (isinstance(p, (list, tuple)) and len(p) > 0 and all(isinstance(i, str) for i in p))

Prevention

When it happens

Trigger: 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).

Common situations: Omitting the prompt field and letting it default to None; programmatic prompt construction returning an empty list for edge-case inputs.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/2b08f2781d5f077b. Report an issue: GitHub.