{"record":{"id":"50d60905d7fb8ae6","repo":"docling-project/docling","slug":"invalid-inference-header-content-length-value","errorCode":null,"errorMessage":"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len_text!r}","messagePattern":"Invalid (.+?) value: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"docling/models/inference_engines/common/kserve_v2_http.py","lineNumber":187,"sourceCode":"    }\n    return request_headers, request_body\n\n\ndef _decode_binary_response(response: requests.Response) -> KserveV2InferResponse:\n    header_len_text = response.headers.get(_INFERENCE_HEADER_CONTENT_LENGTH)\n    if header_len_text is None:\n        try:\n            return KserveV2InferResponse.model_validate(response.json())\n        except Exception as exc:\n            raise RuntimeError(\n                f\"Binary KServe response from {response.url} did not include \"\n                f\"{_INFERENCE_HEADER_CONTENT_LENGTH} and was not valid JSON: {exc}\"\n            ) from exc\n\n    try:\n        header_len = int(header_len_text)\n    except ValueError as exc:\n        raise RuntimeError(\n            f\"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len_text!r}\"\n        ) from exc\n\n    if header_len < 0 or header_len > len(response.content):\n        raise RuntimeError(\n            f\"Invalid {_INFERENCE_HEADER_CONTENT_LENGTH} value: {header_len}\"\n        )\n\n    try:\n        header_json = json.loads(response.content[:header_len].decode(\"utf-8\"))\n        return KserveV2InferResponse.model_validate(header_json)\n    except Exception as exc:\n        raise RuntimeError(\n            f\"Invalid binary inference response header from {response.url}: {exc}\"\n        ) from exc\n\n\n@dataclass(frozen=True)","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/docling-project/docling/blob/61d76f1ff3f8428065465889f7b4577da7df704c/docling/models/inference_engines/common/kserve_v2_http.py#L169-L205","documentation":"_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.","triggerScenarios":"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.","commonSituations":"API gateways that normalize/annotate hop-by-hop headers; hand-rolled test servers; WAFs mangling numeric headers.","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"],"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 Inference-Header-Content-Length value\" in str(e):\n        raise  # header mangled by intermediary; fix proxy config\n    raise","preventionTips":["Do not run header-normalizing middlewares on the model infer route","Test binary mode end-to-end through every proxy layer, not just direct"],"tags":["http","kserve","binary-data","header","gateway"],"backgroundTag":null,"analyzedSha":"61d76f1ff3f8428065465889f7b4577da7df704c","analyzedAt":"2026-08-14T23:53:18.727Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}