{"record":{"id":"f97bcd6e398fea68","repo":"roboflow/supervision","slug":"invalid-type-for-lmm-type-lmm-must-be-lmm-o","errorCode":null,"errorMessage":"Invalid type for 'lmm': {type(lmm)}. Must be LMM or str.","messagePattern":"Invalid type for 'lmm': (.+?)\\. Must be LMM or str\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/supervision/detection/core.py","lineNumber":1604,"sourceCode":"        )\n\n        # LMM and VLM are mirror enums (identical string values) so value-based\n        # lookup is exhaustive by construction — no hand-maintained mapping needed.\n        if isinstance(lmm, LMM):\n            vlm = VLM(lmm.value)\n\n        elif isinstance(lmm, str):\n            try:\n                lmm_enum = LMM(lmm.lower())\n            except ValueError:\n                raise ValueError(\n                    f\"Invalid LMM string '{lmm}'. Must be one of \"\n                    f\"{[m.value for m in LMM]}\"\n                )\n            vlm = VLM(lmm_enum.value)\n\n        else:\n            raise ValueError(\n                f\"Invalid type for 'lmm': {type(lmm)}. Must be LMM or str.\"\n            )\n\n        return cls.from_vlm(vlm=vlm, result=result, **kwargs)\n\n    @classmethod\n    def from_vlm(\n        cls, vlm: VLM | str, result: str | dict[str, Any], **kwargs: Any\n    ) -> Detections:\n        \"\"\"\n\n        Creates a Detections object from the given result string based on the specified\n        Vision Language Model (VLM).\n\n        | Name                | Enum (sv.VLM)        | Tasks                   | Required parameters         | Optional parameters |\n        |---------------------|----------------------|-------------------------|-----------------------------|---------------------|\n        | PaliGemma           | `PALIGEMMA`          | detection               | `resolution_wh`             | `classes`           |\n        | PaliGemma 2         | `PALIGEMMA`          | detection               | `resolution_wh`             | `classes`           |","sourceCodeStart":1586,"sourceCodeEnd":1622,"githubUrl":"https://github.com/roboflow/supervision/blob/7f254d9784d4c37e0f03cd89ddee164c8db099c0/src/supervision/detection/core.py#L1586-L1622","documentation":"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.)","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a valid LMM enum or its string value: from_lmm(result, lmm=sv.LMM.PALIGEMMA) or from_lmm(result, lmm='paligemma').","If you don't care about the deprecated LMM alias, call from_vlm(vlm=sv.VLM.PALIGEMMA, result=...) directly with an explicit backend.","Ensure the lmm argument actually receives the string (check for None/unset variables in kwargs plumbing)."],"exampleFix":"# before\ndetections = sv.Detections.from_lmm(result, lmm=model)  # model object -> ValueError\n\n# after\ndetections = sv.Detections.from_vlm(vlm=sv.VLM.PALIGEMMA, result=result)","handlingStrategy":"type-guard","validationCode":"def resolve_vlm_backend(lmm):\n    if isinstance(lmm, str):\n        return sv.VLM(lmm.lower())\n    if hasattr(lmm, 'value'):\n        return sv.VLM(lmm.value)\n    raise TypeError(f'cannot resolve VLM backend from {type(lmm)}')\n\nvlm = resolve_vlm_backend(lmm_arg)\ndetections = sv.Detections.from_vlm(vlm=vlm, result=result)","typeGuard":"def is_vlm_backend_arg(lmm) -> bool:\n    return isinstance(lmm, str) or isinstance(lmm, (sv.LMM, sv.VLM))","tryCatchPattern":"try:\n    detections = sv.Detections.from_lmm(result, lmm=lmm_arg)\nexcept ValueError as e:\n    if \"Invalid type for 'lmm'\" in str(e):\n        detections = sv.Detections.from_vlm(vlm=sv.VLM.PALIGEMMA, result=result)\n    else:\n        raise","preventionTips":["Pass sv.VLM members explicitly; LMM is a deprecated alias","Never pass model objects as the backend selector","Centralize backend selection in one config constant"],"tags":["vlm","lmm","dispatch","type","deprecated"],"backgroundTag":null,"analyzedSha":"7f254d9784d4c37e0f03cd89ddee164c8db099c0","analyzedAt":"2026-08-15T05:13:01.950Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}