From 4dadfa6482e794356eb8b39f3db9dd64308660c3 Mon Sep 17 00:00:00 2001 From: coderdailyone Date: Fri, 4 Sep 2026 17:29:48 +0000 Subject: [PATCH] fix(core): name the problem when a tool parameter is called model_config 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 Claude-Session: https://claude.ai/code/session_01DFSMrLZZ3oq1dKmJFAofz6 --- src/agents/function_schema.py | 7 +++++++ tests/test_function_schema.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/agents/function_schema.py b/src/agents/function_schema.py index 8860c15180..5b3a4357b8 100644 --- a/src/agents/function_schema.py +++ b/src/agents/function_schema.py @@ -511,6 +511,13 @@ def function_schema( ) # 3. Dynamically build a Pydantic model + if "model_config" in fields: + # Pydantic reads a ``model_config`` keyword as the model's configuration, not as a + # field, so create_model() fails deep inside Pydantic with an unhelpful TypeError. + raise UserError( + f"Parameter `model_config` in function {func_name} is reserved by Pydantic and cannot" + " be a tool argument. Rename the parameter." + ) dynamic_model = create_model(f"{func_name}_args", __base__=BaseModel, **fields) # 4. Build JSON schema from that model diff --git a/tests/test_function_schema.py b/tests/test_function_schema.py index 1d8325d1a0..8b282c7bed 100644 --- a/tests/test_function_schema.py +++ b/tests/test_function_schema.py @@ -1350,3 +1350,14 @@ def test_to_call_args_allows_kwargs_key_matching_var_positional_param() -> None: args, kwargs_dict = fs.to_call_args(parsed) assert _kwargs_var_positional_name(*args, **kwargs_dict) == ((1,), {"rest": 5}) + + +def test_model_config_parameter_raises_a_clear_user_error(): + """Pydantic treats a ``model_config`` kwarg to create_model() as the configuration, which + surfaced as ``TypeError: 'FieldInfo' object is not iterable``. Name the real problem.""" + + def configure(model_config: int) -> int: + return model_config + + with pytest.raises(UserError, match="`model_config` in function configure is reserved"): + function_schema(configure)