Skip to content

Fix tool schema generation for variadic parameters#22170

Open
fengjikui wants to merge 1 commit into
run-llama:mainfrom
fengjikui:codex/function-tool-skip-variadic-schema
Open

Fix tool schema generation for variadic parameters#22170
fengjikui wants to merge 1 commit into
run-llama:mainfrom
fengjikui:codex/function-tool-skip-variadic-schema

Conversation

@fengjikui

Copy link
Copy Markdown

Summary

Fixes #22134.

create_schema_from_function previously treated variadic *args and **kwargs as normal tool parameters. For functions such as:

def search(query: str, **kwargs: str) -> None: ...

this exposed a phantom kwargs property in the generated JSON schema and marked it as required, which can make strict tool/function-calling providers reject the schema.

Changes

  • Skip inspect.Parameter.VAR_POSITIONAL and inspect.Parameter.VAR_KEYWORD when building tool schemas.
  • Add a regression test covering *args and **kwargs, asserting only regular parameters are exposed.

Validation

  • Before the fix, tests/tools/test_utils.py::test_create_schema_from_function_ignores_variadic_parameters failed because args and kwargs were present in schema properties.
  • uv run --directory llama-index-core pytest tests/tools/test_utils.py -q
  • uv run --directory llama-index-core pytest tests/tools/test_utils.py tests/tools/test_base.py -q
  • uv run ruff format --check llama-index-core/llama_index/core/tools/utils.py llama-index-core/tests/tools/test_utils.py
  • uv run ruff check llama-index-core/llama_index/core/tools/utils.py llama-index-core/tests/tools/test_utils.py

@fengjikui fengjikui marked this pull request as ready for review June 27, 2026 17:48
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 27, 2026
@gautamvarmadatla

Copy link
Copy Markdown
Contributor

hi @fengjikui issue author here, please see #22135 it already has the fix :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Tool schema marks **kwargs as a required (untyped) parameter, forcing the LLM to fill it

2 participants