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},