LitServe icon indicating copy to clipboard operation
LitServe copied to clipboard

OpenAISpec rejects standard required and named function tool_choice values

Open emecii opened this issue 2 months ago • 0 comments

🐛 Bug

OpenAISpec rejects two standard Chat Completions tool_choice values during request validation:

  • "required"
  • a named function choice such as {"type": "function", "function": {"name": "lookup_weather"}}

The current request model accepts only "auto", "none", and the non-standard compatibility value "any". As a result, clients using either standard form receive HTTP 422 before LitAPI.decode_request runs. OpenAI's current Chat Completions API reference documents both "required" and a named function object in tool_choice.

Reproduction

On current main (7675990):

from litserve.specs.openai import ChatCompletionRequest

base = {
    "model": "lit",
    "messages": [{"role": "user", "content": "Use the weather tool"}],
}

ChatCompletionRequest(**base, tool_choice="required")
ChatCompletionRequest(
    **base,
    tool_choice={"type": "function", "function": {"name": "lookup_weather"}},
)

Both constructions raise a Pydantic validation error saying the input should be auto, none, or any. The same payloads sent to /v1/chat/completions return HTTP 422.

Expected behavior

OpenAISpec should accept the standard "required" literal and named-function object, preserve them on ChatCompletionRequest, and pass them through the existing request/context path. Existing "auto", "none", and "any" behavior should remain compatible.

Proposed scope

Extend only the tool_choice request schema and add focused CPU-only request-model and endpoint regressions. This does not change tool execution or selection inside user code.

Environment

  • LitServe main at 7675990
  • Python 3.12
  • CPU only; no model download, GPU, or hosted service required

I used Codex assistance to investigate and prepare this report. No maintainer agreement or human review is claimed.

emecii avatar Sep 10 '26 05:09 emecii