{"record":{"id":"ceefd8e9a4ef571e","repo":"docling-project/docling","slug":"unsupported-label-value-type-type-value-r","errorCode":null,"errorMessage":"Unsupported label value type: {type(value)!r}","messagePattern":"Unsupported label value type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/hf_vision_base.py","lineNumber":156,"sourceCode":"            return int(value)\n\n        if isinstance(value, np.ndarray):\n            if value.size != 1:\n                raise TypeError(\n                    f\"Expected scalar-like ndarray with size 1, got shape={value.shape}\"\n                )\n            return int(value.reshape(-1)[0])\n\n        import torch\n\n        if isinstance(value, torch.Tensor):\n            if value.numel() != 1:\n                raise TypeError(\n                    f\"Expected scalar-like tensor with one element, got shape={tuple(value.shape)}\"\n                )\n            return int(value.item())\n\n        raise TypeError(f\"Unsupported label value type: {type(value)!r}\")\n","sourceCodeStart":138,"sourceCodeEnd":157,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/hf_vision_base.py#L138-L157","documentation":"Raised as TypeError by HfVisionModelMixin._as_int when the label value is neither an Integral, numpy ndarray, nor torch Tensor. The converter deliberately rejects everything else to avoid silently coercing unexpected label containers.","triggerScenarios":"Passing a Python list, float, string class name, or another array type where an integer class id is expected.","commonSituations":"Label mappings that emit class-name strings instead of ids; float outputs from a regression head reused as labels; jax/tf arrays from alternative backends.","solutions":["Convert to int first: int(round(value)) for float ids, int(label_id) for Python ints.","Map class names back to ids using get_label_mapping() before conversion.","Convert non-supported arrays to numpy: np.asarray(value)."],"exampleFix":"# before\nlabel = model._as_int('Caption')  # str -> TypeError\n\n# after\nid2label_inv = {v: k for k, v in model.get_label_mapping().items()}\nlabel = model._as_int(id2label_inv['Caption'])  # int","handlingStrategy":"validation","validationCode":"import numbers\nassert isinstance(label, numbers.Integral) or type(label).__module__ in ('numpy', 'torch'), \\\n    f'label must be an integer id, got {type(label)!r}'","typeGuard":"import numbers\nimport numpy as np\n\ndef is_integral_label(value) -> bool:\n    if isinstance(value, numbers.Integral):\n        return True\n    if isinstance(value, np.ndarray):\n        return np.issubdtype(value.dtype, np.integer)\n    try:\n        import torch\n        return torch.is_tensor(value) and not torch.is_floating_point(value)\n    except ImportError:\n        return False","tryCatchPattern":null,"preventionTips":["Convert class-name strings to ids with the inverse of get_label_mapping() before use.","Round/cast float label outputs to int explicitly.","Validate label dtype at the boundary of custom post-processors."],"tags":["type-error","labels","post-processing"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}