Skip to content

function_schema() raises opaque ValueError for params named model_dump / model_validate / etc. #3549

@devteamaegis

Description

@devteamaegis

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.

Metadata

Metadata

Assignees

No one assigned

    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