sgl-project/sglang · error · ValueError

{path} must be a number

Error message

{path} must be a number

What it means

Optional positive float fields (e.g. durations/gain values in the canonical request) must be numeric when present. _optional_positive_finite_float rejects bools and any non int/float value; None is allowed and means absent.

Source

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


def _require_str(value: Any, path: str) -> str:
    if not isinstance(value, str) or value == "":
        raise ValueError(f"{path} must be a non-empty string")
    return value


def _require_int(value: Any, path: str) -> int:
    if isinstance(value, bool) or not isinstance(value, int):
        raise ValueError(f"{path} must be an integer")
    return value


def _optional_positive_finite_float(value: Any, path: str) -> float | None:
    if value is None:
        return None
    if isinstance(value, bool) or not isinstance(value, (int, float)):
        raise ValueError(f"{path} must be a number")
    normalized = float(value)
    if not math.isfinite(normalized) or normalized <= 0.0:
        raise ValueError(f"{path} must be a positive finite number")
    return normalized


def _optional_nonnegative_finite_float(value: Any, path: str) -> float | None:
    if value is None:
        return None
    if isinstance(value, bool) or not isinstance(value, (int, float)):
        raise ValueError(f"{path} must be a number")
    normalized = float(value)
    if not math.isfinite(normalized) or normalized < 0.0:
        raise ValueError(f"{path} must be a non-negative finite number")
    return normalized


def _validate_target(target: Any, *, profile: MiniMaxH3TaskProfile) -> dict[str, Any]:

View on GitHub (pinned to 0132848349)

Solutions

  1. Coerce to float client-side before sending
  2. Keep the field as a JSON number or omit/null it
  3. Check the path in the message to find the offending field

Example fix

# before
{"duration_seconds": "2.0"}
# after
{"duration_seconds": 2.0}
Defensive patterns

Strategy: type-guard

Validate before calling

assert v is None or (isinstance(v, (int, float)) and not isinstance(v, bool)), f"{path} must be a number"

Type guard

def opt_number(v: Any) -> bool:
    return v is None or (isinstance(v, (int, float)) and not isinstance(v, bool))

Prevention

When it happens

Trigger: Passing a string ("2.0"), bool, list, or dict where an optional positive float is expected in minimax_h3_validate_canonical_request.

Common situations: String-typed numerics from form data or query params, or a nested object mistakenly placed where a scalar belongs.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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