Skip to content

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

Closed

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.

Activity

  1. norika1207-lab commented on Jun 2, 2026

    @norika1207-lab
  2. changed the title [-]BUG: function_schema() raises opaque ValueError for params named model_dump / model_validate / etc.[/-] [+]function_schema() raises opaque ValueError for params named model_dump / model_validate / etc.[/+] on Jun 4, 2026
  3. added a commit that references this issue on Jun 11, 2026
    42cdd09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions