From 7fc09d6b7e2f9f8b6de75c7e05af11f398888f8c Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Mon, 29 Jun 2026 12:06:10 +0530 Subject: [PATCH] fix: make _content_digest fail-soft for non-JSON-serializable values (bytes, custom objects) --- litellm/integrations/asqav/asqav.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/litellm/integrations/asqav/asqav.py b/litellm/integrations/asqav/asqav.py index ca091b0d2a5..cdb74afa015 100644 --- a/litellm/integrations/asqav/asqav.py +++ b/litellm/integrations/asqav/asqav.py @@ -64,11 +64,19 @@ def _read_tail(fh: BinaryIO, size: int) -> bytes: def _content_digest(value: object) -> str | None: - """Return a SHA-256 hex digest of a content value, or None if empty.""" + """Return a SHA-256 hex digest of a content value, or None if empty or not serializable.""" if value is None: return None - raw = json.dumps(value, sort_keys=True, separators=(",", ":")).encode("utf-8") - return _sha256_hex(raw) + try: + raw = json.dumps(value, sort_keys=True, separators=(",", ":"), default=repr).encode("utf-8") + return _sha256_hex(raw) + except Exception: # noqa: BLE001 + # Fall back to repr-based digest so non-JSON-serializable values (bytes, + # custom objects) still produce a stable, verifiable digest. + try: + return _sha256_hex(repr(value).encode("utf-8")) + except Exception: # noqa: BLE001 + return None _SENSITIVE_KEYS = frozenset({"user_api_key", "Authorization", "authorization", "token", "api_key"})