Repository navigation
Conversation
Tool.__post_init__ guarded the inputs_from_state check with `valid_inputs and`, which made a legitimately empty valid-parameter set indistinguishable from an unknown one. A zero-argument function, a zero-argument async_function, or a ComponentTool wrapping a component without input sockets therefore accepted any mapping target silently, and the mistake only surfaced later -- inside the agent loop, as a ToolInvocationError that never mentions inputs_from_state. Validate against the returned set unconditionally, and document the contract on _get_valid_inputs(): unlike _get_valid_outputs(), it never returns None, so an empty set means "this tool takes no input" rather than "unknown".
|
@Smilewithoutfalling is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hi @Smilewithoutfalling, thanks a lot for your contribution! 🙏 We noticed that the Contributor License Agreement (CLA) check ( To get your PR reviewed, please sign the CLA via the link in the |
|
Thanks for signing the CLA, @Smilewithoutfalling! 🎉 This PR is now ready for review again and the reviewer has been re-assigned. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
anakin87
left a comment
There was a problem hiding this comment.
Thank you!
I pushed some changes to make validation more robust.
If the function signature is not inspectable (such as some Python builtins), we skip parameter name validation.
I kept your fix for functions with no inputs.
Related Issues
Proposed Changes:
Tool.__post_init__validatedinputs_from_stateagainst the tool's parameters behind a truthiness guard:Because of the
valid_inputs andconjunct, "this tool has no input parameters" was indistinguishable from "the parameters could not be determined". For a tool whose valid-parameter set is legitimately empty -- a zero-argument function, a zero-argumentasync_function, or aComponentToolwrapping a component without input sockets -- every mapping target is by definition a typo, yet construction succeeded silently. The mistake then resurfaced much later, inside the agent loop, as aToolInvocationError(... no_param_tool() got an unexpected keyword argument 'city') that never mentionsinputs_from_state.This PR removes that conjunct, so the check becomes
if param_name not in valid_inputs:. An empty set is now validated exactly as strictly as a non-empty one, and the error reads... Valid parameters are: set().Why an empty set is safe to validate against:
_get_valid_inputs()is typed-> set[str]and always returns a set -- the union of the callable's signature parameters and thepropertiesdeclared inparameters. A tool with no parameters has resolved that set and found it empty; that is knowledge, not missing information._get_valid_outputs()is typed-> set[str] | Noneprecisely because function-based tools genuinely have no output schema, and its caller tests the sentinel withis not Nonerather than by truthiness. Outputs already distinguish "none" from "unknown"; inputs conflated the two.inputs_from_state(ComponentTool,AgentTool,PipelineTool,create_tool_from_function) only forwards the mapping intoTool.__init__. Nothing relies on the empty-set skip.The docstring of
_get_valid_inputs()now states this contract explicitly, so the asymmetry with_get_valid_outputs()is documented rather than implicit.How did you test it?
Three new tests, one per affected construction path, plus one guard test that the fix is not over-broad. I first reproduced the bug on
mainand then confirmed the fix, with the source change as the only variable.main(guard restored)test_tool.py::TestTool::test_inputs_from_state_validation_with_no_valid_parametersDID NOT RAISE ValueError)test_tool.py::TestTool::test_inputs_from_state_validation_with_no_valid_parameters_async_toolDID NOT RAISE ValueError)test_component_tool.py::TestComponentTool::test_from_component_with_inputs_from_state_and_no_input_socketsDID NOT RAISE ValueError)test_tool.py::TestTool::test_inputs_from_state_validation_with_empty_mapping_stays_validIn the
ComponentTooltest I asserttool.parameters == {"type": "object", "properties": {}}first, as an in-file control that the empty valid set really comes from a component that declares no input sockets rather than from a schema that was not resolved.Suites run locally (Windows, Python 3.12,
uvvenv):test/tools-- 296 passed, 14 skipped (292 passed before this PR's four new tests)test/with-m "not integration"-- 6716 passed, 63 failed; all 63 failures are missing optional dependencies (torch,mdit_plain,nltk,sentence_transformers,oxmsg) and are unrelated to this changeruff checkandruff format --checkon the three touched files -- cleanNotes for the reviewer
The error-message format is intentionally unchanged (
... Valid parameters are: set().); only the condition that reaches it changed. A friendlier message for the no-parameter case would be a separate, more invasive change, so I kept the diff minimal here -- happy to adjust if you would prefer a different wording.Checklist
fix:).I used an AI assistant while preparing this change. I have reviewed the diff line by line, reproduced the bug on
main, verified the fix and the new tests locally, and I take responsibility for the contribution.