fix: coerce string-valued tool arguments to declared scalar types#25731
Open
sanidhyasin wants to merge 1 commit into
Open
fix: coerce string-valued tool arguments to declared scalar types#25731sanidhyasin wants to merge 1 commit into
sanidhyasin wants to merge 1 commit into
Conversation
Native function calling can emit numeric/boolean tool parameters as strings (e.g. "1" instead of 1). Builtin tools declare int/float/bool type hints but never coerced the runtime values, so the first comparison or arithmetic on such a value raised TypeError (e.g. min(count, max_count) in search_web), crashing the tool call and returning an error to the model. Coerce string-valued arguments to their declared scalar type in the shared tool wrapper (get_async_tool_function_and_apply_extra_params), so the fix covers every builtin and user-defined tool. Coercion is best-effort: only str values are touched, and unparseable values are passed through unchanged to preserve existing behaviour.
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.
Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch.dev, and contains no unrelated commits.fixChangelog Entry
Description
Models using native function calling (
function_calling: native) sometimes emit numeric or boolean tool parameters as strings — e.g.count="1"instead ofcount=1. The builtin tools declareint/Optional[int]/bool/floattype hints but never coerced the actual runtime values, so the first comparison or arithmetic on such a value raised:For example,
search_webcrashes oncount = max(1, min(count, max_count))(builtin.py), so the model receives an error response instead of search results.Fix: coerce string-valued arguments to their declared scalar type inside the shared tool wrapper
get_async_tool_function_and_apply_extra_params(backend/open_webui/utils/tools.py). Because every builtin and user-defined tool is invoked through this wrapper, the fix is centralized rather than scattered across individual tools.The coercion is best-effort and non-intrusive:
strvalues are touched; values that already have the correct type are left untouched.int/float/bool(and theirOptional[...]forms) are supported.intalso tolerates integral floats like"1.0".true/false/1/0/yes/no/on/offspellings.count="abc") are passed through unchanged, preserving existing behaviour.get_type_hintsfailures fall back to no coercion.Fixed
TypeErrorwhen a model passes numeric/boolean parameters as strings via native function calling (e.g.search_web(count="1")).Additional Information
Manual Verification Performed
Validated the coercion against representative tool signatures (
search_web(query: str, count: Optional[int]), and a tool withbool/float/intparams):count="1"Optional[int]1(andmin(count, max_count)no longer raises)count="3.0"Optional[int]3count=NoneOptional[int]None(unchanged)count=2Optional[int]2(unchanged)count="abc"Optional[int]"abc"(unchanged)case_insensitive="false"boolFalseratio="0.5"float0.5query="weather"str"weather"(unchanged)Contributor License Agreement
Note
Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.