#2035·outlines

`types.datetime` rejects the ISO 8601 `T` separator (`datetime.isoformat()` output does not match)

Author: betacatslingCreated Sep 14, 2026Updated Sep 14, 2026

Actual behavior

python
import datetime
from outlines import types

types.datetime.matches("2022-03-23T10:15:30")  # False
types.datetime.matches(datetime.datetime(2022, 3, 23, 10, 15, 30).isoformat())  # False
types.datetime.matches("2022-03-23 10:15:30")  # True (space separator only)

The datetime regex requires a whitespace separator between the date and the time:

python
datetime = Regex(rf"({date.pattern})(\s)({time.pattern})")

So the canonical ISO 8601 / RFC 3339 form YYYY-MM-DDTHH:MM:SS — what datetime.isoformat() produces by default and what models are most likely to emit — is rejected. When types.datetime is used as a field type, the generated JSON Schema pattern inherits the same restriction, so a constrained model cannot emit the standard form. The JSON Schema path disagrees: a {"format": "date-time"} field compiled via build_regex_from_schema requires the T separator, so the DSL type and the schema path constrain datetimes differently.

Expected behavior

types.datetime should accept the T separator (ISO 8601 also permits lowercase t), in addition to the space form it already accepts.

Proposed fix

Change the separator group from (\s) to ([Tt\s]). Fractional seconds and timezone offsets could be added later; this fix only restores the canonical separator.

Environment

outlines main @ c52af84, Python 3.12, Linux.