From 2b9f03b71271f646d7b8a33b2776bc8635c9aa64 Mon Sep 17 00:00:00 2001 From: Joshua Valluru <326636767+joshua-berri@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:51:31 -0700 Subject: [PATCH] fix(router): preserve screenshot image routing --- .../prompt_templates/common_utils.py | 6 +++--- tests/unit/test_router/test_router.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.py index 123dd7b97e9..5fbd787b3b6 100644 --- a/litellm/litellm_core_utils/prompt_templates/common_utils.py +++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py @@ -238,7 +238,7 @@ def is_non_content_values_set(message: AllMessageValues) -> bool: return any(message.get(key, None) is not None for key in message if key not in ignore_keys) -_IMAGE_CONTENT_PART_TYPES: Final = ("image_url", "input_image", "image") +_IMAGE_CONTENT_PART_TYPES: Final = ("image_url", "input_image", "image", "computer_screenshot") _IMAGE_SCAN_MAX_DEPTH: Final = 4 @@ -564,8 +564,8 @@ def _message_contains_image_content(message: object) -> bool: case {"type": "function_call_output" | "custom_tool_call_output" | "tool_result", "output": list()}: output: Final = _CONTENT_PART.validate_python(message)["output"] return _content_parts_contain_image(_CONTENT_PARTS.validate_python(output)) - case {"type": "computer_call_output", "output": {"type": "computer_screenshot", "image_url": str()}}: - return True + case {"type": "computer_call_output", "output": dict()}: + return _content_parts_contain_image((_CONTENT_PART.validate_python(message)["output"],)) case _: return False diff --git a/tests/unit/test_router/test_router.py b/tests/unit/test_router/test_router.py index 0a4abb12ca5..9bfa78ab288 100644 --- a/tests/unit/test_router/test_router.py +++ b/tests/unit/test_router/test_router.py @@ -31826,8 +31826,10 @@ def test_router_warns_when_a_deployment_enforces_endpoints_without_a_list(caplog ("/v1/messages", "malformed", {}), ("/v1/messages", 5, {}), ("/v1/messages", None, {"messages": ["malformed"]}), + ("/v1/responses", None, {"input": [{"type": "computer_call_output", "output": {"type": "text", "text": "no image"}}]}), + ("/v1/responses", None, {"input": [{"type": "computer_call_output", "output": "malformed"}]}), ], - ids=["moderation-list", "embedding-empty-messages", "message-entry", "message-string", "message-number", "kwargs-messages"], + ids=["moderation-list", "embedding-empty-messages", "message-entry", "message-string", "message-number", "kwargs-messages", "computer-output-text", "computer-output-string"], ) async def test_image_routing_leaves_non_image_and_malformed_requests_to_the_endpoint( mode: str, metadata_key: str | None, route: str, messages: object, request_kwargs: dict[str, object] @@ -31860,8 +31862,12 @@ async def test_image_routing_leaves_non_image_and_malformed_requests_to_the_endp {"input": [{"type": "function_call_output", "call_id": "call_image", "output": [{"type": "input_image", "image_url": "https://example.invalid/image.png"}]}]}, {"input": [{"type": "custom_tool_call_output", "call_id": "call_image", "output": [{"type": "input_image", "image_url": "https://example.invalid/image.png"}]}]}, {"input": [{"type": "computer_call_output", "call_id": "call_image", "output": {"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}}]}, + {"input": [{"role": "user", "content": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]}, + {"input": [{"type": "function_call_output", "call_id": "call_image", "output": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]}, + {"input": [{"type": "custom_tool_call_output", "call_id": "call_image", "output": [{"type": "computer_screenshot", "image_url": "https://example.invalid/image.png"}]}]}, + {"input": [{"type": "computer_call_output", "call_id": "call_image", "output": {"type": "computer_screenshot", "url": "https://example.invalid/image.png"}}]}, ], - ids=["chat", "responses", "anthropic", "tool-result", "function-output", "custom-output", "computer-output"], + ids=["chat", "responses", "anthropic", "tool-result", "function-output", "custom-output", "computer-output", "screenshot-content", "screenshot-function-output", "screenshot-custom-output", "screenshot-url"], ) def test_image_routing_inspects_native_request_content_without_translation(request_kwargs: dict[str, object]) -> None: router: Final = _mixed_router(_VISION_LEG, _DECLARED_TEXT_LEG)