Skip to content

fix(tools): include field details in beta tool argument errors - #2034

Open
vitorcomin33 wants to merge 1 commit into
anthropics:mainfrom
vitorcomin33:beta-tool-validation
Open

vitorcomin33 wants to merge 1 commit into
anthropics:mainfrom
vitorcomin33:beta-tool-validation

Conversation

@vitorcomin33

Copy link
Copy Markdown

No description provided.

@vitorcomin33
vitorcomin33 requested a review from a team as a code owner October 24, 2026 17:48

@chrikrah chrikrah left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

From my perspective this can be merged. Reverting _beta_functions.py fails your 8 new or changed non-snapshot tests, and a body ValidationError still matches except ValueError, its base class.

$ uv run pytest tests/lib/tools/test_functions.py tests/lib/tools/test_runners.py -n 0 -q
# head c3f8bf0, Python 3.10, pydantic 2.12.5
9 failed, 182 passed, 1 xfailed
# head with _beta_functions.py reverted to 202db72, tests kept
17 failed, 174 passed, 1 xfailed
# the 9 failing in both are http_snapshot runner tests, which need network here

non-blocking: a callable instance now gets a misleading NameError. functools.wraps copies no annotations, so pydantic resolves the wrapper's Any in the wrong module.

# exported trees, pydantic 2.12.5; class C: def __call__(self, a: int) -> str
$ uv run python inst.py   # beta_tool(C(), name="c", description="d").call({"a": 1})
base 202db72: PydanticUserError Unable to validate <__main__.C object ...>: `validate_call` should be applied to functions, not ...
head c3f8bf0: NameError name 'Any' is not defined

A partial gets it too, so #1955's partial tests fail on top of this unless one is wrapped as partial(_wrap_body_validation_errors(p.func), *p.args, **p.keywords).

# head c3f8bf0 + #1955 d87ffc6, both test_functions.py files
$ uv run pytest <both> -n 0 -q -k partial
5 failed
# same, with that partial branch
$ uv run pytest <both> -n 0 -q
57 passed

@vitorcomin33 should only plain functions get the wrapper?

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants