Skip to content

fix(llm): preserve Field() constraints on function tool arguments#5861

Open
theomonnom wants to merge 1 commit into
mainfrom
fix/tool-arg-field-constraints
Open

fix(llm): preserve Field() constraints on function tool arguments#5861
theomonnom wants to merge 1 commit into
mainfrom
fix/tool-arg-field-constraints

Conversation

@theomonnom
Copy link
Copy Markdown
Member

No description provided.

@chenghao-mou chenghao-mou requested a review from a team May 27, 2026 05:58
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Comment on lines +350 to +356
annotated_dict = annotated_field.asdict()
field_attrs = annotated_dict["attributes"]
# Constraints (ge/le/gt/lt/multiple_of/min_length/pattern/...) live
# in `metadata`, not `attributes`. Re-attach them to the annotation
# so `Field(...)` constraints on a tool argument are preserved.
if annotated_dict["metadata"]:
type_hint = Annotated[(type_hint, *annotated_dict["metadata"])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

annotated_dictfield_dict

annotated_dict got me thinking it's a dict of Annotated at a first glance

Suggested change
annotated_dict = annotated_field.asdict()
field_attrs = annotated_dict["attributes"]
# Constraints (ge/le/gt/lt/multiple_of/min_length/pattern/...) live
# in `metadata`, not `attributes`. Re-attach them to the annotation
# so `Field(...)` constraints on a tool argument are preserved.
if annotated_dict["metadata"]:
type_hint = Annotated[(type_hint, *annotated_dict["metadata"])]
field_dict = annotated_field.asdict()
field_attrs = field_dict["attributes"]
# Constraints (ge/le/gt/lt/multiple_of/min_length/pattern/...) live
# in `metadata`, not `attributes`. Re-attach them to the annotation
# so `Field(...)` constraints on a tool argument are preserved.
if field_dict["metadata"]:
type_hint = Annotated[(type_hint, *field_dict["metadata"])]

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants