[Bugfix] Reject empty tools array with HTTP 400 (#39780)

Signed-off-by: Jigang Zhou <zjg0907008@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
jigangz
2026-04-16 12:08:04 +08:00
committed by GitHub
co-authored by Claude
parent c0722f22de
commit 18013df6ae
4 changed files with 23 additions and 23 deletions
@@ -26,15 +26,15 @@ def test_chat_completion_request_with_no_tools():
)
assert request.tool_choice == "none"
# tools key present but empty
request = ChatCompletionRequest.model_validate(
{
"messages": [{"role": "user", "content": "Hello"}],
"model": "facebook/opt-125m",
"tools": [],
}
)
assert request.tool_choice == "none"
# tools key present but empty -- should be rejected
with pytest.raises(ValueError, match="must not be an empty array"):
ChatCompletionRequest.model_validate(
{
"messages": [{"role": "user", "content": "Hello"}],
"model": "facebook/opt-125m",
"tools": [],
}
)
@pytest.mark.parametrize("tool_choice", ["auto", "required"])