Skip to content

Fix FunctionTool not respecting pydantic Field defaults#20839

Open
Br1an67 wants to merge 1 commit intorun-llama:mainfrom
Br1an67:fix/issue-17324-fieldinfo-defaults
Open

Fix FunctionTool not respecting pydantic Field defaults#20839
Br1an67 wants to merge 1 commit intorun-llama:mainfrom
Br1an67:fix/issue-17324-fieldinfo-defaults

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Description

Fix FunctionTool to properly resolve pydantic Field(default=...) values when calling the wrapped function. Previously, if a function parameter used Field(default="Berlin") and wasn't explicitly provided at call time, the raw FieldInfo object was passed instead of the actual default value.

The fix extracts actual default values from FieldInfo objects during __init__ and applies them as lowest-priority defaults in call() and acall().

Fixes #17324

New Package?

N/A

Version Bump?

N/A — bug fix only.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Added test_function_tool_field_default that creates a function with Field(default="Berlin"), wraps it in FunctionTool, and verifies:

  1. Calling without args uses the Field default
  2. Calling with an explicit arg overrides the default

All 20 existing tests continue to pass.

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Extract actual default values from FieldInfo objects in the function
signature during __init__ and apply them as lowest-priority defaults
when calling the function. This ensures that pydantic Field defaults
are used when arguments are not explicitly provided.
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 1, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: "default" argument in Field not respected for FunctionTool

2 participants