Repository navigation
fix(responses): keep nested function tool fields on the chat bridge - #51527
Open
abenezeradane wants to merge 2 commits into
Open
abenezeradane wants to merge 2 commits into
abenezeradane wants to merge 2 commits into
Conversation
A function tool sent to /v1/responses in the Chat Completions layout reached the provider with an empty name, an empty description and a bare object schema, because the bridge read only top-level fields. The bridge now fills name, description, parameters and strict from the nested function object when the top level does not set them, so an explicit top-level strict false still wins. The Responses tool-name extractor now reads function.name too, through the shared anthropic_tool_names helper, so allowed_tools sees every name a tool can act under and a flat decoy name cannot carry a blocked nested one.
…llowed_tools The deny cases alone let an extractor that adds a stray name for nested tools pass, which would refuse a client whose tools are all allowed. Assert the exact name list for a nested tool and a hybrid tool instead.
Contributor
PR overviewNo security issues were found in this pull request. Reviews
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Handwritten 1-3 sentence description
The proxy now keeps the name, description, and schema of a Chat Completions function tool that a client sends to the Responses API. Before this change, the provider received a tool with no name, so the model did not use it. The proxy compares this tool name with the tool list of the key and stops the request if the tool is not on the list.
Details
TLDR
Problem this solves:
/v1/responseslost name, description, schema and strictallowed_toolskeys reach blocked nested toolsHow it solves it:
functionobjectstrict: falsestays false/v1/responsesallowlist also checksfunction.name, like/v1/messagesdoesIntentional product change: a key with
allowed_toolsnow gets 403 for a Chat Completions shaped tool whosefunction.nameis not on its list. Before, the proxy skipped that tool, and the chat bridge sent it on without a name.User Flow
Before: a client that sends Chat Completions shaped function tools to
/v1/responseson a chat-bridged model never gets a tool call, and a restricted key's tool list never sees those tools"tools": [{"type": "function", "function": {"name": "read_file", ...}}]function_callmetadata.allowed_toolsis["get_weather"]sends the same tool and gets 200After: the same request reaches the model with the real tool, and the restricted key is refused
read_filewith its description, itspathschema andstrict: truefunction_call read_file({"path":"notes/todo.txt"})in 3 of 3 runstool_access_deniednamingread_file, also when a flatget_weathername wraps itRelevant issues
Fixes #27276. Its custom tool half already shipped in 1.97.0, so this closes the remaining nested function tool half.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Both runs used the same 2-worker proxy setup, one dedicated Redis for router state and coordination, Postgres for virtual keys, and local Ollama 0.40.15 serving
hf.co/JetBrains/Mellum2.1-12B-A2.5B-Thinking-GGUF:Q4_K_Mthrough the OpenAI-compatible chat endpoint. The curl requests replay the tool layout from the issue's reproduction. No coding tool is installed on this machine, so none was driven.Shared setup: containers, env vars, config, proxy command
docker run -d --rm --name litellm-qa-redis -p 127.0.0.1:6391:6379 redis:7.4.2 docker run -d --rm --name litellm-qa-pg -e POSTGRES_USER=litellm -e POSTGRES_PASSWORD="$QA_PG_PASSWORD" \ -e POSTGRES_DB=litellm -p 127.0.0.1:5491:5432 postgres:18-alpineEnv vars, values not shown:
LITELLM_MASTER_KEY(a randomsk-key),QA_PG_PASSWORD, andDATABASE_URL=postgresql://litellm:$QA_PG_PASSWORD@127.0.0.1:5491/litellm.proxy_config.yamlislitellm/proxy/dev_config.yamlwith this diff:Before ran from
git archive 40debbb9c0 litellm | tar -xin a scratch directory, with the builtlitellm/rust_bridge/_native.abi3.socopied in andPYTHONPATHpointing at that directory. After ran from the checkout at the PR tip. Port 4127 was Before and 4128 was After.Each log shows two
Started server processlines with different PIDs (Before 19835 and 19836, After 22169 and 22170) and twoApplication startup completelines.--use_v2_migration_resolvernow only prints a deprecation notice because v2 is the default, and it stays to match the AGENTS.md command.Client script
proof.sh, run asbash proof.sh 4127andbash proof.sh 4128The tool payloads that reached Ollama come from the
POST Request Sent from LiteLLMlines that--detailed_debugwrites, pulled withgrep -o "'tools': \[.*\], 'extra_body'" <proxy log>.Before (40debbb)
Chat Completions shaped tool, master key
bash proof.sh 4127, bridge partKey with
metadata.allowed_tools: ["get_weather"]bash proof.sh 4127, allowlist partget_weatherwith the nested schema dropped, and the control kept its own schemaAfter (ec97a6e)
Chat Completions shaped tool, master key
bash proof.sh 4128, bridge partKey with
metadata.allowed_tools: ["get_weather"]bash proof.sh 4128, allowlist partTests, mutation check and gates
The regression tests live in
test_litellm_completion_responses.py(TestToolTransformation),test_openai_responses_guardrail_tool_merge.pyandtest_tools_allowlist_enforcement.py. Each mutant below was applied to the PR tip on its own and run against the new tests, and every one turned them red.set_top_level_fields_winandexplicit_top_level_strict_false_winsfailexplicit_top_level_strict_false_winsfailsnone_top_level_fields_fall_back_to_nestedfailsflat_name_behind_nested_decoyfailsfunctionis not validated: the string and list cases of the non-object test failtest_openai_responses_chat_completions_shaped_tools_yield_every_namefailsThe five lint gates (
ruff_strict_gate,type_discipline_gate,test_quality_gate,openapi_docs_gate,type_check_gate) pass againstorigin/mainat ec97a6e. Locally,tests/unit/responses,tests/unit/llms/openai/responses,tests/unit/proxy/guardrailsandtests/unit/proxy/test_tools_allowlist_enforcement.pypass (8862 tests), and so do the other callers of the bridge intests/unit/litellm_core_utils/prompt_templates,tests/unit/router_utilsandtests/unit/router_strategy(5479 tests). Seven tests were left out because this machine lacks their environment. Six are inguardrail_hooks/semantic_guardand needsemantic_router, andtest_deep_tool_arguments_parser_limit_keeps_raw_masking_fallbacknever reaches its JSON recursion guard on Python 3.14.Type
🐛 Bug Fix
Caveats (if any)
Severe
allowed_toolsnow get 403 for nested tools outside their listallowed_toolsLow
/v1/responsesallowlist, same as/v1/messages"name": 123got 403. Now Ollama refuses it with 400, so no model sees itdefer_loadingnamestill beats a nested one, since only None counts as unsetFinal Attestation