From 50a5c919f0c51ea805ec789fffe53df0243238bd Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Mon, 13 Nov 2023 14:03:15 -0800 Subject: [PATCH] IMPROVEMENT self-query template (#13305) - [ ] https://github.com/langchain-ai/langchain/pull/12694#discussion_r1391334719 -> keep date - [x] https://github.com/langchain-ai/langchain/pull/12694#discussion_r1391336586 --- .../langchain/chains/query_constructor/parser.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/langchain/langchain/chains/query_constructor/parser.py b/libs/langchain/langchain/chains/query_constructor/parser.py index 26521876820..a2f7db6cbd0 100644 --- a/libs/langchain/langchain/chains/query_constructor/parser.py +++ b/libs/langchain/langchain/chains/query_constructor/parser.py @@ -1,4 +1,5 @@ import datetime +import warnings from typing import Any, Literal, Optional, Sequence, Union from typing_extensions import TypedDict @@ -55,6 +56,8 @@ GRAMMAR = r""" class ISO8601Date(TypedDict): + """A date in ISO 8601 format (YYYY-MM-DD).""" + date: str type: Literal["date"] @@ -140,11 +143,11 @@ class QueryTransformer(Transformer): item = str(item).strip("\"'") try: datetime.datetime.strptime(item, "%Y-%m-%d") - except ValueError as e: - raise ValueError( + except ValueError: + warnings.warn( "Dates are expected to be provided in ISO 8601 date format " "(YYYY-MM-DD)." - ) from e + ) return {"date": item, "type": "date"} def string(self, item: Any) -> str: