Skip to main content
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

signature

Methods

filter(query: str, max_results: int = 5) -> tuple[list[str], list[str]]Returns a 2-tuple (matching_appointments, other_appointments):
  • matching_appointments: datetimes from source_list that match query, capped at max_results.
  • other_appointments: alternative datetimes to suggest when matching_appointments is empty, also capped at max_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

datetime_filter.py

Using with Field and search queries

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