sgl-project/sglang · error · ValueError

{path}.duration_seconds must be a number

Error message

{path}.duration_seconds must be a number

What it means

duration_seconds was provided but is not a number — it is a string, None-as-sentinel, list, or a bool (bools are explicitly rejected even though isinstance(bool, int)).

Source

Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/minimax_h3/request_validation.py:124

    ):
        raise ValueError(
            f"{path}.aspect_ratio for task {profile.task!r} must be 'auto' or "
            f"one of {list(MINIMAX_H3_FINITE_ASPECT_RATIOS)!r}, got "
            f"{aspect_ratio!r}"
        )
    if not has_duration:
        if not profile.duration_from_audio_reference:
            raise ValueError(f"{path}.duration_seconds is required")
        # ref2va: duration may derive from a reference audio; the
        # audio-condition presence is enforced after conditions validate.
    out: dict[str, Any] = {
        "short_edge": short_edge,
        "aspect_ratio": aspect_ratio,
    }
    if has_duration:
        duration = target["duration_seconds"]
        if isinstance(duration, bool) or not isinstance(duration, (int, float)):
            raise ValueError(f"{path}.duration_seconds must be a number")
        if duration <= 0:
            raise ValueError(f"{path}.duration_seconds must be positive")
        if not (
            MINIMAX_H3_MIN_DURATION_SECONDS
            <= float(duration)
            <= MINIMAX_H3_MAX_DURATION_SECONDS
        ):
            raise ValueError(
                f"{path}.duration_seconds must be in "
                f"[{MINIMAX_H3_MIN_DURATION_SECONDS:g}, "
                f"{MINIMAX_H3_MAX_DURATION_SECONDS:g}], got {duration}"
            )
        out["duration_seconds"] = float(duration)
    return out


def _validate_conditions(
    conditions: Any,

View on GitHub (pinned to 0132848349)

Solutions

  1. Coerce to float/int before submission: float(user_value)
  2. Reject bools explicitly at the client boundary
  3. Validate with a numeric type guard before calling the API

Example fix

// before
{"duration_seconds": "6"}
// after
{"duration_seconds": 6}
Defensive patterns

Strategy: type-guard

Validate before calling

d = target.get('duration_seconds')
if d is not None and (isinstance(d, bool) or not isinstance(d, (int, float))):
    target['duration_seconds'] = float(str(d))  # or reject

Type guard

def is_numeric_duration(v) -> bool:
    return not isinstance(v, bool) and isinstance(v, (int, float))

Prevention

When it happens

Trigger: Passing duration_seconds="6" (JSON string from user input) or True/False.

Common situations: Forwarding untyped form/API input; JSON where the client serialized the number as a string; configuration systems that coerce values to strings.

Related errors


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