roboflow/supervision · error · ValueError

Invalid type for 'lmm': {type(lmm)}. Must be LMM or str.

Error message

Invalid type for 'lmm': {type(lmm)}. Must be LMM or str.

What it means

Detections.from_lmm routes to a VLM parser based on an LMM enum value or an enum-name string. If the lmm argument is neither an LMM member nor a str (e.g. a model object, dict, or None), the dispatch chain falls through to this ValueError. (Note: an invalid *string* raises the separate 'Invalid LMM string' error just above.)

Source

Thrown at src/supervision/detection/core.py:1604

        )

        # LMM and VLM are mirror enums (identical string values) so value-based
        # lookup is exhaustive by construction — no hand-maintained mapping needed.
        if isinstance(lmm, LMM):
            vlm = VLM(lmm.value)

        elif isinstance(lmm, str):
            try:
                lmm_enum = LMM(lmm.lower())
            except ValueError:
                raise ValueError(
                    f"Invalid LMM string '{lmm}'. Must be one of "
                    f"{[m.value for m in LMM]}"
                )
            vlm = VLM(lmm_enum.value)

        else:
            raise ValueError(
                f"Invalid type for 'lmm': {type(lmm)}. Must be LMM or str."
            )

        return cls.from_vlm(vlm=vlm, result=result, **kwargs)

    @classmethod
    def from_vlm(
        cls, vlm: VLM | str, result: str | dict[str, Any], **kwargs: Any
    ) -> Detections:
        """

        Creates a Detections object from the given result string based on the specified
        Vision Language Model (VLM).

        | Name                | Enum (sv.VLM)        | Tasks                   | Required parameters         | Optional parameters |
        |---------------------|----------------------|-------------------------|-----------------------------|---------------------|
        | PaliGemma           | `PALIGEMMA`          | detection               | `resolution_wh`             | `classes`           |
        | PaliGemma 2         | `PALIGEMMA`          | detection               | `resolution_wh`             | `classes`           |

View on GitHub (pinned to 7f254d9784)

Solutions

  1. Pass a valid LMM enum or its string value: from_lmm(result, lmm=sv.LMM.PALIGEMMA) or from_lmm(result, lmm='paligemma').
  2. If you don't care about the deprecated LMM alias, call from_vlm(vlm=sv.VLM.PALIGEMMA, result=...) directly with an explicit backend.
  3. Ensure the lmm argument actually receives the string (check for None/unset variables in kwargs plumbing).

Example fix

# before
detections = sv.Detections.from_lmm(result, lmm=model)  # model object -> ValueError

# after
detections = sv.Detections.from_vlm(vlm=sv.VLM.PALIGEMMA, result=result)
Defensive patterns

Strategy: type-guard

Validate before calling

def resolve_vlm_backend(lmm):
    if isinstance(lmm, str):
        return sv.VLM(lmm.lower())
    if hasattr(lmm, 'value'):
        return sv.VLM(lmm.value)
    raise TypeError(f'cannot resolve VLM backend from {type(lmm)}')

vlm = resolve_vlm_backend(lmm_arg)
detections = sv.Detections.from_vlm(vlm=vlm, result=result)

Type guard

def is_vlm_backend_arg(lmm) -> bool:
    return isinstance(lmm, str) or isinstance(lmm, (sv.LMM, sv.VLM))

Try / catch

try:
    detections = sv.Detections.from_lmm(result, lmm=lmm_arg)
except ValueError as e:
    if "Invalid type for 'lmm'" in str(e):
        detections = sv.Detections.from_vlm(vlm=sv.VLM.PALIGEMMA, result=result)
    else:
        raise

Prevention

When it happens

Trigger: Calling Detections.from_lmm(result, lmm=model) where model is a loaded model/inference object; passing lmm=None as a 'detect automatically' attempt; passing a variable that was never assigned and defaults to some non-str object.

Common situations: Assuming from_lmm auto-detects the backend from the result; passing the VLM client (Roboflow model handle, transformers pipeline) instead of a backend name; refactor changing a variable from str to an enum/object without updating the call site.

Related errors


AI-assisted analysis of roboflow/supervision@7f254d9784 (2026-08-15). Data as JSON: /api/errors/f97bcd6e398fea68. Report an issue: GitHub.