Skip to content

Commit

Permalink
Merge pull request vanna-ai#512 from mahendrasinghbora/fix/extract-sq…
Browse files Browse the repository at this point in the history
…l-cte-regex

Fix regex in `extract_sql` to correctly handle SQL containing CTEs (without matching WITHIN)
  • Loading branch information
zainhoda authored Jun 21, 2024
2 parents 14dd2fa + 67f1bce commit dce3186
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 dce3186

Please sign in to comment.