docling-project/docling · error · RuntimeError

Invalid binary_data_size value: {size!r}

Error message

Invalid binary_data_size value: {size!r}

What it means

_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.

Source

Thrown at docling/models/inference_engines/common/kserve_v2_http.py:134

            f"Supported types: {list(KSERVE_V2_NUMPY_DATATYPES.keys())}"
        )

    shape = tuple(int(dim) for dim in raw_output.shape)
    if raw_output.datatype == "BYTES":
        return decode_bytes_tensor(raw_payload, shape)

    return np.frombuffer(raw_payload, dtype=np_dtype).reshape(shape)


def _parse_binary_data_size(parameters: Mapping[str, Any] | None) -> int | None:
    if not parameters or "binary_data_size" not in parameters:
        return None

    size = parameters["binary_data_size"]
    try:
        parsed_size = int(size)
    except (TypeError, ValueError) as exc:
        raise RuntimeError(f"Invalid binary_data_size value: {size!r}") from exc
    if parsed_size < 0:
        raise RuntimeError(f"Invalid binary_data_size value: {parsed_size}")
    return parsed_size


def _build_binary_request(
    *,
    inputs: Mapping[str, np.ndarray],
    output_names: list[str],
    request_parameters: Optional[Mapping[str, Any]],
) -> tuple[Dict[str, str], bytes]:
    raw_inputs: list[bytes] = []
    payload: Dict[str, Any] = {"inputs": []}
    for input_name, tensor in inputs.items():
        encoded_tensor, raw_payload = _encode_binary_input_tensor(
            name=input_name, tensor=np.asarray(tensor)
        )
        payload["inputs"].append(encoded_tensor)

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Reproduce with curl and inspect the raw JSON header - check outputs[].parameters.binary_data_size
  2. Fix the server/predictor to emit an integer byte count, or disable binary responses (use_binary_data=False)
  3. If a proxy is re-encoding JSON, bypass it for the infer route
Defensive patterns

Strategy: try-catch

Try / catch

try:
    outputs = client.infer(inputs=inputs, output_names=[...])
except RuntimeError as e:
    if "Invalid binary_data_size value" in str(e):
        # capture response via a debug proxy, then fix the server or disable binary
        raise
    raise

Prevention

When it happens

Trigger: 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.

Common situations: Mock/test KServe servers written without honoring the binary_data_size contract; gateways that rewrite parameter maps; version drift in custom predictors.

Related errors


AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14). Data as JSON: /api/errors/e587bcca56c714d4. Report an issue: GitHub.