{"record":{"id":"7d4e635edb5ac12d","repo":"docling-project/docling","slug":"unsupported-score-value-type-type-value-r","errorCode":null,"errorMessage":"Unsupported score value type: {type(value)!r}","messagePattern":"Unsupported score value type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/hf_vision_base.py","lineNumber":133,"sourceCode":"            return float(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 float(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 float(value.item())\n\n        raise TypeError(f\"Unsupported score value type: {type(value)!r}\")\n\n    @staticmethod\n    def _as_int(value: Any) -> int:\n        if isinstance(value, Integral):\n            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(","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/hf_vision_base.py#L115-L151","documentation":"Raised as TypeError by HfVisionModelMixin._as_float when the score value is neither a Python Real (int/float), a numpy ndarray, nor a torch Tensor. The converter only accepts those three shapes of scalar-like values.","triggerScenarios":"Passing e.g. a Python list, dict, string, or a third-party array type (jax, tf.Tensor) as a score value.","commonSituations":"Swapping inference backends so outputs arrive as an unsupported container; test fixtures injecting plain lists as fake scores.","solutions":["Convert to float before passing: float(value) for lists of length 1, or index element [0].","Convert third-party tensors to numpy first (value.numpy()).","Keep your post-processor emitting only Python scalars, np.ndarray size-1, or torch.Tensor numel-1 values."],"exampleFix":"# before\nconf = model._as_float([0.93])  # list -> TypeError\n\n# after\nconf = model._as_float(0.93)  # or float(scores[i])","handlingStrategy":"validation","validationCode":"import numbers\nimport numpy as np\nok = isinstance(value, numbers.Real) or isinstance(value, np.ndarray) or _is_torch_tensor(value)\nassert ok, f'unsupported score type {type(value)!r}'","typeGuard":"import numbers\nimport numpy as np\n\ndef is_convertible_score(value) -> bool:\n    if isinstance(value, (numbers.Real, np.ndarray)):\n        return True\n    try:\n        import torch\n        return torch.is_tensor(value)\n    except ImportError:\n        return False","tryCatchPattern":null,"preventionTips":["Normalize scores to plain Python floats right after inference.","Convert third-party tensors to numpy at the boundary.","Never pass raw containers (lists/dicts) into result construction."],"tags":["type-error","scores","post-processing","duck-typing"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}