Skip to content

fix(tools): keep Annotated parameter metadata in the tool schema - #271

Open
jaygupta17 wants to merge 1 commit into
vercel-labs:mainfrom
jaygupta17:feat/tool-param-descriptions
Open

jaygupta17 wants to merge 1 commit into
vercel-labs:mainfrom
jaygupta17:feat/tool-param-descriptions

Conversation

@jaygupta17

@jaygupta17 jaygupta17 commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #270

What

Annotated[str, Field(description=...)] now survives into the schema — the fix is get_type_hints(fn, include_extras=True); pydantic carries the metadata through create_model().model_json_schema() unchanged.

Why

Descriptions are how the model judges which tool to call and what each argument means. This idiomatic typed-Python pattern was silently dropped, so every tool built this way shipped undocumented arguments.

Notes

  • Field limits such as ge and le now reach the schema and the validator too, so a tool rejects arguments outside its declared limits.
  • Tools with plain hints get byte-identical schemas; there is a regression test pinning that.
  • Edited by a maintainer with the author's agreement: the docstring Args: parser from the first version is not included.

Validation

  • uv run pytest: 1247 passed, 20 skipped (3 new tests covering annotated fields, nested Annotated[...] | None unions keeping constraints + description, and the byte-identical regression)
  • uv run ruff format --check / ruff check: clean
  • uv run mypy: 35 errors, identical to baseline on main (all pre-existing, none in touched code)
  • uv run ty check: clean

@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

@jaygupta17 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@jaygupta17

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the feature label? (External PRs can't set labels.) The two red checks are permission artifacts: changelog-label needs triage rights and the Vercel deploy needs collaborator status.

@jaygupta17

Copy link
Copy Markdown
Contributor Author

hey folks quick ping on #271 and #273 when you get a sec, been open since Aug 26. both are mergeable and green across 3.12-3.15 and Socket. the two reds are just fork perms (Vercel needs collaborator auth and changelog-label needs the feature tag which I can't set). happy to jump on any feedback fast. thanks!

@jaygupta17
jaygupta17 force-pushed the feat/tool-param-descriptions branch from 204f90e to 9528108 Compare September 4, 2026 06:07
@jaygupta17

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main. The only conflict was in test_tools.py (upstream added to_model_input tests where mine go), kept both suites. Ruff, mypy, ty, and pytest all green locally. The two reds still need a maintainer: the feature label and Vercel auth.

@jaygupta17
jaygupta17 force-pushed the feat/tool-param-descriptions branch from 9528108 to aa74ab1 Compare September 8, 2026 07:42
@jaygupta17

Copy link
Copy Markdown
Contributor Author

Rebased onto latest main, no code changes. Ruff, ty, mypy, and pytest green locally.

Still needs a maintainer for the feature label and Vercel auth.

@anbuzin

anbuzin commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

@jaygupta17 i would like to merge just the Annotated part, not the parser. would you like to follow up on that or should i edit the commit myself?

@jaygupta17

Copy link
Copy Markdown
Contributor Author

@jaygupta17 i would like to merge just the Annotated part, not the parser. would you like to follow up on that or should i edit the commit myself?

proceed with editing

`@ai.tool` read the type hints without `include_extras`, so
`Annotated[..., Field(...)]` lost its description and its limits. The
model got no parameter description, and the validator did not apply
the limits.

Tools with plain hints get the same schema as before; a test pins it.

Closes vercel-labs#270
@anbuzin
anbuzin force-pushed the feat/tool-param-descriptions branch from aa74ab1 to b2accf1 Compare November 30, 2026 23:26
@anbuzin anbuzin added the fix Bug fix label Nov 30, 2026
@anbuzin anbuzin changed the title feat(tools): parameter descriptions via Annotated and docstring Args fix(tools): keep Annotated parameter metadata in the tool schema Nov 30, 2026

This branch has not been deployed

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

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool parameters lose descriptions from Annotated[...] and docstring Args sections

2 participants