DatetimeFilter filters a list of ISO 8601 datetime strings to find entries matching a natural-language query (e.g. “tomorrow afternoon”). Returns both matching datetimes and fallback suggestions when no exact match exists.
Constructor
- Python
- TypeScript
signature
Methods
- Python
- TypeScript
filter(query: str, max_results: int = 5) -> tuple[list[str], list[str]]Returns a 2-tuple (matching_appointments, other_appointments):matching_appointments: datetimes fromsource_listthat matchquery, capped atmax_results.other_appointments: alternative datetimes to suggest whenmatching_appointmentsis empty, also capped atmax_results.
Edge Cases
- The model is instructed to only return values drawn from the source list, never invented datetimes.
- Today’s date is injected into the prompt automatically, so relative queries like “tomorrow” and “next week” resolve correctly without any date math on the caller’s side.
- The fallback list may be non-empty even when the matching list is empty — use it to offer the caller nearby alternatives.
Basic Usage
- Python
- TypeScript
datetime_filter.py
Using with Field and search queries
- Python
- TypeScript
A common pattern is to pair
DatetimeFilter with a Field of type "calendar_slot" with searchable=True, and wire the filter into the on_search_query callback:scheduling_agent.py