Skip to content

fix: reject required underscore-prefixed tool parameters - #13567

Merged
sjrl merged 2 commits into
deepset-ai:mainfrom
mengchen-atx:fix/keep-underscore-tool-parameters
Nov 6, 2026
Merged

sjrl merged 2 commits into
deepset-ai:mainfrom
mengchen-atx:fix/keep-underscore-tool-parameters

Conversation

@mengchen-atx

@mengchen-atx mengchen-atx commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

create_tool_from_function and @tool built tool schemas with Pydantic (annotation, default) fields. Pydantic treats a name that starts with _ as a private attribute, so a parameter such as _tenant never appeared in model_json_schema(). When that parameter was required, the model could not supply it and Tool.invoke failed with a missing argument.

Underscore-prefixed parameters stay out of the schema. They are not exposed to the LLM. If a required parameter (no default) starts with _ and is not covered by inputs_from_state, tool creation now raises ValueError and names the parameter. The check runs after the existing inputs_from_state, State, and Callable skips. Supply the value with inputs_from_state, or give the parameter a default.

tool = create_tool_from_function(lookup_order, inputs_from_state={"tenant": "_tenant"})

Parameters that already have a default are still omitted from the schema, and the function keeps that default. create_tool_from_function and @tool document this.

The earlier change that kept these names in the schema with a Pydantic alias is removed, including the ComponentTool and dataclass schema changes from that approach.

How did you test it?

  • hatch run fmt: ruff checks passed
  • hatch run reno lint .: passed
  • hatch -e test run pytest -m "not integration" test/tools/test_from_function.py test/tools/test_component_tool.py test/tools/test_parameters_schema_utils.py -q --no-cov: 93 passed, 2 skipped, 7 deselected
  • New tests: a required _tenant raises; the same function succeeds when _tenant is in inputs_from_state and _tenant stays out of the schema; a defaulted _tenant stays out of the schema while invoke() uses the default.

Notes for the reviewer

This follows the direction from @sjrl on issue #13472: do not expose _ parameters to the LLM, and fail at tool creation only for a required underscore parameter that inputs_from_state does not cover.

ComponentTool is unchanged from main.

This change was AI-assisted. I have reviewed the changes and run the relevant tests.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

Pydantic treats leading-underscore names as private attributes, so
create_tool_from_function dropped them and ComponentTool failed while
building the schema. Store those parameters under a safe field name
with Field(alias=...) so the JSON schema keeps the real name.
@mengchen-atx
mengchen-atx requested a review from a team as a code owner November 5, 2026 08:16
@mengchen-atx
mengchen-atx requested review from sjrl and removed request for a team November 5, 2026 08:16
@vercel

vercel Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@mengchen-atx is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Hi @mengchen-atx, thanks for your interest in contributing to Haystack! 🙏

⚠️ Issue #13472 is already being addressed by open pull request(s) #13482. Before opening a PR for an issue, please check whether a PR is already linked to it, and consider contributing to the existing PR instead. We may close duplicate PRs to keep the review queue manageable.

This is an automated message to help us keep the review queue healthy.

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Underscore-prefixed parameters stay out of the tool schema.
create_tool_from_function raises ValueError when a required parameter
starts with an underscore and is not covered by inputs_from_state.
Parameters that already have a default stay omitted.
@mengchen-atx mengchen-atx changed the title fix: keep underscore-prefixed parameters in tool schemas fix: reject required underscore-prefixed tool parameters Nov 5, 2026
@github-actions github-actions Bot added the type:documentation Improvements on the docs label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

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

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

@sjrl sjrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@sjrl
sjrl merged commit 1d97791 into deepset-ai:main Nov 6, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create_tool_from_function / @tool silently drops parameters whose name starts with _, making the tool uncallable

3 participants