Skip to content

fix: @tool and create_tool_from_function now preserve underscore-prefixed parameters - #13482

Closed
inmassat wants to merge 2 commits into
deepset-ai:mainfrom
inmassat:fix/underscore-params-schema
Closed

inmassat wants to merge 2 commits into
deepset-ai:mainfrom
inmassat:fix/underscore-params-schema

Conversation

@inmassat

Copy link
Copy Markdown

Related Issues

Proposed Changes:

\create_tool_from_function\ and the @tool\ decorator were silently dropping parameters whose names start with an underscore (e.g., _tenant, _session). This made tools with required underscore-prefixed parameters uncallable, as the parameters were missing from the generated JSON schema.

The fix uses Pydantic's \Field(alias=...)\ feature to preserve original parameter names in the schema while using safe internal field names. The same fix has been applied to \ComponentTool\ which builds its schema similarly.

How did you test it?

  • Added four comprehensive unit tests covering:
    1. Required underscore parameters (_tenant: str)
    2. Optional underscore parameters (_session: str = "default")
    3. Underscore parameters with \Annotated\ type hints
    4. Multiple underscore parameters in the same function
  • Ran all existing \ est_from_function\ tests (60 passed, 3 skipped)
  • Ran comprehensive tool tests (700 passed, 3 skipped)
  • Type checking passes with \hatch run test:types\

Notes for the reviewer

  • The fix follows the existing pattern in the codebase and uses Pydantic's built-in \�lias\ feature
  • Both \ rom_function.py\ and \component_tool.py\ have been updated for consistency
  • No breaking changes - tools with underscore parameters now work correctly instead of silently failing
  • Added a release note documenting the user-facing fix

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: \ ix:, \ eat:, \�uild:, \chore:, \ci:, \docs:, \style:,
    efactor:, \perf:, \ est:\ 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.

inmassat and others added 2 commits October 29, 2026 13:49
…ixed parameters

Pydantic rejects field names starting with underscore as private attributes.
Parameters like `_tenant` or `_session` were silently dropped from the tool schema,
making it impossible for LLMs to supply them. This caused ToolInvocationError when
the function had required underscore parameters.

The fix uses safe internal field names with Pydantic Field(alias=...) to preserve
the original underscore-prefixed names in the JSON schema and during tool invocation.

This applies to both create_tool_from_function and ComponentTool, and handles:
- Required parameters with leading underscores
- Optional parameters with leading underscores (with defaults)
- Annotated parameters with descriptions
- Multiple underscore parameters in the same function

Fixes deepset-ai#13472

Co-Authored-By: Claude Code <[email protected]>
…ixed parameters

Add release note for underscore parameter fix
Add .claude/ to .gitignore
@inmassat
inmassat requested a review from a team as a code owner October 29, 2026 16:10
@inmassat
inmassat requested review from julian-risch and removed request for a team October 29, 2026 16:10
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@inmassat 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 added topic:tests topic:DX Developer Experience labels Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @inmassat, thanks for your interest in contributing to Haystack! 🙏

⚠️ Issue #13472 is already being addressed by open pull request(s) #13473. 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.

@HaystackBot

Copy link
Copy Markdown
Contributor

Hi @inmassat, 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 julian-risch October 29, 2026 17:22
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Oct 29, 2026
@HaystackBot
HaystackBot marked this pull request as draft October 29, 2026 17:22
@HaystackBot
HaystackBot marked this pull request as ready for review October 31, 2026 03:56
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Oct 31, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

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

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@HaystackBot
HaystackBot removed the request for review from julian-risch November 5, 2026 08:27
@HaystackBot HaystackBot added the cla-pending PR is in draft until the contributor signs the CLA label Nov 5, 2026
@HaystackBot
HaystackBot marked this pull request as draft November 5, 2026 08:27
@HaystackBot
HaystackBot marked this pull request as ready for review November 5, 2026 08:51
@HaystackBot HaystackBot removed the cla-pending PR is in draft until the contributor signs the CLA label Nov 5, 2026
@HaystackBot

Copy link
Copy Markdown
Contributor

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

@sjrl

sjrl commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as duplicate of #13567

@sjrl sjrl closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:DX Developer Experience topic:tests

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

4 participants