Skip to content

fix(core): raise a clear UserError when a tool parameter is named model_config - #4861

Closed
coderdailyone wants to merge 1 commit into
openai:mainfrom
coderdailyone:fix/function-schema-model-config-param
Closed

fix(core): raise a clear UserError when a tool parameter is named model_config#4861
coderdailyone wants to merge 1 commit into
openai:mainfrom
coderdailyone:fix/function-schema-model-config-param

Conversation

@coderdailyone

Copy link
Copy Markdown

Summary

A tool parameter named model_config made function_schema() fail with an unrelated-looking error from inside Pydantic:

TypeError: 'FieldInfo' object is not iterable

function_schema() builds the argument model with create_model(f"{name}_args", __base__=BaseModel, **fields), and Pydantic interprets a model_config keyword to create_model() as the model's configuration dict rather than as a field, so it tries to iterate the FieldInfo. 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_config was the one that failed opaquely.

This PR checks for that name before calling create_model() and raises a UserError that names the function and the parameter:

Parameter `model_config` in function configure is reserved by Pydantic and cannot be a tool argument. Rename the parameter.

No behavior changes for any other parameter name.

Test plan

  • test_model_config_parameter_raises_a_clear_user_error in tests/test_function_schema.py: on main it fails with the Pydantic TypeError; with this change it gets the UserError.
  • tests/test_function_schema.py, tests/test_function_tool.py, tests/test_function_tool_decorator.py: 177 passed. ruff format/ruff check clean, mypy and pyright clean on the changed files (Linux, Python 3.10). The repository-wide mypy src reports pre-existing Python 3.10 errors in archive_ops.py / run_loop.py unrelated to this change, so the full-stack checkbox is left unchecked.

Issue number

None (found while probing function_schema() with reserved parameter names).

Checks

  • I've added new tests, if relevant
  • I've run the verification steps from .agents/skills/code-change-verification individually (format, lint, typecheck on changed files, tests)
  • I've confirmed all verification steps pass (see Test plan)
  • If using Codex, I've run /review before submitting this PR

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFSMrLZZ3oq1dKmJFAofz6

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 sylvesterkaczmarek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@seratch

seratch commented Sep 5, 2026

Copy link
Copy Markdown
Member

We consider #4800 as the primary candidate for the same purpose.

@seratch seratch closed this Sep 5, 2026
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