docling-project/docling · error · RuntimeError
Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_le
Error message
Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len_text!r} What it means
_decode_binary_response: the Inference-Header-Content-Length response header exists but its value cannot be parsed as an integer (int() raised ValueError). The header must be the decimal byte length of the JSON header; garbage like '12; charset=utf-8' or an empty value fails here.
Source
Thrown at docling/models/inference_engines/common/kserve_v2_http.py:187
}
return request_headers, request_body
def _decode_binary_response(response: requests.Response) -> KserveV2InferResponse:
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)View on GitHub (pinned to 61d76f1ff3)
Solutions
- Check the actual header value with curl -i / a network trace
- Fix or reconfigure the intermediary that mutates the header, or route the infer traffic around it
- Disable use_binary_data to avoid binary parsing entirely while the header path is broken
Defensive patterns
Strategy: try-catch
Try / catch
try:
outputs = client.infer(inputs=inputs, output_names=[...])
except RuntimeError as e:
if "Invalid Inference-Header-Content-Length value" in str(e):
raise # header mangled by intermediary; fix proxy config
raise Prevention
- Do not run header-normalizing middlewares on the model infer route
- Test binary mode end-to-end through every proxy layer, not just direct
When it happens
Trigger: A proxy rewrites the header value (appends parameters, quotes it); a custom server sends a float or empty string; header name-collision with another middleware writing the same header.
Common situations: API gateways that normalize/annotate hop-by-hop headers; hand-rolled test servers; WAFs mangling numeric headers.
Related errors
- Binary KServe response from {response.url} did not include {
- Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_le
- KServe v2 output tensor {raw_output.name} did not include in
- Invalid binary_data_size value: {size!r}
- Invalid binary_data_size value: {parsed_size}
AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14).
Data as JSON: /api/errors/50d60905d7fb8ae6.
Report an issue: GitHub.