sgl-project/sglang · error · ValueError

{path} is required and must be an object

Error message

{path} is required and must be an object

What it means

The canonical request's top-level target must be a Mapping (JSON object). A missing target (None), a list, or a scalar raises this error before any field validation inside _validate_target.

Source

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

        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")
    # The canonical target has a deliberately small projection.  Transport
    # compatibility keys are ignored; only these three declared values are
    # validated and emitted below.
    short_edge = _require_int(target.get("short_edge"), f"{path}.short_edge")
    if short_edge <= 0:
        raise ValueError(f"{path}.short_edge must be positive, got {short_edge}")
    if short_edge != MINIMAX_H3_RECOMMENDED_SHORT_EDGE:
        # Same guard the resolver applies. Without it the recommended value warns
        # that it is "outside the verified configuration", naming itself as the
        # verified one.
        warn_unverified_short_edge(short_edge)
    aspect_ratio = _require_str(target.get("aspect_ratio"), f"{path}.aspect_ratio")
    if profile.aspect_ratio_forced_auto and aspect_ratio != "auto":
        raise ValueError(
            f'{path}.aspect_ratio must be "auto" for task {profile.task!r}, '
            f"got {aspect_ratio!r}"
        )
    has_duration = target.get("duration_seconds") is not None

View on GitHub (pinned to 0132848349)

Solutions

  1. Include target as a nested object: {"target": {"short_edge": ..., "uri": ...}}
  2. Fix serializers that flatten or drop the nested object
  3. Check the canonical request schema before submitting

Example fix

# before
{"short_edge": 512}
# after
{"target": {"short_edge": 512}}
Defensive patterns

Strategy: type-guard

Validate before calling

from collections.abc import Mapping
assert isinstance(req.get("target"), Mapping), "target is required and must be an object"

Type guard

from collections.abc import Mapping
def has_target(req: Any) -> bool:
    return isinstance(req, Mapping) and isinstance(req.get("target"), Mapping)

Prevention

When it happens

Trigger: Calling minimax_h3_validate_canonical_request with a request dict lacking 'target', or with target set to a string/number/array.

Common situations: Clients flattening target fields to top level, or a transport dropping the nested object; also None from optional-key handling code.

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/5e9bffa3a3ee64f7. Report an issue: GitHub.