sgl-project/sglang · error · ValueError

{path} must be a positive finite number

Error message

{path} must be a positive finite number

What it means

After the numeric check, optional positive float fields must be finite (> 0, not inf/nan). Zero, negative values, float('inf'), and NaN all raise this error.

Source

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

    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]:
    path = "target"
    if not isinstance(target, Mapping):
        raise ValueError(f"{path} is required and must be an object")

View on GitHub (pinned to 0132848349)

Solutions

  1. Guard the value with math.isfinite(v) and v > 0 before sending
  2. Fix upstream arithmetic that yields 0/NaN/inf (e.g. equal timestamps)
  3. Omit the field (null) when it genuinely has no value

Example fix

# before
{"duration_seconds": 0.0}
# after
{"duration_seconds": 2.0}  # or omit the key
Defensive patterns

Strategy: validation

Validate before calling

import math
assert v is None or (math.isfinite(v) and v > 0), f"{path} must be positive finite"

Type guard

import math
def opt_pos_finite(v: Any) -> bool:
    return v is None or (isinstance(v, (int, float)) and math.isfinite(v) and v > 0)

Prevention

When it happens

Trigger: Passing duration = 0, -1.5, float('nan'), or float('inf') to an optional positive float field; NaN slips past naive comparisons, hence the explicit math.isfinite check.

Common situations: Computed values that degenerate to 0 (e.g. end - start when equal), un sanitized client math producing NaN/inf, or treating the field as allowing zero.

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/09efda13b412b4c2. Report an issue: GitHub.