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: return an error when a model can't use the tools sent to it (#11960)

Nilaydbba692171ca
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 83bcbc4ae5f..cf94a0941a4 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -29297,16 +29297,30 @@ async def produce_openai_chat_completions(
if _continue_final_message(payload):
gen_kwargs["continue_final_message"] = True
- # ── Client-tool passthrough (safetensors + MLX) ──────────────
- # Client tools (or tool-result history) without server-side tools: render
- # tools into the template, generate one turn, heal text-form calls (#6801).
- # supports_tools=False falls through to plain relay (GGUF gate parity).
+ # Client-tool passthrough (safetensors + MLX): render client tools, generate one turn,
+ # heal text-form calls (#6801). A catalog the model cannot render is refused, as on GGUF.
_sf_has_tool_msgs = any(m.role == "tool" or m.tool_calls for m in payload.messages)
# Classified against the processor body above, before the server loop's own gate:
# that gate reads the same flag, and deciding it here left the loop enabled on a
# tokenizer body that renders tools while generation used a processor body that
# does not, so the model was never shown the schemas the loop was driving.
_sf_supports_tools = _sf_features.get("supports_tools", False)
+ if _has_active_tool_catalog and (_sf_is_gptoss or not _sf_supports_tools):
+ raise _reject(
+ 400,
+ openai_error_body(
+ (
+ "Client-supplied tools are not supported for gpt-oss on this backend; "
+ "load a GGUF build of the model."
+ if _sf_is_gptoss
+ else "Client-supplied tools require a chat template with tool-call support; "
+ "the current model/template does not advertise tools."
+ ),
+ status = 400,
+ code = "unsupported_parameter",
+ param = "tools",
+ ),
+ )
# Gate on _sf_use_tools (did the server-side path claim the request?), not
# raw mcp_enabled: an empty MCP registry must not silently drop client tools.
_sf_client_tools = (
diff --git a/studio/backend/tests/test_sf_client_tools_passthrough.py b/studio/backend/tests/test_sf_client_tools_passthrough.py
index 68d5cdd5e3f..61302f63714 100644
--- a/studio/backend/tests/test_sf_client_tools_passthrough.py
+++ b/studio/backend/tests/test_sf_client_tools_passthrough.py
@@ -905,6 +905,65 @@ def test_tool_choice_none_does_not_advertise_tools(monkeypatch):
assert backend.calls[0]["tools"] is None
+_CLIENT_TOOL_HISTORY = [
+ {"role": "user", "content": "look up cats"},
+ {
+ "role": "assistant",
+ "content": None,
+ "tool_calls": [
+ {
+ "id": "call_1",
+ "type": "function",
+ "function": {"name": "lookup", "arguments": '{"q": "cats"}'},
+ }
+ ],
+ },
+ {"role": "tool", "tool_call_id": "call_1", "content": "cats are mammals"},
+]
+
+
+ "kwargs",
+ [
+ dict(tools = [LOOKUP_TOOL], tool_choice = "required"),
+ dict(tools = [LOOKUP_TOOL]),
+ dict(tools = [LOOKUP_TOOL], messages = _CLIENT_TOOL_HISTORY),
+ dict(tools = [LOOKUP_TOOL], enable_tools = True),
+ ],
+)
[email protected]("gptoss", [False, True])
+def test_client_tools_the_model_cannot_take_are_refused(monkeypatch, kwargs, gptoss):
+ backend = _ScriptedBackend(_fixed("prose instead of a call"))
+ if gptoss:
+ backend._is_gpt_oss_model = lambda: True
+ payload = _request(stream = False, **kwargs)
+ entry, error = _monitor_entry(payload, monkeypatch, backend, supports_tools = gptoss)
+
+ assert error is not None and error.status_code == 400
+ assert error.detail["error"]["code"] == "unsupported_parameter"
+ assert error.detail["error"]["param"] == "tools"
+ assert ("gpt-oss" in error.detail["error"]["message"]) is gptoss
+ assert backend.calls == []
+ assert entry["status"] == "error"
+
+
+ "kwargs",
+ [
+ dict(tools = [LOOKUP_TOOL], tool_choice = "none"),
+ dict(tools = [LOOKUP_TOOL], tool_choice = "none", messages = _CLIENT_TOOL_HISTORY),
+ dict(messages = _CLIENT_TOOL_HISTORY),
+ dict(enable_tools = True),
+ ],
+)
+def test_requests_without_an_active_client_catalog_still_answer(monkeypatch, kwargs):
+ backend = _ScriptedBackend(_fixed("plain answer"))
+ payload = _request(stream = False, **kwargs)
+ body = _json_body(_call(payload, monkeypatch, backend, supports_tools = False))
+ assert body["choices"][0]["message"]["content"] == "plain answer"
+ assert backend.calls[0]["tools"] is None
+
+
def test_developer_message_folded_into_system_prompt(monkeypatch):
# The "developer" role folds into one leading system message (local templates reject it).
backend = _ScriptedBackend(_fixed("ok"))
diff --git a/studio/backend/tests/test_vision_client_tools.py b/studio/backend/tests/test_vision_client_tools.py
index 00271dd8ec2..23d9be18d0a 100644
--- a/studio/backend/tests/test_vision_client_tools.py
+++ b/studio/backend/tests/test_vision_client_tools.py
@@ -860,6 +860,8 @@ def test_a_named_processor_template_is_classified_without_tool_use():
it advertised a catalog the prompt never shows (#10092)."""
import asyncio
+ from fastapi import HTTPException
+
_pytest = _shared_setup_1(__file__)
import routes.inference as inf
@@ -901,12 +903,14 @@ def test_a_named_processor_template_is_classified_without_tool_use():
payload, request = passthrough._Request(), current_subject = "u"
)
- asyncio.run(_run())
+ with _pytest.raises(HTTPException) as exc:
+ asyncio.run(_run())
finally:
monkeypatch.undo()
- assert backend.calls, "generation never ran"
- assert not backend.calls[0]["tools"]
+ assert exc.value.status_code == 400
+ assert exc.value.detail["error"]["param"] == "tools"
+ assert backend.calls == []
def test_a_historical_image_stays_on_the_turn_that_sent_it():