Calling function_schema() (or using @function_tool) on a function whose parameter is named model_dump, model_dump_json, model_validate, model_validate_json, or model_validate_strings raises an unhandled ValueError deep inside Pydantic rather than a clear SDK error.
Trigger
from agents.function_schema import function_schema
def search_tool(model_validate: str, query: str) -> str:
return f"search: {query}"
schema = function_schema(search_tool)
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/_internal/_fields.py", line 97, in _check_protected_namespaces
raise ValueError(...)
ValueError: Field 'model_validate' conflicts with member <bound method BaseModel.model_validate ...>
of protected namespace 'model_validate'.
Pydantic's create_model() refuses any field whose name matches a built-in BaseModel method in a protected namespace. The error message gives no hint that the issue is the parameter name or how to fix it. These five names are distinct from model_config / model_fields / model_computed_fields (covered by PR #3548, which surfaces a different TypeError).
The fix is to detect these names before calling create_model() and raise a UserError with an actionable message.
Calling
function_schema()(or using@function_tool) on a function whose parameter is namedmodel_dump,model_dump_json,model_validate,model_validate_json, ormodel_validate_stringsraises an unhandledValueErrordeep inside Pydantic rather than a clear SDK error.Trigger
Traceback
Pydantic's
create_model()refuses any field whose name matches a built-inBaseModelmethod in a protected namespace. The error message gives no hint that the issue is the parameter name or how to fix it. These five names are distinct frommodel_config/model_fields/model_computed_fields(covered by PR #3548, which surfaces a differentTypeError).The fix is to detect these names before calling
create_model()and raise aUserErrorwith an actionable message.