litellm/tests/unit/responses/litellm_completion_transformation
Kerry Lu 7e6479b3a0
fix(completion): accept a tool_choice that forces an OpenAI hosted tool (#50578)
* fix(completion): accept a tool_choice that forces an OpenAI hosted tool

litellm.completion rejected tool_choice={"type": "web_search"} before any request, while /v1/responses took the same choice. The chat validator now forwards a hosted tool type unchanged and a provider gate turns it into a 400 off openai, azure and litellm_proxy, where the choice would otherwise be dropped or mangled.

Fixes #50566

* fix(utils): keep a non-string tool_choice type a 400, not a TypeError

A list or dict in tool_choice["type"] is unhashable, so the hosted tool lookup needs the string check first. The bridge test that used file_search as an untranslatable choice now uses a type that really is unknown.

* refactor(completion): forward any Responses API tool_choice type instead of keeping a hosted tool allowlist

Chat completions now accepts any tool_choice dict with a string type it has no shape for and sends it as is on openai, azure and litellm_proxy, where OpenAI validates the type itself (a typo is still a 400, from OpenAI). The provider gate keeps the 400 everywhere else. The HOSTED_TOOL_CHOICE_TYPES list is gone, so a new OpenAI hosted tool needs no change here.

* Revert "refactor(completion): forward any Responses API tool_choice type instead of keeping a hosted tool allowlist"

This reverts commit 5a6d5a8e08.

* fix(utils): add tool_search to the hosted tool_choice types

OpenAI lists it among the supported tool_choice.type values (live error on 2026-11-08), alongside the ones already in the set.

---------

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-11-07 17:54:57 -08:00
..
__init__.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_anthropic_responses_bridge.py fix(anthropic): answer 400 naming a non-string role or tool call id instead of 500 (#49237) 2026-10-31 21:13:24 +00:00
test_client_tool_search.py feat(responses): support Codex client tool_search on Anthropic and other bridged providers (#48972) 2026-10-29 00:29:40 -07:00
test_compaction_items.py fix(responses)!: round-trip Anthropic compaction blocks as compaction items (#46754) 2026-10-21 08:50:19 +00:00
test_count_request.py fix(anthropic): answer 400 naming a non-string role or tool call id instead of 500 (#49237) 2026-10-31 21:13:24 +00:00
test_function_call_output_normalization.py fix(responses): normalize empty function_call_output to an empty tool result (#48845) 2026-10-30 11:01:00 -07:00
test_google_ai_studio_responses_bridge.py test: move the unit half of 126 mixed legacy files into tests/unit (#45090) 2026-10-07 14:07:43 -07:00
test_google_ai_studio_responses_wire.py fix(responses): normalize empty function_call_output to an empty tool result (#48845) 2026-10-30 11:01:00 -07:00
test_handler.py fix(anthropic): answer 400 naming a non-string role or tool call id instead of 500 (#49237) 2026-10-31 21:13:24 +00:00
test_image_generation_output.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_litellm_completion_responses.py fix(completion): accept a tool_choice that forces an OpenAI hosted tool (#50578) 2026-11-07 17:54:57 -08:00
test_reasoning_input_item_preservation.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00
test_reasoning_items.py feat(proxy): mixed Codex model picker and LiteLLM routing on native codex routes (#49408) 2026-11-06 11:14:47 -08:00
test_session_handler.py fix(spend)!: save streamed /v1/responses spend rows under the encrypted resp_ id the client received (#49493) 2026-11-02 14:13:17 -08:00
test_session_handler_with_cold_storage.py fix(spend_logs): persist user email in spend log metadata so it shows in UI request logs (#41150) 2026-10-17 13:26:09 -07:00
test_streaming_iterator_transformation.py fix(anthropic)!: do not surface server_tool_use as client tool_calls (#48385) 2026-11-06 03:54:34 -08:00
test_tool_output_order_preserved_for_gemini.py test: move tests/test_litellm core utils, routing, responses, caching and rust_bridge into tests/unit (#43199) 2026-09-25 17:10:13 -07:00