From 15e6516fe110d6b6fba58070f497a3b06218bfbd Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 09:30:58 -0700 Subject: [PATCH] fix(managed files): skip chat messages and content items that are not objects --- enterprise/litellm_enterprise/proxy/hooks/managed_files.py | 4 ++-- tests/unit/enterprise/proxy/hooks/test_managed_files.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py index 01aa8465567..171be00ef6b 100644 --- a/enterprise/litellm_enterprise/proxy/hooks/managed_files.py +++ b/enterprise/litellm_enterprise/proxy/hooks/managed_files.py @@ -1735,13 +1735,13 @@ class _PROXY_LiteLLMManagedFiles(CustomLogger, BaseFileEndpoints): """ file_ids = [] for message in messages: - if message.get("role") == "user": + if isinstance(message, dict) and message.get("role") == "user": content = message.get("content") if content: if isinstance(content, str): continue for c in content: - if c.get("type") == "file": + if isinstance(c, dict) and c.get("type") == "file": file_object_file_field = cast(Dict[str, object], c).get("file") if not isinstance(file_object_file_field, dict): continue diff --git a/tests/unit/enterprise/proxy/hooks/test_managed_files.py b/tests/unit/enterprise/proxy/hooks/test_managed_files.py index 33d7289c893..7d9b328fc9a 100644 --- a/tests/unit/enterprise/proxy/hooks/test_managed_files.py +++ b/tests/unit/enterprise/proxy/hooks/test_managed_files.py @@ -337,9 +337,11 @@ def test_get_file_ids_from_messages_leaves_malformed_file_parts_to_request_valid DualCache(), prisma_client=MagicMock() ) messages = [ + "not-a-message", { "role": "user", "content": [ + "not-a-part", {"type": "file"}, {"type": "file", "file": "file-raw"}, {"type": "file", "file": None},