Skip to content

fix: validate inputs_from_state when a tool takes no input - #13279

Merged
anakin87 merged 2 commits into
deepset-ai:mainfrom
Smilewithoutfalling:fix/validate-inputs-from-state-no-input
Oct 22, 2026
Merged

anakin87 merged 2 commits into
deepset-ai:mainfrom
Smilewithoutfalling:fix/validate-inputs-from-state-no-input

Conversation

@Smilewithoutfalling

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Tool.__post_init__ validated inputs_from_state against the tool's parameters behind a truthiness guard:

if valid_inputs and param_name not in valid_inputs:

Because of the valid_inputs and conjunct, "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-argument async_function, or a ComponentTool wrapping 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 a ToolInvocationError (... no_param_tool() got an unexpected keyword argument 'city') that never mentions inputs_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 the properties declared in parameters. A tool with no parameters has resolved that set and found it empty; that is knowledge, not missing information.
  • The sibling _get_valid_outputs() is typed -> set[str] | None precisely because function-based tools genuinely have no output schema, and its caller tests the sentinel with is not None rather than by truthiness. Outputs already distinguish "none" from "unknown"; inputs conflated the two.
  • I grepped the codebase: every other use of inputs_from_state (ComponentTool, AgentTool, PipelineTool, create_tool_from_function) only forwards the mapping into Tool.__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 main and then confirmed the fix, with the source change as the only variable.

test on main (guard restored) with this change
test_tool.py::TestTool::test_inputs_from_state_validation_with_no_valid_parameters fail (DID NOT RAISE ValueError) pass
test_tool.py::TestTool::test_inputs_from_state_validation_with_no_valid_parameters_async_tool fail (DID NOT RAISE ValueError) pass
test_component_tool.py::TestComponentTool::test_from_component_with_inputs_from_state_and_no_input_sockets fail (DID NOT RAISE ValueError) pass
test_tool.py::TestTool::test_inputs_from_state_validation_with_empty_mapping_stays_valid pass pass

In the ComponentTool test I assert tool.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, uv venv):

  • test/tools -- 296 passed, 14 skipped (292 passed before this PR's four new tests)
  • full 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 change
  • ruff check and ruff format --check on the three touched files -- clean

Notes 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

  • I have read the contributors guidelines and code of conduct.
  • I have added unit tests and documented the behaviour.
  • I have added a release note file.
  • I've used a conventional commit type for my PR title (fix:).
  • I have run the relevant checks locally (ruff, full unit suite).

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.

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
Smilewithoutfalling requested a review from a team as a code owner October 15, 2026 13:41
@Smilewithoutfalling
Smilewithoutfalling requested review from anakin87 and removed request for a team October 15, 2026 13:41
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@Smilewithoutfalling is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Oct 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Smilewithoutfalling

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @Smilewithoutfalling, thanks a lot for your contribution! 🙏

We noticed that the Contributor License Agreement (CLA) check (license/cla) hasn't passed yet, so we've temporarily moved this PR to draft and paused the review assignment.

To get your PR reviewed, please sign the CLA via the link in the license/cla check below (or in the CLA bot comment). As soon as the check turns green, this PR will automatically be marked ready for review again and a reviewer will be re-assigned.

@HaystackBot
HaystackBot removed the request for review from anakin87 October 15, 2026 14:52
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Oct 15, 2026
@HaystackBot
HaystackBot marked this pull request as draft October 15, 2026 14:52
@github-actions github-actions Bot added the P2 Medium priority, add to the next sprint if no P1 available label Oct 16, 2026
@HaystackBot
HaystackBot marked this pull request as ready for review October 19, 2026 11:28
@HaystackBot
HaystackBot requested a review from anakin87 October 19, 2026 11:29
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Oct 19, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

Thanks for signing the CLA, @Smilewithoutfalling! 🎉 This PR is now ready for review again and the reviewer has been re-assigned.

@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/tools
  tool.py 236
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@anakin87
anakin87 enabled auto-merge (squash) October 22, 2026 14:02
@anakin87
anakin87 merged commit b5ebcb0 into deepset-ai:main Oct 22, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium priority, add to the next sprint if no P1 available topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inputs_from_state typos pass construction when a tool takes no input

4 participants