Skip to content

Commit

Permalink
Fix regex in extract_sql to handle CTEs without matching WITHIN
Browse files Browse the repository at this point in the history
  • Loading branch information
mahendrasinghbora committed Jun 21, 2024
1 parent 14dd2fa commit 67f1bce
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/vanna/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def extract_sql(self, llm_response: str) -> str:
"""

# If the llm_response contains a CTE (with clause), extract the last sql between WITH and ;
sqls = re.findall(r"WITH.*?;", llm_response, re.DOTALL)
sqls = re.findall(r"\bWITH\b .*?;", llm_response, re.DOTALL)
if sqls:
sql = sqls[-1]
self.log(title="Extracted SQL", message=f"{sql}")
Expand Down

0 comments on commit 67f1bce

Please sign in to comment.