Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validators.BugFreeSQL actually validates input sql #33

Merged
merged 1 commit into from
Mar 15, 2023
Merged

validators.BugFreeSQL actually validates input sql #33

merged 1 commit into from
Mar 15, 2023

Conversation

fruttasecca
Copy link
Contributor

@fruttasecca fruttasecca commented Mar 15, 2023

Before the change, everything would be passing, for example

from guardrails.validators import BugFreeSQL
v = BugFreeSQL()
invalid_query = "SELECT FROM;"
v.validate("", invalid_query, {})

Note, sqlvalidator has a bunch of open issues that will lead to an uncaught exception, see for example David-Wobrock/sqlvalidator#51, David-Wobrock/sqlvalidator#44. It can't be assumed that the exception is because of the query being invalid, at the same time, a query cannot be considered valid by just catching these exceptions and moving on. I've had the issue come up with fairly trivial examples, e.g. "SELECT ** FROM table;"

@fruttasecca fruttasecca changed the title validators.BugFreeSQL actually uses input sql validators.BugFreeSQL actually validates input sql Mar 15, 2023
Copy link
Collaborator

@ShreyaR ShreyaR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

I've been thinking about how to add better sql support because of issues with sqlvalidator similar to the ones you've mentioned. I'm considering using this cli tool https://github.com/jarulraj/sqlcheck instead of sqlvalidator since it seems to be more reliable. Let me know if you have any suggestions!

@ShreyaR ShreyaR merged commit 2e14c47 into guardrails-ai:main Mar 15, 2023
@fruttasecca
Copy link
Contributor Author

I've had good luck with https://github.com/tobymao/sqlglot, which would also allow specifying the SQL dialect against which to validate

@fruttasecca fruttasecca deleted the fix/sql-validator-not-testing-value branch March 15, 2023 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants