sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

[BUG] @tool turns *args / **kwargs into required inputs, so a tool with **kwargs fails validation

Open 1AbdullahButt opened this issue 2 weeks ago • 2 comments

Human Overview

  • A tool function with **kwargs gets a required field literally named kwargs.
  • If the model doesn’t send it, validation fails. If it does, the function receives {"kwargs": {...}} instead of the real values.
  • Why it matters: any flexible tool that takes extra keyword arguments can’t be used.

Checks

  • [x] I have updated to the lastest minor and patch version of Strands
  • [x] I have checked the documentation and this is not expected behavior
  • [x] I have searched ./issues and there are no duplicates of my issue

SDK Language

Python

Strands Version

main at 1060ccee1 (1.64.1.dev91)

Language Runtime Version

Python 3.12.10

Operating System

Windows 11

Installation Method

git clone

Steps to Reproduce

import asyncio, json
from typing import Any
from strands import tool

@tool
def lookup(query: str, **kwargs: Any) -> str:
    """Look something up.

    Args:
        query: What to look up.
    """
    return f"{query} {kwargs}"

print(json.dumps(lookup.tool_spec["inputSchema"]["json"], indent=1))

async def main():
    async for event in lookup.stream({"toolUseId": "1", "name": "lookup", "input": {"query": "x"}}, {}):
        pass
    print(event["tool_result"])

asyncio.run(main())

Expected Behavior

*args and **kwargs are not tool inputs, so they are left out of the schema, and a call with only query runs the function.

Actual Behavior

The schema lists kwargs as a required property (*args is handled the same way, as a required args string):

"required": ["query", "kwargs"]

A call with only query fails validation, so the function never runs:

{'toolUseId': '1', 'status': 'error', 'content': [{'text': "Error: Validation failed for input parameters: 1 validation error for LookupTool\nkwargs\n  Field required ..."}]}

If the model does send kwargs or args, they are passed as keyword arguments with those names, so the function receives kwargs == {"kwargs": ...} instead of the values.

Possible Solution

FunctionToolMetadata._create_input_model turns every signature parameter into a pydantic field. Skipping parameters whose kind is inspect.Parameter.VAR_POSITIONAL or inspect.Parameter.VAR_KEYWORD there would fix it.

Happy to send a fix if that helps.

Drafted with Claude Code (AI); the repro above was run locally against main.

1AbdullahButt avatar Nov 12 '26 19:11 1AbdullahButt

We could consider adding validation to more explicitly state that kwargs isn't supported. The model needs a well defined schema and so explicitly defining the supported inputs is necessary. Kwargs thus doesn't fit in this model.

pgrayy avatar Nov 12 '26 22:11 pgrayy

Makes sense. Would a PR that raises a clear error when a @tool function uses *args/**kwargs be welcome?

1AbdullahButt avatar Nov 12 '26 23:11 1AbdullahButt