{"record":{"id":"99617196ab54b9ab","repo":"docling-project/docling","slug":"unsupported-numpy-dtype-for-kserve-v2-input-tens","errorCode":null,"errorMessage":"Unsupported numpy dtype for KServe v2 input: {tensor.dtype!s}. Supported types: {list(NUMPY_KSERVE_V2_DATATYPES.keys())}","messagePattern":"Unsupported numpy dtype for KServe v2 input: (.+?)\\. Supported types: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/kserve_v2_http.py","lineNumber":37,"sourceCode":"\nfrom docling.models.inference_engines.common.kserve_v2_types import (\n    KSERVE_V2_NUMPY_DATATYPES,\n    NUMPY_KSERVE_V2_DATATYPES,\n    KserveV2ModelMetadataResponse,\n)\nfrom docling.models.inference_engines.common.kserve_v2_utils import (\n    decode_bytes_tensor,\n    encode_bytes_tensor,\n)\n\n_log = logging.getLogger(__name__)\n_INFERENCE_HEADER_CONTENT_LENGTH = \"Inference-Header-Content-Length\"\n\n\ndef _tensor_kserve_dtype(tensor: np.ndarray) -> str:\n    kserve_dtype = NUMPY_KSERVE_V2_DATATYPES.get(tensor.dtype)\n    if kserve_dtype is None:\n        raise ValueError(\n            f\"Unsupported numpy dtype for KServe v2 input: {tensor.dtype!s}. \"\n            f\"Supported types: {list(NUMPY_KSERVE_V2_DATATYPES.keys())}\"\n        )\n    return kserve_dtype\n\n\ndef _encode_input_tensor(name: str, tensor: np.ndarray) -> Dict[str, Any]:\n    kserve_dtype = _tensor_kserve_dtype(tensor)\n\n    return {\n        \"name\": name,\n        \"shape\": list(tensor.shape),\n        \"datatype\": kserve_dtype,\n        \"data\": tensor.reshape(-1).tolist(),\n    }\n\n\ndef _encode_binary_input_tensor(","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/kserve_v2_http.py#L19-L55","documentation":"HTTP-path equivalent of the gRPC input dtype check: _tensor_kserve_dtype raises ValueError when a numpy input tensor's dtype is not in NUMPY_KSERVE_V2_DATATYPES while encoding the JSON request body. Only BOOL, UINT8/16/32/64, INT8/16/32/64, FP16/32/64 and object/BYTES are encodable.","triggerScenarios":"Posting infer() over HTTP with a '<U'-dtype string array, float128, complex, or datetime64 tensor; passing Python lists of mixed strings that np.asarray turns into '<U' dtype; object arrays whose per-element types cannot be encoded are fine, but the container dtype itself must be object.","commonSituations":"Sending string prompts/labels without dtype=object; porting a pipeline from a REST mock (which accepted anything) to the typed client; numpy version differences yielding unexpected result dtypes.","solutions":["Convert string tensors to object dtype and numeric tensors to a supported width before calling infer (arr.astype(object) or arr.astype(np.float32))","Pre-validate: all(np.asarray(t).dtype in NUMPY_KSERVE_V2_DATATYPES for t in inputs.values())","Read the message - it prints the offending dtype and the exact supported set"],"exampleFix":"// before\ninputs = {\"input_str\": np.array([\"hello\"])}  # '<U5'\n\n// after\ninputs = {\"input_str\": np.array([\"hello\"], dtype=object)}  # BYTES","handlingStrategy":"validation","validationCode":"import numpy as np\nfrom docling.models.inference_engines.common.kserve_v2_types import NUMPY_KSERVE_V2_DATATYPES\n\ndef validate_inputs(inputs: dict[str, np.ndarray]) -> None:\n    for name, tensor in inputs.items():\n        if np.asarray(tensor).dtype not in NUMPY_KSERVE_V2_DATATYPES:\n            raise TypeError(f\"Input {name!r} dtype not KServe v2 encodable\")","typeGuard":"import numpy as np\nfrom docling.models.inference_engines.common.kserve_v2_types import NUMPY_KSERVE_V2_DATATYPES\n\ndef is_encodable_tensor(tensor: np.ndarray) -> bool:\n    return np.asarray(tensor).dtype in NUMPY_KSERVE_V2_DATATYPES","tryCatchPattern":"try:\n    outputs = client.infer(inputs=inputs, output_names=[...])\nexcept ValueError as e:\n    if \"Unsupported numpy dtype\" in str(e):\n        raise  # fix the caller's tensor dtypes; retrying unchanged will not help\n    raise","preventionTips":["Construct string inputs with dtype=object","Centralize tensor construction in one factory that enforces supported dtypes","Add dtype asserts in tests so unsupported dtypes never reach infer"],"tags":["numpy","dtype","http","kserve","validation"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}