Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llama-index-core/llama_index/core/tools/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from inspect import signature
from inspect import Parameter, signature
from typing import (
Any,
Awaitable,
Expand Down Expand Up @@ -40,6 +40,11 @@ def create_schema_from_function(
for param_name in params:
if param_name in ignore_fields:
continue
if params[param_name].kind in (
Parameter.VAR_POSITIONAL,
Parameter.VAR_KEYWORD,
):
continue

param_type = params[param_name].annotation
param_default = params[param_name].default
Expand Down
13 changes: 13 additions & 0 deletions llama-index-core/tests/tools/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ def test_fn2(x: int = 1) -> None:
assert "required" not in schema


def test_create_schema_from_function_ignores_variadic_parameters() -> None:
"""Test that *args and **kwargs are not exposed as tool parameters."""

def test_fn(query: str, *args: str, **kwargs: str) -> None:
"""Test variadic inputs."""

SchemaCls = create_schema_from_function("test_schema", test_fn)
schema = SchemaCls.model_json_schema()

assert schema["properties"] == {"query": {"title": "Query", "type": "string"}}
assert schema["required"] == ["query"]


def test_create_schema_from_function_with_field() -> None:
"""Test create_schema_from_function with pydantic.Field."""

Expand Down