Repository navigation
fix: reject required underscore-prefixed tool parameters - #13567
Merged
sjrl merged 2 commits intoNov 6, 2026
Merged
Conversation
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.
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. |
Contributor
|
Hi @mengchen-atx, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
7 tasks done
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.
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
create_tool_from_function/@toolsilently drops parameters whose name starts with_, making the tool uncallable #13472Proposed Changes:
create_tool_from_functionand@toolbuilt tool schemas with Pydantic(annotation, default)fields. Pydantic treats a name that starts with_as a private attribute, so a parameter such as_tenantnever appeared inmodel_json_schema(). When that parameter was required, the model could not supply it andTool.invokefailed 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 byinputs_from_state, tool creation now raisesValueErrorand names the parameter. The check runs after the existinginputs_from_state,State, andCallableskips. Supply the value withinputs_from_state, or give the parameter a default.Parameters that already have a default are still omitted from the schema, and the function keeps that default.
create_tool_from_functionand@tooldocument this.The earlier change that kept these names in the schema with a Pydantic alias is removed, including the
ComponentTooland dataclass schema changes from that approach.How did you test it?
hatch run fmt: ruff checks passedhatch run reno lint .: passedhatch -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_tenantraises; the same function succeeds when_tenantis ininputs_from_stateand_tenantstays out of the schema; a defaulted_tenantstays out of the schema whileinvoke()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 thatinputs_from_statedoes not cover.ComponentToolis unchanged from main.This change was AI-assisted. I have reviewed the changes and run the relevant tests.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.