Skip to content

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.

Studio: name what is wrong with a text part that has no text

danielhanchenbfcc3f6c9168
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index a648976f351..70705df2d52 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -27766,6 +27766,17 @@ def _reject_unserviceable_responses_attachment(part, *, role = "user") -> None:
as well as, so it validates and is served from the URL on this path and on that one.
"""
part_type = getattr(part, "type", None)
+ if part_type in ("input_text", "output_text") and not isinstance(
+ part, (ResponsesInputTextPart, ResponsesOutputTextPart)
+ ):
+ # A text part that lost its `text` field is a ResponsesUnknownContentPart wearing a
+ # known type name, so it passes a name-only allowlist and is then dropped by both the
+ # flatten and the parts loop. Say what is wrong with it, the way the tool-result path
+ # does, rather than "parts of type 'input_text' are not supported", which is untrue.
+ _raise_unsupported_openai_parameter(
+ "input",
+ f"Responses {part_type} message parts require a text field.",
+ )
if part_type == "input_file":
_raise_unsupported_openai_parameter(
"input",
diff --git a/studio/backend/tests/test_responses_tool_passthrough.py b/studio/backend/tests/test_responses_tool_passthrough.py
index 8c6da0257fc..b4c0869de7c 100644
--- a/studio/backend/tests/test_responses_tool_passthrough.py
+++ b/studio/backend/tests/test_responses_tool_passthrough.py
@@ -1152,6 +1152,49 @@ class TestResponsesMessagePartMatrix:
assert part["type"] in str(exc.value.detail)
assert role in str(exc.value.detail)
+ @pytest.mark.parametrize("role", ["system", "developer", "user", "assistant"])
+ @pytest.mark.parametrize(
+ "part",
+ [
+ {"type": "input_text"},
+ {"type": "input_text", "text": None},
+ {"type": "input_text", "text": 123},
+ {"type": "output_text"},
+ ],
+ ids = ["no_text", "null_text", "int_text", "output_no_text"],
+ )
+ def test_a_text_part_without_text_is_named_for_what_is_wrong(self, role, part):
+ # It fails its typed variant and becomes a ResponsesUnknownContentPart wearing a known
+ # type name, so a name-only allowlist waves it through and both the flatten and the
+ # parts loop then drop it. "type 'input_text' is not supported" would also be untrue.
+ payload = ResponsesRequest(
+ input = [
+ {"role": role, "content": [part]},
+ {"role": "user", "content": "go on"},
+ ],
+ )
+ with pytest.raises(HTTPException) as exc:
+ _normalise_responses_input(payload)
+ assert exc.value.status_code == 400
+ assert "require a text field" in str(exc.value.detail)
+ assert part["type"] in str(exc.value.detail)
+
+ def test_a_malformed_text_part_does_not_hide_behind_a_good_one(self):
+ # The turn still had servable text, so before this the request succeeded and only the
+ # broken part went missing.
+ payload = ResponsesRequest(
+ input = [
+ {
+ "role": "system",
+ "content": [{"type": "input_text", "text": "keep"}, {"type": "input_text"}],
+ },
+ {"role": "user", "content": "go on"},
+ ],
+ )
+ with pytest.raises(HTTPException) as exc:
+ _normalise_responses_input(payload)
+ assert "require a text field" in str(exc.value.detail)
+
@pytest.mark.parametrize("part_type", ["refusal", "summary_text"])
def test_assistant_output_metadata_survives_the_flatten(self, part_type):
# refusal and summary_text are the model's own output, which clients round-trip.