{"record":{"id":"b7a014256cbd0499","repo":"openai/openai-python","slug":"invalid-date-format","errorCode":null,"errorMessage":"invalid date format","messagePattern":"invalid date format","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/openai/_utils/_datetime_parse.py","lineNumber":129,"sourceCode":"    Raise ValueError if the input isn't well formatted.\n    \"\"\"\n    if isinstance(value, date):\n        if isinstance(value, datetime):\n            return value.date()\n        else:\n            return value\n\n    number = _get_numeric(value, \"date\")\n    if number is not None:\n        return _from_unix_seconds(number).date()\n\n    if isinstance(value, bytes):\n        value = value.decode()\n\n    assert not isinstance(value, (float, int))\n    match = date_re.match(value)\n    if match is None:\n        raise ValueError(\"invalid date format\")\n\n    kw = {k: int(v) for k, v in match.groupdict().items()}\n\n    try:\n        return date(**kw)\n    except ValueError:\n        raise ValueError(\"invalid date format\") from None\n","sourceCodeStart":111,"sourceCodeEnd":137,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/_utils/_datetime_parse.py#L111-L137","documentation":"parse_date matches the input string against a strict date regex (ISO-8601 calendar date). This ValueError fires when the string does not match that pattern at all — wrong separators, locale formats, or a full datetime string passed to a date-only field. It is the regex-miss branch, distinct from the second 'invalid date format' raised when the regex matched but the components form an impossible date.","triggerScenarios":"Passing strings like '01/02/2024', '2024-1-5' (unpadded), 'Jan 5, 2024', or '2024-01-05T10:00:00Z' (a datetime string) to a field parsed with parse_date.","commonSituations":"Hand-building SDK models from user input or CSV/Excel exports with locale-formatted dates; frontend sending datetime strings to date-only fields; tests with sloppy fixtures.","solutions":["Convert the value to an ISO-8601 date string (date.isoformat()) or a datetime.date object before assignment","If the source is a datetime string, truncate it: value[:10] or parse with datetime.fromisoformat(...).date()","Validate with datetime.strptime(value, '%Y-%m-%d') before passing","Add unit fixtures that use strict YYYY-MM-DD strings"],"exampleFix":"# before\nm = MyModel(expires=\"03/15/2024\")\n\n# after\nfrom datetime import date\nm = MyModel(expires=date(2024,3,15).isoformat())","handlingStrategy":"validation","validationCode":"from datetime import datetime\ntry:\n    datetime.strptime(value, \"%Y-%m-%d\")\n    ok = True\nexcept ValueError:\n    ok = False","typeGuard":"import re\ndef is_iso_date(v: str) -> bool:\n    return bool(re.fullmatch(r\"\\d{4}-\\d{2}-\\d{2}\", v)) and not \"T\" in v","tryCatchPattern":"try:\n    parse_date(s)\nexcept ValueError:\n    s = datetime.fromisoformat(s).date().isoformat()  # handle datetime strings","preventionTips":["Use date.isoformat() for date fields","Convert datetime strings to date before date-typed fields","Reject locale-format dates at input validation"],"tags":["valueerror","date","iso8601","parsing"],"backgroundTag":"invalid-date-format","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}