You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=656570421)
61
-
62
-
or [view the read-only notebook](./notebooks/demo.ipynb)
63
-
64
-
# 📋 Explanation
65
-
66
-
So, what is actually happening above?
67
-
68
-
1. Unsafe free-form input is provided, presumably from some front end user interface.
69
-
1. That unsafe input is wrapped in a prompt envelope, producing a prompt with additional
70
-
context to help an LLM produce a correct query.
71
-
1. The unsafe prompt is sent to an LLM of your choice, which then produces an unsafe
72
-
SQL query.
73
-
1. The LLM response is parsed by a strict grammar which defines only the SQL features
74
-
that are allowed.
75
-
1. If parsing succeeds, we know at the very least we're dealing with a valid SQL query
76
-
albeit an untrusted one.
77
-
1. Different features of the parsed query are extracted for validation.
78
-
1. A soft validation pass is performed on the extracted features, and we potentially
79
-
modify the query to be compliant, for example, to add a `LIMIT` clause, or to remove
80
-
disallowed columns.
81
-
1. A hard validation pass is performed with your custom constraints to ensure that the
82
-
query is only accessing allowed tables, columns, and functions, while containing
83
-
required conditions.
84
-
1. If validation succeeds, the resulting SQL query can then be sent to the database.
85
-
1. If validation fails, you'll see a helpful exception explaining exactly why.
0 commit comments