Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(core): populate default args from tool's args_schema#34399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
nathannewyen wants to merge1 commit intolangchain-ai:master
base:master
Choose a base branch
Loading
fromnathannewyen:fix/34384-tool-default-args

Conversation

@nathannewyen
Copy link
Contributor

@nathannewyennathannewyen commentedDec 17, 2025
edited
Loading

Summary

  • Fixes issue where Pydantic default values fromargs_schema were not passed to tool functions when the caller omits optional arguments
  • Modified_parse_input() inlibs/core/langchain_core/tools/base.py to include fields with non-None defaults
  • Added unit tests to verify default args behavior for both sync and async tools

Problem

When a tool has anargs_schema with default values:

classSearchArgs(BaseModel):query:str=Field(...,description="Search query")page:int=Field(default=1,description="Page number")size:int=Field(default=10,description="Results per page")@tool("search",args_schema=SearchArgs)defsearch_tool(query:str,page:int,size:int)->str:returnf"query={query}, page={page}, size={size}"# This threw: TypeError: search_tool() missing 2 required positional argumentssearch_tool.invoke({"query":"test"})

The defaults fromargs_schema were being discarded because_parse_input() filtered validated results to only include keys from the original input.

Solution

Changed the filtering logic to:

  1. Include all fields that were in the original input (validated)
  2. Also include fields with non-None defaults from the Pydantic schema

This applies user-defined defaults (likeField(default=1)) while excluding synthetic fields from*args/**kwargs which havedefault=None.

Test plan

  • Addedtest_tool_args_schema_default_values - tests sync tool with defaults
  • Addedtest_tool_args_schema_default_values_async - tests async tool with defaults
  • All existing tests pass (150 passed, 4 skipped)
  • Lint passes

Fixes#34384

@github-actionsgithub-actionsbot added core`langchain-core` package issues & PRs fixFor PRs that implement a fix labelsDec 17, 2025
When a tool has an args_schema with Pydantic default values (e.g.,`page: int = Field(default=1, ...)`), those defaults are now passedto the tool function when the caller omits optional arguments.Previously, the `_parse_input` method filtered validated results toonly include keys that were in the original input, discarding Pydanticdefaults. Now it includes fields with non-None defaults, which appliesuser-defined defaults while excluding synthetic fields from *args/*kwargs.Fixeslangchain-ai#34384
@github-actionsgithub-actionsbot added fixFor PRs that implement a fix and removed fixFor PRs that implement a fix labelsDec 17, 2025
@nathannewyennathannewyenforce-pushed thefix/34384-tool-default-args branch froma70d266 to2fec706CompareDecember 17, 2025 01:39
@codspeed-hq
Copy link

CodSpeed Performance Report

Merging#34399 willimprove performances by 33.42%

Comparingnathannewyen:fix/34384-tool-default-args (2fec706) withmaster (37d8666)

⚠️Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend usingCodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

⚡ 13 improvements
⏩ 21 skipped1

Benchmarks breakdown

ModeBenchmarkBASEHEADChange
WallTimetest_import_time[InMemoryVectorStore]646.5 ms554.2 ms+16.65%
WallTimetest_import_time[InMemoryRateLimiter]188.6 ms159.7 ms+18.12%
WallTimetest_import_time[Document]195.7 ms169.3 ms+15.55%
WallTimetest_import_time[HumanMessage]281 ms244.7 ms+14.87%
WallTimetest_import_time[LangChainTracer]479.2 ms397.7 ms+20.48%
WallTimetest_async_callbacks_in_sync25.3 ms19 ms+33.42%
WallTimetest_import_time[RunnableLambda]544.2 ms447.8 ms+21.51%
WallTimetest_import_time[tool]542.8 ms477.4 ms+13.72%
WallTimetest_import_time[ChatPromptTemplate]629.4 ms535.8 ms+17.48%
WallTimetest_import_time[BaseChatModel]550.9 ms489.1 ms+12.64%
WallTimetest_import_time[CallbackManager]485.3 ms430.6 ms+12.71%
WallTimetest_import_time[PydanticOutputParser]575.1 ms475.4 ms+20.98%
WallTimetest_import_time[Runnable]525 ms466.8 ms+12.48%

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase,click here and archive them to remove them from the performance reports.

@nathannewyen
Copy link
ContributorAuthor

The CI failure intest_startup_command_failure is unrelated to this PR. That test is inlibs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_shell_tool.py which tests shell tool middleware - completely separate from our changes inlibs/core/langchain_core/tools/base.py.

The test fails becauseexit 1 terminates the shell process, then when trying to write a marker to stdin, it getsBrokenPipeError instead of the expectedRuntimeError. This appears to be a flaky test or pre-existing issue in the shell middleware error handling.

Could a maintainer please re-run the CI or mark this as a known flaky test?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@eyurtseveyurtsevAwaiting requested review from eyurtseveyurtsev is a code owner

Assignees

No one assigned

Labels

core`langchain-core` package issues & PRsfixFor PRs that implement a fix

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Populate default args when provided in a tool's args_schema

1 participant

@nathannewyen

[8]ページ先頭

©2009-2025 Movatter.jp