fix(responses): preserve custom tools through guardrails - #34361
Draft
mayank-affirm wants to merge 1 commit into
Draft
Conversation
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
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.
TLDR
Problem this solves:
How it solves it:
Relevant issues
Follow-up to #32258
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays 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
The proxy used a live provider-backed model with a pass-through request and response guardrail
Request used for both runs:
{ "model": "glm-local", "input": "Call exec with exactly text(\"OK\"). Do not answer in prose.", "tools": [ { "type": "custom", "name": "exec", "description": "Execute JavaScript and return its output", "format": { "type": "grammar", "syntax": "lark", "definition": "start: /[\\s\\S]+/" } } ], "tool_choice": { "type": "custom", "name": "exec" }, "max_output_tokens": 100 }Before (
baf85d7):After (
4fbe675):{ "status": "completed", "output": [ { "type": "custom_tool_call", "name": "exec", "input": "text(\"OK\")", "arguments": null } ] }Type
🐛 Bug Fix
Changes
The Responses bridge added in #32258 projects custom tools into functions for Chat Completions providers. Responses guardrail processing kept that projected function after inspection, so downstream clients received a
function_callinstead of the originalcustom_tool_call. Response guardrails also omitted custom calls from completed responses andresponse.output_item.donestreaming eventsThis change restores an original custom tool only when the guardrail output exactly matches its function projection. Guardrail removals, reordering, modifications, and injected tools remain intact. Forced custom tool choices are translated for the provider, raw custom inputs are wrapped for guardrail inspection, and tool-call output indexes are preserved
Regression tests cover unchanged and modified custom tools, removed and reordered tools, injected tools, forced custom choices, Pydantic and dictionary outputs, completed and streaming responses, guardrail blocking, and output index preservation
Final Attestation