Skip to content

BUG: TypeError crash when function parameter is named 'model_config' #3547

@devteamaegis

Description

@devteamaegis

What breaks

Calling function_schema() (or using @function_tool) on a Python function that has a parameter named model_config (or another Pydantic-reserved name like model_fields, model_computed_fields) causes an unhandled TypeError deep inside Pydantic internals.

from agents.function_schema import function_schema

def my_tool(model_config: str) -> str:
    return model_config

schema = function_schema(my_tool)
# TypeError: 'FieldInfo' object is not iterable

Full traceback:

File "src/agents/function_schema.py", line 407, in function_schema
    dynamic_model = create_model(f"{func_name}_args", __base__=BaseModel, **fields)
  File "pydantic/main.py", line 1828, in create_model
  File "pydantic/_internal/_model_construction.py", line 131, in __new__
    config_wrapper = ConfigWrapper.for_model(bases, namespace, raw_annotations, kwargs)
  File "pydantic/_internal/_config.py", line 143, in for_model
    config_new.update(config_from_namespace)
TypeError: 'FieldInfo' object is not iterable

Root cause

Pydantic's create_model() treats keyword arguments named model_config as a model-level configuration key, not a field. When function_schema.py passes a FieldInfo for that name, Pydantic's ConfigWrapper.for_model() calls .update() on it expecting a dict-like object, causing the crash. No guard exists to detect reserved names before handing them to create_model().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions