{"record":{"id":"d7ff684ab295c057","repo":"langchain-ai/langchain","slug":"too-many-arguments-for-tool-decorator-a-decorator","errorCode":null,"errorMessage":"Too many arguments for tool decorator. A decorator ","messagePattern":"Too many arguments for tool decorator\\. A decorator ","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/tools/convert.py","lineNumber":357,"sourceCode":"            return Tool(\n                name=tool_name,\n                func=func,\n                description=tool_description,\n                return_direct=return_direct,\n                coroutine=coroutine,\n                response_format=response_format,\n                extras=extras,\n            )\n\n        return _tool_factory\n\n    if len(args) != 0:\n        # Triggered if a user attempts to use positional arguments that\n        # do not exist in the function signature\n        # e.g., @tool(\"name\", runnable, \"extra_arg\")\n        # Here, \"extra_arg\" is not a valid argument\n        msg = \"Too many arguments for tool decorator. A decorator \"\n        raise ValueError(msg)\n\n    if runnable is not None:\n        # tool is used as a function\n        # for instance tool_from_runnable = tool(\"name\", runnable)\n        if not name_or_callable:\n            msg = \"Runnable without name for tool constructor\"\n            raise ValueError(msg)\n        if not isinstance(name_or_callable, str):\n            msg = \"Name must be a string for tool constructor\"\n            raise ValueError(msg)\n        return _create_tool_factory(name_or_callable)(runnable)\n    if name_or_callable is not None:\n        if callable(name_or_callable) and hasattr(name_or_callable, \"__name__\"):\n            # Used as a decorator without parameters\n            # @tool\n            # def my_tool():\n            #    pass\n            return _create_tool_factory(name_or_callable.__name__)(name_or_callable)","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/tools/convert.py#L339-L375","documentation":"The @tool decorator accepts at most one positional argument (a name string or the function itself). This error means extra positional arguments were passed, i.e. the decorator was used with a signature the API does not support — everything besides the first positional must be keyword-only.","triggerScenarios":"@tool('name', runnable, 'extra') or tool('name', func, True); any call to tool(...) with len(args) > 1 positionally.","commonSituations":"Assuming @tool supports positional (name, func) style like older or different APIs; copy-pasting decorator usage from another library; typos adding stray positional args.","solutions":["Pass only the name positionally and everything else by keyword: @tool('search', return_direct=True)","To convert a Runnable, use tool('name', runnable=runnable)","To decorate a function, apply @tool directly or @tool('name') — never pass the function positionally to tool()"],"exampleFix":"# before\nmy_tool = tool(\"search\", my_func, True)\n\n# after\nmy_tool = tool(\"search\", return_direct=True)(my_func)\n# or\n@tool(\"search\", return_direct=True)\ndef my_func(query: str) -> str: ...","handlingStrategy":"validation","validationCode":"import inspect\n\ndef safe_tool_call(*args, **kwargs):\n    \"\"\"Enforce @tool's one-positional-argument contract.\"\"\"\n    if len(args) > 1:\n        msg = \"tool() takes at most 1 positional argument; pass the rest by keyword\"\n        raise TypeError(msg)\n    return tool(*args, **kwargs)","typeGuard":null,"tryCatchPattern":"try:\n    t = tool(\"name\", func, True)\nexcept ValueError as e:\n    if \"Too many arguments\" in str(e):\n        t = tool(\"name\", return_direct=True)(func)\n    else:\n        raise","preventionTips":["Use the decorator form (@tool or @tool('name')) instead of calling tool() positionally","Pass Runnables via the runnable= keyword only","Treat any second positional argument to tool() as a bug"],"tags":["langchain","tools","api-misuse","decorator"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}