fix(core): raise a clear UserError when a tool parameter is named model_config - #4861
Closed
coderdailyone wants to merge 1 commit into
Closed
fix(core): raise a clear UserError when a tool parameter is named model_config#4861coderdailyone wants to merge 1 commit into
coderdailyone wants to merge 1 commit into
Conversation
function_schema() builds the argument model with create_model(**fields). Pydantic reads a `model_config` keyword as the model configuration, not as a field, so a tool parameter named `model_config` failed deep inside Pydantic with "TypeError: 'FieldInfo' object is not iterable". Raise a UserError that names the function and the reserved parameter instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFSMrLZZ3oq1dKmJFAofz6
sylvesterkaczmarek
left a comment
Contributor
There was a problem hiding this comment.
Catching model_config before create_model() is the correct ownership boundary: this is a Pydantic metaclass/config namespace collision, not a malformed tool schema, so allowing the opaque FieldInfo TypeError to escape misdiagnoses the user's function. The exact-name check is intentionally narrow and leaves all other parameter handling unchanged. The regression also pins the public error to the function and offending parameter.
Member
|
We consider #4800 as the primary candidate for the same purpose. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A tool parameter named
model_configmadefunction_schema()fail with an unrelated-looking error from inside Pydantic:function_schema()builds the argument model withcreate_model(f"{name}_args", __base__=BaseModel, **fields), and Pydantic interprets amodel_configkeyword tocreate_model()as the model's configuration dict rather than as a field, so it tries to iterate theFieldInfo. Other reserved names already produce readable Pydantic errors (model_dump/model_validate→ "conflicts with member … of protected namespace", leading underscores → "Fields must not use names with leading underscores");model_configwas the one that failed opaquely.This PR checks for that name before calling
create_model()and raises aUserErrorthat names the function and the parameter:No behavior changes for any other parameter name.
Test plan
test_model_config_parameter_raises_a_clear_user_errorintests/test_function_schema.py: onmainit fails with the PydanticTypeError; with this change it gets theUserError.tests/test_function_schema.py,tests/test_function_tool.py,tests/test_function_tool_decorator.py: 177 passed.ruff format/ruff checkclean,mypyandpyrightclean on the changed files (Linux, Python 3.10). The repository-widemypy srcreports pre-existing Python 3.10 errors inarchive_ops.py/run_loop.pyunrelated to this change, so the full-stack checkbox is left unchecked.Issue number
None (found while probing
function_schema()with reserved parameter names).Checks
.agents/skills/code-change-verificationindividually (format, lint, typecheck on changed files, tests)/reviewbefore submitting this PR🤖 Generated with Claude Code
https://claude.ai/code/session_01DFSMrLZZ3oq1dKmJFAofz6