{"record":{"id":"e587bcca56c714d4","repo":"docling-project/docling","slug":"invalid-binary-data-size-value-size-r","errorCode":null,"errorMessage":"Invalid binary_data_size value: {size!r}","messagePattern":"Invalid binary_data_size value: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/kserve_v2_http.py","lineNumber":134,"sourceCode":"            f\"Supported types: {list(KSERVE_V2_NUMPY_DATATYPES.keys())}\"\n        )\n\n    shape = tuple(int(dim) for dim in raw_output.shape)\n    if raw_output.datatype == \"BYTES\":\n        return decode_bytes_tensor(raw_payload, shape)\n\n    return np.frombuffer(raw_payload, dtype=np_dtype).reshape(shape)\n\n\ndef _parse_binary_data_size(parameters: Mapping[str, Any] | None) -> int | None:\n    if not parameters or \"binary_data_size\" not in parameters:\n        return None\n\n    size = parameters[\"binary_data_size\"]\n    try:\n        parsed_size = int(size)\n    except (TypeError, ValueError) as exc:\n        raise RuntimeError(f\"Invalid binary_data_size value: {size!r}\") from exc\n    if parsed_size < 0:\n        raise RuntimeError(f\"Invalid binary_data_size value: {parsed_size}\")\n    return parsed_size\n\n\ndef _build_binary_request(\n    *,\n    inputs: Mapping[str, np.ndarray],\n    output_names: list[str],\n    request_parameters: Optional[Mapping[str, Any]],\n) -> tuple[Dict[str, str], bytes]:\n    raw_inputs: list[bytes] = []\n    payload: Dict[str, Any] = {\"inputs\": []}\n    for input_name, tensor in inputs.items():\n        encoded_tensor, raw_payload = _encode_binary_input_tensor(\n            name=input_name, tensor=np.asarray(tensor)\n        )\n        payload[\"inputs\"].append(encoded_tensor)","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/kserve_v2_http.py#L116-L152","documentation":"_parse_binary_data_size could not coerce the server-supplied outputs[].parameters.binary_data_size to int (raised TypeError/ValueError). The KServe v2 spec requires this parameter to be an integer byte count when a tensor is returned in binary form; a non-numeric value means the server or an intermediary mangled the response.","triggerScenarios":"binary_data_size arrives as 'abc', None, a nested object, or a float-formatted string; a JSON re-serializing proxy converts the int to something odd; a hand-rolled test server sends the wrong shape.","commonSituations":"Mock/test KServe servers written without honoring the binary_data_size contract; gateways that rewrite parameter maps; version drift in custom predictors.","solutions":["Reproduce with curl and inspect the raw JSON header - check outputs[].parameters.binary_data_size","Fix the server/predictor to emit an integer byte count, or disable binary responses (use_binary_data=False)","If a proxy is re-encoding JSON, bypass it for the infer route"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    outputs = client.infer(inputs=inputs, output_names=[...])\nexcept RuntimeError as e:\n    if \"Invalid binary_data_size value\" in str(e):\n        # capture response via a debug proxy, then fix the server or disable binary\n        raise\n    raise","preventionTips":["Conformance-test custom servers against the KServe v2 binary extension before pointing clients at them","Avoid JSON-rewriting proxies on the infer route","Keep use_binary_data=False against servers whose binary support is unverified"],"tags":["http","kserve","binary-data","server-bug","validation"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}