spring-projects/spring-ai · error · IllegalArgumentException
Invalid date type:
Error message
Invalid date type:
What it means
normalizeDateString normalizes date values in filter expressions to java.util.Date using ISO_DATE_FORMATTER. If the text cannot be parsed as an ISO date it throws IllegalArgumentException("Invalid date type: " + text). This validates that date-typed filter values are real ISO-formatted dates.
Solutions
- Use ISO-8601 date format (yyyy-MM-dd or full ISO date-time) in filter date values, e.g. "createdAt > 2024-01-15"
- Pre-parse your date in application code with LocalDate.parse(..., DateTimeFormatter.ISO_LOCAL_DATE) to validate before building the filter
- Catch IllegalArgumentException and prompt the user with the expected ISO format
Example fix
// before
parser.parse("createdAt > 01/15/2024");
// after
parser.parse("createdAt > 2024-01-15"); Defensive patterns
Strategy: validation
Validate before calling
try { LocalDate.parse(dateText, DateTimeFormatter.ISO_LOCAL_DATE); }
catch (DateTimeParseException e) { throw new IllegalArgumentException("Use ISO date: yyyy-MM-dd"); } Try / catch
try { filter = parser.parse(text); }
catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid date in filter, expected ISO format: " + e.getMessage(), e); } Prevention
- Always emit ISO-8601 dates in filter strings
- Validate dates with java.time before building filters
When it happens
Trigger: Using a date string value in a filter (e.g. "createdAt > <date>") where the value text reaching normalizeDateString (via doValue) is not ISO format — e.g. "01/15/2024", "Jan 15 2024", or an impossible date like "2024-13-45" — causing DateTimeParseException.
Common situations: US-style date formats in filter strings; locale-specific dates; user-supplied dates passed straight into filter expressions; typos like 2024-1-5 without zero padding.
Related errors
- Cannot compare values of incompatible types
- Cannot compare values of incompatible types
- Cannot compare values of types
- Cannot compare values of types
- Expected a Key operand but got:
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/c26f809ddb02cdf2.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-vector-store/src/main/java/org/springframework/ai/vectorstore/filter/converter/AbstractFilterExpressionConverter.java:185
}
}
/**
* If the value is a string matching the ISO date pattern, parse and return as
* {@link Date} so that all converters that handle {@code Date} automatically support
* date strings. Otherwise return the value unchanged.
* @param value the value (possibly a date string)
* @return the value, or a {@code Date} if the value was a parseable date string
*/
protected static Object normalizeDateString(Object value) {
if (!(value instanceof String text) || !ISO_DATE_PATTERN.matcher(text).matches()) {
return value;
}
try {
return Date.from(Instant.from(ISO_DATE_FORMATTER.parse(text)));
}
catch (DateTimeParseException e) {
throw new IllegalArgumentException("Invalid date type: " + text, e);
}
}
/**
* Convert the given single value into a string representation and append it to the
* context. This method handles all value types including String, Number, Boolean,
* Date, etc.
* <p>
* For convenience, implementations can use the provided static helper methods such as
* {@link #emitJsonValue(Object, StringBuilder)} for JSON-based filters,
* {@link #emitLuceneString(String, StringBuilder)} for Lucene-based filters, or
* implement their own format-specific escaping logic as needed.
* @param value the value to convert
* @param context the context to append the string representation to
*/
protected abstract void doSingleValue(Object value, StringBuilder context);
/**View on GitHub (pinned to 98a7beda4f)