Skip to content

tool_choice: "required" is accepted but not enforced #52

Closed

Description

@simonmd

Summary. tool_choice: "required" is accepted but not enforced: the model can answer in plain text with finish_reason: "stop". In OpenAI's API, "required" means the reply must contain at least one tool call.

Environment. TensorFold 0.3.5.1 (beddbb7), Vontra/Qwen3.8-27B-MLX-4bit, Apple M1 Max, macOS 27.0.

Repro:

curl -s http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{
  "model": "qwen3.8-27b", "temperature": 0, "chat_template_kwargs": {"enable_thinking": false},
  "tool_choice": "required",
  "messages": [{"role": "user", "content": "Say hello."}],
  "tools": [{"type": "function", "function": {"name": "get_weather", "description": "Current weather for a city",
    "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]}'

This returns finish_reason: "stop", content "Hello! How can I help you today?", and no tool_calls.

Where. active_tool_specs / tool_choice_disables_tools in server/tools.py act only on "none"; validate_tool_choice checks the named-function form. Nothing else reads "required". tool-eval-bench's TC-45 (tool_choice=required Compliance) fails for this reason. vLLM and SGLang pass it by constraining decoding to a tool call.

If enforcing it is out of scope for now, returning a 400 for "required" would at least avoid silently ignoring it. docs/api.md currently documents only "none".

Activity

  1. simonmd commented on Sep 28, 2026

    @simonmd
    Author

    Verified fixed in 0.3.6.2 (71377a5) on the same setup: Apple M1 Max, macOS 27.0, Vontra/Qwen3.8-27B-MLX-4bit.

    Thanks for the quick fix. This can be closed.

  2. ashhart commented on Sep 28, 2026

    @ashhart
    Owner

    Thanks @simonmd. tool_choice: "required" is enforced in 0.3.6.2 on the Mac and CUDA servers. We don't have a grammar
    engine like vLLM's, so the server fixes only what it has to. After any think block, the answer must open a tool call,
    and the tool's name must be one you offered. If the model starts in prose, that token becomes <tool_call> plus the
    template's text before a name. If it reaches for a tool you didn't offer, the name becomes the first offered one it
    can still spell. The model writes the arguments. A function named in tool_choice works the same way, and the
    template then offers only that tool.

    Each fix depends only on the tokens before it, so drafted, serial ("draft": false) and concurrent requests produce
    the same tokens, and the same request gives the same tokens on a Mac and on a DGX Spark. Your repro now returns a
    get_weather call with finish_reason: "tool_calls", with thinking on or off, streamed or not. Holding the name
    mattered: with only the opener forced, Flash Next called an update_plan tool that wasn't in the request. One limit:
    required parameters aren't enforced, so a model can still send {} to a tool that needs arguments. docs/api.md has
    the details. Release: https://github.com/ashhart/TensorFold/releases/tag/v0.3.6.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions