Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: refuse an image on a responses role that flattens its content
danielhanchen4e6a2cd5f22c
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex f12e616cc27..86439987568 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -27755,7 +27755,7 @@ def _responses_reasoning_output_item(return ResponsesOutputReasoning(**kwargs).model_dump()-def _reject_unserviceable_responses_attachment(part) -> None:+def _reject_unserviceable_responses_attachment(part, *, role = "user") -> None:"""Refuse an attachment the local adapter cannot serve, instead of dropping it.Same four rules and same wording as ``_responses_tool_output_content``, which already@@ -27792,14 +27792,26 @@ def _reject_unserviceable_responses_attachment(part) -> None:"input","Responses input_image message detail must be auto, low, high, or original.",)+ if role != "user":+ _raise_unsupported_openai_parameter(+ "input",+ f"Responses input_image message parts are only supported on user messages; "+ f"{role} content is flattened to text by the local adapter.",+ )def _reject_unserviceable_responses_attachments(item) -> None:- """Run the attachment refusal over one input message's content parts."""+ """Run the attachment refusal over one input message's content parts.++ Role matters for images: only a user turn keeps its parts. Every other role is flattened+ by ``_responses_message_text``, which keeps text and dropped the image in silence, because+ Chat Completions wants a plain string on system and assistant and strict templates reject+ an array there. So an image on those roles cannot be forwarded, only refused.+ """if isinstance(item.content, str):returnfor part in item.content or []:- _reject_unserviceable_responses_attachment(part)+ _reject_unserviceable_responses_attachment(part, role = item.role)def _reject_unknown_responses_message_part(part) -> None:diff --git a/studio/backend/tests/test_responses_message_attachments.py b/studio/backend/tests/test_responses_message_attachments.pyindex 2f4733adcf0..2dac3b26797 100644--- a/studio/backend/tests/test_responses_message_attachments.py+++ b/studio/backend/tests/test_responses_message_attachments.py@@ -105,6 +105,17 @@ def test_the_route_refuses_an_attachment_on_a_non_user_turn(role):assert "input_file" in response.json()["detail"]["error"]["message"][email protected]("role", ["system", "developer", "assistant"])+def test_the_route_refuses_a_servable_image_on_a_role_that_flattens(role):+ # These roles are flattened to a string, so the image was dropped and the turn answered.+ part = {"type": "input_image", "image_url": "https://example.com/a.png"}+ with _route_client() as client:+ response = client.post("/v1/responses", json = _body(part, role = role))++ assert response.status_code == 400, response.text+ assert "only supported on user messages" in response.json()["detail"]["error"]["message"]++@pytest.mark.parametrize("case", _REFUSED_PARTS, ids = _part_id)def test_the_refusal_lands_before_the_model_switch(case, monkeypatch):"""The route holds this for its other refusals: a 400 must not evict the model."""diff --git a/studio/backend/tests/test_responses_tool_passthrough.py b/studio/backend/tests/test_responses_tool_passthrough.pyindex f0b956ada7a..24084c20561 100644--- a/studio/backend/tests/test_responses_tool_passthrough.py+++ b/studio/backend/tests/test_responses_tool_passthrough.py@@ -1072,22 +1072,69 @@ class TestResponsesMessagePartMatrix:@pytest.mark.parametrize("role", ["system", "developer", "assistant"])def test_attachments_refused_on_every_role(self, case, role):# Only attachments are hoisted, so an unmodelled text part passes here while the- # same part is refused on a user turn.+ # same part is refused on a user turn. Every image is refused on these roles,+ # servable or not: _responses_message_text keeps text and would drop it.part, refused, needle = case- attachment = part["type"] in ("input_file", "input_image")payload = ResponsesRequest(input = [{"role": role, "content": [{"type": "input_text", "text": "hi"}, part]},{"role": "user", "content": "go on"},],)- if refused and attachment:- with pytest.raises(HTTPException) as exc:- _normalise_responses_input(payload)- assert exc.value.status_code == 400- assert needle in str(exc.value.detail)+ if part["type"] == "input_file":+ expected = needle+ elif part["type"] == "input_image":+ expected = needle if refused else "only supported on user messages"else:assert _normalise_responses_input(payload)+ return+ with pytest.raises(HTTPException) as exc:+ _normalise_responses_input(payload)+ assert exc.value.status_code == 400+ assert expected in str(exc.value.detail)++ @pytest.mark.parametrize("role", ["system", "developer", "assistant"])+ def test_a_servable_image_is_refused_on_a_role_that_flattens(self, role):+ # The role branches flatten content through _responses_message_text, which keeps only+ # text, so an image that passed every shape check still vanished. Forwarding it is not+ # an option: Chat Completions wants a plain string on system and assistant.+ text_part = (+ {"type": "output_text", "text": "hi"}+ if role == "assistant"+ else {"type": "input_text", "text": "hi"}+ )+ payload = ResponsesRequest(+ input = [+ {+ "role": role,+ "content": [+ text_part,+ {"type": "input_image", "image_url": "https://example.com/a.png"},+ ],+ },+ {"role": "user", "content": "go on"},+ ],+ )+ with pytest.raises(HTTPException) as exc:+ _normalise_responses_input(payload)+ assert exc.value.status_code == 400+ assert "only supported on user messages" in str(exc.value.detail)+ assert role in str(exc.value.detail)++ def test_a_servable_image_still_passes_on_a_user_turn(self):+ payload = ResponsesRequest(+ input = [+ {+ "role": "user",+ "content": [+ {"type": "input_text", "text": "hi"},+ {"type": "input_image", "image_url": "https://example.com/a.png"},+ ],+ }+ ],+ )+ msgs = _normalise_responses_input(payload)+ assert msgs[0].content[1].image_url.url == "https://example.com/a.png"def test_instructions_still_merge_when_a_turn_is_servable(self):payload = ResponsesRequest(