sgl-project/sglang · error · ValueError

Unknown value for {flag}: {name}. Available: {list(mapping.k

Error message

Unknown value for {flag}: {name}. Available: {list(mapping.keys())}

What it means

Raised by _expand_flag in the comparator preset module when a preset-expanding CLI flag (e.g. --preset or similar mapped flag) is given a value that is not a key in the flag's mapping table. The error message lists the available values so the developer can pick a valid one. It is a strict whitelist lookup, so any typo or unsupported name fails immediately.

Source

Thrown at python/sglang/srt/debug_utils/comparator/preset.py:48

        return expanded

    if "--grouping-skip-keys" not in argv:
        return presets[DEFAULT_PRESET] + argv

    return argv


def _expand_flag(
    argv: list[str], flag: str, mapping: dict[str, list[str]]
) -> list[str] | None:
    """Replace ``flag <name>`` in *argv* with the corresponding argv fragment from *mapping*."""
    if flag not in argv:
        return None

    idx: int = argv.index(flag)
    name: str = argv[idx + 1]
    if name not in mapping:
        raise ValueError(
            f"Unknown value for {flag}: {name}. Available: {list(mapping.keys())}"
        )

    return argv[:idx] + mapping[name] + argv[idx + 2 :]

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the error's 'Available:' list and use one of those exact keys
  2. Check for case sensitivity or trailing whitespace in the value
  3. If the value should be supported, add it to the mapping passed to expand_preset

Example fix

# before
expand_preset(['prog','--preset','fp8-e4m3'], mapping)
# after
expand_preset(['prog','--preset','fp8_e4m3'], mapping)  # use a listed key
Defensive patterns

Strategy: validation

Validate before calling

def check_flag_value(flag, name, mapping):
    if name not in mapping:
        raise SystemExit(f"{flag}: unknown value {name!r}; available: {sorted(mapping)}")

Try / catch

try:
    argv = expand_preset(argv, mapping)
except ValueError as e:
    print(e); sys.exit(2)

Prevention

When it happens

Trigger: Calling expand_preset(argv, mapping) with a command line like ['...','--flag','typo-name'] where 'typo-name' is not in mapping; e.g. passing an unknown preset name after the flag.

Common situations: Typos in preset names, presets renamed between versions, copy-pasting a preset name from old docs, or case mismatches (e.g. 'BF16' vs 'bf16').

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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