From 9acf80fd697c7da6846a3b608e632c45e372c0a8 Mon Sep 17 00:00:00 2001 From: tomer555 <37261280+tomer555@users.noreply.github.com> Date: Tue, 2 May 2023 06:57:19 +0300 Subject: [PATCH] fix: invalid escape sequence error in regex pattern (#3902) This PR fixes the "SyntaxError: invalid escape sequence" error in the pydantic.py file. The issue was caused by the backslashes in the regular expression pattern being treated as escape characters. By using a raw string literal for the regex pattern (e.g., r"\{.*\}"), this fix ensures that backslashes are treated as literal characters, thus preventing the error. Co-authored-by: Tomer Levy --- langchain/output_parsers/pydantic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/langchain/output_parsers/pydantic.py b/langchain/output_parsers/pydantic.py index e1e5e716..4b0fa53d 100644 --- a/langchain/output_parsers/pydantic.py +++ b/langchain/output_parsers/pydantic.py @@ -17,7 +17,7 @@ class PydanticOutputParser(BaseOutputParser[T]): try: # Greedy search for 1st json candidate. match = re.search( - "\{.*\}", text.strip(), re.MULTILINE | re.IGNORECASE | re.DOTALL + r"\{.*\}", text.strip(), re.MULTILINE | re.IGNORECASE | re.DOTALL ) json_str = "" if match: