-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
I wrote a function tool that accepts a datetime as one of its arguments e.g.
def create_task(ctx: RunContext, name: str, due_date: datetime) -> None:
...(I use this as Tool(create_task).)
Unfortunately the schema generator gets very sad:
.venv/lib/python3.13/site-packages/pydantic_ai/tools.py:246: in __init__
self.function_schema = function_schema or _function_schema.function_schema(
.venv/lib/python3.13/site-packages/pydantic_ai/_function_schema.py:167: in function_schema
fields[field_name] = td_schema = gen_schema._generate_td_field_schema( # pyright: ignore[reportPrivateUsage]
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1189: in _generate_td_field_schema
common_field = self._common_field_schema(name, field_info, decorators)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1372: in _common_field_schema
schema = self._apply_annotations(
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:2297: in _apply_annotations
schema = get_inner_schema(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_schema_generation_shared.py:83: in __call__
schema = self._handler(source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:2279: in inner_handler
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1009: in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1123: in match_type
return self._match_generic_type(obj, origin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1146: in _match_generic_type
return self._union_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1434: in _union_schema
choices.append(self.generate_schema(arg))
^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:711: in generate_schema
schema = self._generate_schema_inner(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1009: in _generate_schema_inner
return self.match_type(obj)
^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.13/site-packages/pydantic/_internal/_generate_schema.py:1127: in match_type
return self._unknown_type_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pydantic._internal._generate_schema.GenerateSchema object at 0x10ad9fd30>
obj = <class 'datetime.datetime'>
def _unknown_type_schema(self, obj: Any) -> CoreSchema:
> raise PydanticSchemaGenerationError(
f'Unable to generate pydantic-core schema for {obj!r}. '
'Set `arbitrary_types_allowed=True` in the model_config to ignore this error'
' or implement `__get_pydantic_core_schema__` on your type to fully support it.'
'\n\nIf you got this error by calling handler(<some type>) within'
' `__get_pydantic_core_schema__` then you likely need to call'
' `handler.generate_schema(<some type>)` since we do not call'
' `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.'
)
E pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'datetime.datetime'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
E
E If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
E
E For further information visit https://errors.pydantic.dev/2.11/u/schema-for-unknown-type
Is this supposed to work? If not, is the recommended practice to accept datetimes as strings and hope that the model passes them correctly as ISO 8601?
References
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working