docling-project/docling · error · RuntimeError

Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_le

Error message

Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len}

What it means

_decode_binary_response: Inference-Header-Content-Length parsed to an int, but the value is negative or larger than the total response body length. The JSON header cannot possibly live within the body, indicating truncation (Content-Length mismatch, early connection close) or a corrupted header value.

Source

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

    header_len_text = response.headers.get(_INFERENCE_HEADER_CONTENT_LENGTH)
    if header_len_text is None:
        try:
            return KserveV2InferResponse.model_validate(response.json())
        except Exception as exc:
            raise RuntimeError(
                f"Binary KServe response from {response.url} did not include "
                f"{_INFERENCE_HEADER_CONTENT_LENGTH} and was not valid JSON: {exc}"
            ) from exc

    try:
        header_len = int(header_len_text)
    except ValueError as exc:
        raise RuntimeError(
            f"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len_text!r}"
        ) from exc

    if header_len < 0 or header_len > len(response.content):
        raise RuntimeError(
            f"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len}"
        )

    try:
        header_json = json.loads(response.content[:header_len].decode("utf-8"))
        return KserveV2InferResponse.model_validate(header_json)
    except Exception as exc:
        raise RuntimeError(
            f"Invalid binary inference response header from {response.url}: {exc}"
        ) from exc


@dataclass(frozen=True)
class KserveV2HttpClient:
    """Minimal client for KServe v2 REST infer requests."""

    base_url: str
    model_name: str

View on GitHub (pinned to 61d76f1ff3)

Solutions

  1. Compare the header value with the actual body length (log len(response.content)) to confirm truncation
  2. Raise or remove max-response-size limits on proxies in front of the model server
  3. Retry once - transient truncation resolves; if persistent, capture a tcpdump and inspect at the server
  4. Fall back to use_binary_data=False (JSON responses are smaller per-element but avoid the header split)
Defensive patterns

Strategy: retry

Try / catch

try:
    outputs = client.infer(inputs=inputs, output_names=[...])
except RuntimeError as e:
    if "Invalid Inference-Header-Content-Length value" in str(e):
        outputs = client.infer(inputs=inputs, output_names=[...])  # truncation may be transient
    else:
        raise

Prevention

When it happens

Trigger: Response body truncated by a proxy enforcing a max-response-size; connection cut mid-transfer but requests still returned partial content; header claims a length computed before the server re-serialized the header; chunked-encoding reassembly bug.

Common situations: Gateway/CDN response size limits on large binary inference payloads; flaky links dropping bytes; server-side header-size arithmetic bugs.

Related errors


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