sqlguardllm 0.1.0a1__tar.gz → 0.1.0a2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/CHANGELOG.md +14 -4
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/PKG-INFO +14 -14
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/README.md +21 -21
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/docs/pypi.md +8 -8
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/pyproject.toml +7 -7
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/__init__.py +5 -5
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/_compiled.py +1 -1
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/_names.py +1 -1
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/guard.py +12 -12
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/messages.py +1 -1
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/policy.py +3 -3
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/result.py +4 -4
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/columns.py +4 -4
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/functions.py +3 -3
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/row_filters.py +6 -6
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/sources.py +4 -4
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/statement.py +2 -2
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/conftest.py +1 -1
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/test_api.py +4 -4
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/test_corpus.py +1 -1
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/test_policy.py +1 -1
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/test_row_filters.py +1 -1
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/test_rules.py +1 -1
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/.gitignore +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/LICENSE +0 -0
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/data/__init__.py +0 -0
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/data/denied_functions.py +0 -0
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/py.typed +0 -0
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/__init__.py +0 -0
- {sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/limit.py +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/corpus/allowed.yaml +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/corpus/context.yaml +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/corpus/functions.yaml +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/corpus/tables_columns.yaml +0 -0
- {sqlguardllm-0.1.0a1 → sqlguardllm-0.1.0a2}/tests/corpus/writes.yaml +0 -0
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
All notable changes to
|
|
3
|
+
All notable changes to sqlguardllm are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/). Violation codes are stable across minor versions.
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.1.0a2] - 2026-11-25
|
|
8
|
+
|
|
9
|
+
One name everywhere: the project is now **sqlguardllm**.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- The import package is now `sqlguardllm` (`from sqlguardllm import Guard, Policy`), matching the PyPI name. `import sqlguard` from 0.1.0a1 no longer works.
|
|
14
|
+
- The repository moved to [jmmana/sqlguardllm](https://github.com/jmmana/sqlguardllm); the old URL redirects.
|
|
15
|
+
|
|
7
16
|
## [0.1.0a1] - 2026-11-25
|
|
8
17
|
|
|
9
|
-
First alpha.
|
|
18
|
+
First alpha. Installed with `pip install sqlguardllm` and imported as `import sqlguard`.
|
|
10
19
|
|
|
11
20
|
### Added
|
|
12
21
|
|
|
@@ -27,5 +36,6 @@ First alpha. Install with `pip install sqlguardllm`; import with `import sqlguar
|
|
|
27
36
|
- Table functions are rejected, even harmless ones like `generate_series`.
|
|
28
37
|
- No command-line tool yet (planned for v0.2).
|
|
29
38
|
|
|
30
|
-
[Unreleased]: https://github.com/jmmana/
|
|
31
|
-
[0.1.
|
|
39
|
+
[Unreleased]: https://github.com/jmmana/sqlguardllm/compare/v0.1.0a2...HEAD
|
|
40
|
+
[0.1.0a2]: https://github.com/jmmana/sqlguardllm/compare/v0.1.0a1...v0.1.0a2
|
|
41
|
+
[0.1.0a1]: https://github.com/jmmana/sqlguardllm/releases/tag/v0.1.0a1
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: sqlguardllm
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0a2
|
|
4
4
|
Summary: The SQL firewall for LLM apps: validate SQL written by AI and rewrite it read-only, allowlisted, row-filtered and limited.
|
|
5
|
-
Project-URL: Homepage, https://github.com/jmmana/
|
|
6
|
-
Project-URL: Documentation, https://github.com/jmmana/
|
|
7
|
-
Project-URL: Issues, https://github.com/jmmana/
|
|
8
|
-
Project-URL: Changelog, https://github.com/jmmana/
|
|
9
|
-
Project-URL: Source, https://github.com/jmmana/
|
|
5
|
+
Project-URL: Homepage, https://github.com/jmmana/sqlguardllm
|
|
6
|
+
Project-URL: Documentation, https://github.com/jmmana/sqlguardllm/tree/main/docs
|
|
7
|
+
Project-URL: Issues, https://github.com/jmmana/sqlguardllm/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/jmmana/sqlguardllm/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Source, https://github.com/jmmana/sqlguardllm
|
|
10
10
|
Author: Juan Castillo
|
|
11
11
|
License-Expression: Apache-2.0
|
|
12
12
|
License-File: LICENSE
|
|
@@ -32,19 +32,19 @@ Requires-Dist: pyyaml>=6.0; extra == 'yaml'
|
|
|
32
32
|
Description-Content-Type: text/markdown
|
|
33
33
|
|
|
34
34
|
<p align="center">
|
|
35
|
-
<img alt="
|
|
35
|
+
<img alt="sqlguardllm" src="https://raw.githubusercontent.com/jmmana/sqlguardllm/main/docs/assets/logo-light.svg" width="340">
|
|
36
36
|
</p>
|
|
37
37
|
|
|
38
|
-
#
|
|
38
|
+
# sqlguardllm — the SQL firewall for LLM apps
|
|
39
39
|
|
|
40
|
-
Your model writes SQL. **
|
|
40
|
+
Your model writes SQL. **sqlguardllm** makes sure it can only read what it's allowed to read: one read-only statement, allowlisted tables and columns, row-level filters per user, and a row limit, in any dialect [sqlglot](https://github.com/tobymao/sqlglot) understands.
|
|
41
41
|
|
|
42
42
|
```bash
|
|
43
43
|
pip install sqlguardllm
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
```python
|
|
47
|
-
from
|
|
47
|
+
from sqlguardllm import Guard, Policy
|
|
48
48
|
|
|
49
49
|
guard = Guard(
|
|
50
50
|
Policy(
|
|
@@ -77,8 +77,8 @@ Pure Python, one dependency (sqlglot), no network, no LLM. Status: **alpha** —
|
|
|
77
77
|
|
|
78
78
|
## Learn more
|
|
79
79
|
|
|
80
|
-
- Source, design and attack gallery: <https://github.com/jmmana/
|
|
81
|
-
- Threat model: <https://github.com/jmmana/
|
|
82
|
-
- Report a bypass privately: <https://github.com/jmmana/
|
|
80
|
+
- Source, design and attack gallery: <https://github.com/jmmana/sqlguardllm>
|
|
81
|
+
- Threat model: <https://github.com/jmmana/sqlguardllm/blob/main/docs/THREAT_MODEL.md>
|
|
82
|
+
- Report a bypass privately: <https://github.com/jmmana/sqlguardllm/security/advisories/new>
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
Licensed under Apache-2.0.
|
|
@@ -5,26 +5,26 @@
|
|
|
5
5
|
|
|
6
6
|
<picture>
|
|
7
7
|
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
|
|
8
|
-
<img alt="
|
|
8
|
+
<img alt="sqlguardllm" src="docs/assets/logo-light.svg" width="380">
|
|
9
9
|
</picture>
|
|
10
10
|
|
|
11
11
|
### The SQL firewall for LLM apps.
|
|
12
12
|
|
|
13
|
-
Your model writes SQL. **
|
|
13
|
+
Your model writes SQL. **sqlguardllm** makes sure it can only read what it's allowed to read: one read-only statement, allowlisted tables and columns, row-level filters per user, and a row limit, in any of the 32 dialects [sqlglot](https://github.com/tobymao/sqlglot) speaks.
|
|
14
14
|
|
|
15
15
|
[](https://pypi.org/project/sqlguardllm/)
|
|
16
|
-
[](https://github.com/jmmana/sqlguardllm/actions/workflows/ci.yml)
|
|
17
17
|
[](LICENSE)
|
|
18
18
|
[](docs/DESIGN.md)
|
|
19
19
|
[](https://github.com/tobymao/sqlglot)
|
|
20
20
|
[](CONTRIBUTING.md)
|
|
21
21
|
|
|
22
|
-
<img src="docs/assets/hero.svg" alt="
|
|
22
|
+
<img src="docs/assets/hero.svg" alt="sqlguardllm blocks a DELETE hidden inside a CTE and a query on a hidden column, and rewrites an allowed query with the user's row filter and a row limit" width="100%">
|
|
23
23
|
|
|
24
24
|
</div>
|
|
25
25
|
|
|
26
26
|
> [!NOTE]
|
|
27
|
-
> **Status: alpha.** `0.1.
|
|
27
|
+
> **Status: alpha.** `0.1.0a2` is on [PyPI](https://pypi.org/project/sqlguardllm/) (`pip install sqlguardllm`, `import sqlguardllm`), with the rules of [docs/DESIGN.md](docs/DESIGN.md) and a 64-case adversarial corpus. The API may still change before 1.0; violation codes are stable. ⭐ Star the repo to follow along, and tell us what you think in [Discussions](https://github.com/jmmana/sqlguardllm/discussions).
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
@@ -41,7 +41,7 @@ The usual defense is a keyword blocklist. It fails in **both** directions:
|
|
|
41
41
|
| `SELECT * INTO backup FROM invoices` | ⚠️ Lets it through: it starts with `SELECT` | Creates a new table (SQL Server) |
|
|
42
42
|
| `SELECT name, email FROM customers` | ⚠️ Lets it through | Reads personal data the model should never see |
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
sqlguardllm parses the statement into a syntax tree with sqlglot and **decides on the tree, not on the text**. Then it rewrites the query so it can only see the rows the current user is allowed to see.
|
|
45
45
|
|
|
46
46
|
## What it guarantees
|
|
47
47
|
|
|
@@ -62,7 +62,7 @@ pip install sqlguardllm # Python 3.10+, one dependency: sqlglot
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
```python
|
|
65
|
-
from
|
|
65
|
+
from sqlguardllm import Guard, Policy
|
|
66
66
|
|
|
67
67
|
guard = Guard(Policy(
|
|
68
68
|
dialect="postgres",
|
|
@@ -139,9 +139,9 @@ Same idea on SQL Server, where the limit becomes `TOP 500`, or Oracle, where it
|
|
|
139
139
|
|
|
140
140
|
## Attack gallery
|
|
141
141
|
|
|
142
|
-
What sqlglot 30.35 actually sees for each attempt, and what
|
|
142
|
+
What sqlglot 30.35 actually sees for each attempt, and what sqlguardllm does about it. Every row is a test case. The full list is in [docs/ATTACK_GALLERY.md](docs/ATTACK_GALLERY.md).
|
|
143
143
|
|
|
144
|
-
| Dialect | Attempt | sqlglot sees |
|
|
144
|
+
| Dialect | Attempt | sqlglot sees | sqlguardllm |
|
|
145
145
|
|---|---|---|---|
|
|
146
146
|
| postgres | `WITH d AS (DELETE FROM invoices RETURNING *) SELECT * FROM d` | `Select` root with a `Delete` inside | ❌ `write_operation` |
|
|
147
147
|
| tsql | `SELECT 1; DROP TABLE invoices` | 2 statements | ❌ `multiple_statements` |
|
|
@@ -158,10 +158,10 @@ Found a way through? That's a vulnerability: please [report it privately](SECURI
|
|
|
158
158
|
|
|
159
159
|
## Where it fits
|
|
160
160
|
|
|
161
|
-
|
|
161
|
+
sqlguardllm is **one layer**, not the only one. Keep the others:
|
|
162
162
|
|
|
163
163
|
1. **A read-only database user** with access to only the tables the app needs. Non-negotiable.
|
|
164
|
-
2. **
|
|
164
|
+
2. **sqlguardllm** between the model and the database: shape, allowlists, row filters, limits.
|
|
165
165
|
3. **Statement timeouts** in the database, against expensive queries.
|
|
166
166
|
4. **Audit logs** of every SQL that ran and for whom.
|
|
167
167
|
|
|
@@ -169,26 +169,26 @@ What it does not do, and why, is in the [threat model](docs/THREAT_MODEL.md).
|
|
|
169
169
|
|
|
170
170
|
## Works with your stack
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
sqlguardllm sits wherever your app executes the SQL the model wrote. Recipes, planned for v0.3, will cover a generic `execute()` wrapper, LangChain and LlamaIndex SQL tools, Vanna, and MCP database servers. See [docs/INTEGRATIONS.md](docs/INTEGRATIONS.md).
|
|
173
173
|
|
|
174
174
|
A command-line tool is planned too, handy in CI and for trying policies:
|
|
175
175
|
|
|
176
176
|
```bash
|
|
177
|
-
|
|
177
|
+
sqlguardllm check --policy policy.yaml --context '{"user": {"branches": [1, 2]}}' \
|
|
178
178
|
"SELECT * FROM invoices"
|
|
179
179
|
```
|
|
180
180
|
|
|
181
181
|
## Playground: try to break it
|
|
182
182
|
|
|
183
|
-
A static playground (planned for v0.3) will run
|
|
183
|
+
A static playground (planned for v0.3) will run sqlguardllm **entirely in your browser** with Pyodide and a demo SQLite database: pick a role, type the nastiest SQL you can think of, and watch it get blocked or rewritten. No server, no sign-up.
|
|
184
184
|
|
|
185
185
|
## Roadmap
|
|
186
186
|
|
|
187
187
|
| Milestone | Scope |
|
|
188
188
|
|---|---|
|
|
189
|
-
| [**v0.1 · Core guard**](https://github.com/jmmana/
|
|
190
|
-
| [**v0.2 · Row-level security & CLI**](https://github.com/jmmana/
|
|
191
|
-
| [**v0.3 · Ecosystem & playground**](https://github.com/jmmana/
|
|
189
|
+
| [**v0.1 · Core guard**](https://github.com/jmmana/sqlguardllm/milestone/1) | Statement and read-only checks, allowlists, hidden columns, denied functions, row limit, adversarial corpus |
|
|
190
|
+
| [**v0.2 · Row-level security & CLI**](https://github.com/jmmana/sqlguardllm/milestone/2) | Row filters as derived tables, policy files, CLI, dialect test matrix, docs site, PyPI release |
|
|
191
|
+
| [**v0.3 · Ecosystem & playground**](https://github.com/jmmana/sqlguardllm/milestone/3) | Integration recipes, browser playground, performance budget |
|
|
192
192
|
|
|
193
193
|
Details in [docs/ROADMAP.md](docs/ROADMAP.md).
|
|
194
194
|
|
|
@@ -199,14 +199,14 @@ Contributions are very welcome, and some of the most valuable ones need no deep
|
|
|
199
199
|
- **Add attack cases** to the adversarial corpus, especially for dialects you know well.
|
|
200
200
|
- **Extend the denied-function lists** for your database.
|
|
201
201
|
- **Translate violation messages.**
|
|
202
|
-
- **Challenge the design** in [Discussions](https://github.com/jmmana/
|
|
202
|
+
- **Challenge the design** in [Discussions](https://github.com/jmmana/sqlguardllm/discussions) before v0.1 freezes the API.
|
|
203
203
|
|
|
204
|
-
Start with [CONTRIBUTING.md](CONTRIBUTING.md) and the [good first issues](https://github.com/jmmana/
|
|
204
|
+
Start with [CONTRIBUTING.md](CONTRIBUTING.md) and the [good first issues](https://github.com/jmmana/sqlguardllm/labels/good%20first%20issue). This project follows a [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
205
205
|
|
|
206
206
|
## Security
|
|
207
207
|
|
|
208
|
-
A bypass of
|
|
208
|
+
A bypass of sqlguardllm is a security vulnerability. **Don't open a public issue:** report it privately as described in [SECURITY.md](SECURITY.md).
|
|
209
209
|
|
|
210
210
|
## License
|
|
211
211
|
|
|
212
|
-
[Apache-2.0](LICENSE) © 2026 Juan Castillo.
|
|
212
|
+
[Apache-2.0](LICENSE) © 2026 Juan Castillo. sqlguardllm was born inside [ChatIApp](https://github.com/jmmana/ChatIApp), an open-source chat that turns business questions into safe SQL.
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img alt="
|
|
2
|
+
<img alt="sqlguardllm" src="https://raw.githubusercontent.com/jmmana/sqlguardllm/main/docs/assets/logo-light.svg" width="340">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# sqlguardllm — the SQL firewall for LLM apps
|
|
6
6
|
|
|
7
|
-
Your model writes SQL. **
|
|
7
|
+
Your model writes SQL. **sqlguardllm** makes sure it can only read what it's allowed to read: one read-only statement, allowlisted tables and columns, row-level filters per user, and a row limit, in any dialect [sqlglot](https://github.com/tobymao/sqlglot) understands.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pip install sqlguardllm
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```python
|
|
14
|
-
from
|
|
14
|
+
from sqlguardllm import Guard, Policy
|
|
15
15
|
|
|
16
16
|
guard = Guard(
|
|
17
17
|
Policy(
|
|
@@ -44,8 +44,8 @@ Pure Python, one dependency (sqlglot), no network, no LLM. Status: **alpha** —
|
|
|
44
44
|
|
|
45
45
|
## Learn more
|
|
46
46
|
|
|
47
|
-
- Source, design and attack gallery: <https://github.com/jmmana/
|
|
48
|
-
- Threat model: <https://github.com/jmmana/
|
|
49
|
-
- Report a bypass privately: <https://github.com/jmmana/
|
|
47
|
+
- Source, design and attack gallery: <https://github.com/jmmana/sqlguardllm>
|
|
48
|
+
- Threat model: <https://github.com/jmmana/sqlguardllm/blob/main/docs/THREAT_MODEL.md>
|
|
49
|
+
- Report a bypass privately: <https://github.com/jmmana/sqlguardllm/security/advisories/new>
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
Licensed under Apache-2.0.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sqlguardllm"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.0a2"
|
|
4
4
|
description = "The SQL firewall for LLM apps: validate SQL written by AI and rewrite it read-only, allowlisted, row-filtered and limited."
|
|
5
5
|
readme = "docs/pypi.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -30,11 +30,11 @@ dependencies = ["sqlglot>=30.0,<31"]
|
|
|
30
30
|
yaml = ["pyyaml>=6.0"]
|
|
31
31
|
|
|
32
32
|
[project.urls]
|
|
33
|
-
Homepage = "https://github.com/jmmana/
|
|
34
|
-
Documentation = "https://github.com/jmmana/
|
|
35
|
-
Issues = "https://github.com/jmmana/
|
|
36
|
-
Changelog = "https://github.com/jmmana/
|
|
37
|
-
Source = "https://github.com/jmmana/
|
|
33
|
+
Homepage = "https://github.com/jmmana/sqlguardllm"
|
|
34
|
+
Documentation = "https://github.com/jmmana/sqlguardllm/tree/main/docs"
|
|
35
|
+
Issues = "https://github.com/jmmana/sqlguardllm/issues"
|
|
36
|
+
Changelog = "https://github.com/jmmana/sqlguardllm/blob/main/CHANGELOG.md"
|
|
37
|
+
Source = "https://github.com/jmmana/sqlguardllm"
|
|
38
38
|
|
|
39
39
|
[dependency-groups]
|
|
40
40
|
dev = [
|
|
@@ -50,7 +50,7 @@ requires = ["hatchling>=1.26"]
|
|
|
50
50
|
build-backend = "hatchling.build"
|
|
51
51
|
|
|
52
52
|
[tool.hatch.build.targets.wheel]
|
|
53
|
-
packages = ["src/
|
|
53
|
+
packages = ["src/sqlguardllm"]
|
|
54
54
|
|
|
55
55
|
[tool.hatch.build.targets.sdist]
|
|
56
56
|
include = ["src", "tests", "docs/pypi.md", "README.md", "LICENSE", "CHANGELOG.md"]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""sqlguardllm: the SQL firewall for LLM apps.
|
|
2
2
|
|
|
3
3
|
Validate SQL written by an untrusted source and rewrite it so it is a single read-only query
|
|
4
4
|
over allowlisted tables and columns, filtered per user and bounded in rows::
|
|
5
5
|
|
|
6
|
-
from
|
|
6
|
+
from sqlguardllm import Guard, Policy
|
|
7
7
|
|
|
8
8
|
guard = Guard(Policy(dialect="postgres", tables={"invoices"}, max_rows=1000))
|
|
9
9
|
result = guard.check("SELECT * FROM invoices")
|
|
@@ -13,9 +13,9 @@ from __future__ import annotations
|
|
|
13
13
|
|
|
14
14
|
from importlib.metadata import PackageNotFoundError, version
|
|
15
15
|
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
from
|
|
16
|
+
from sqlguardllm.guard import Guard
|
|
17
|
+
from sqlguardllm.policy import FunctionPolicy, Policy
|
|
18
|
+
from sqlguardllm.result import CheckResult, GuardViolation, PolicyError, Violation, ViolationCode
|
|
19
19
|
|
|
20
20
|
try:
|
|
21
21
|
__version__ = version("sqlguardllm")
|
|
@@ -12,18 +12,18 @@ from sqlglot.dialects.dialect import Dialect
|
|
|
12
12
|
from sqlglot.errors import SqlglotError
|
|
13
13
|
from sqlglot.optimizer.scope import traverse_scope
|
|
14
14
|
|
|
15
|
-
from
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
from
|
|
19
|
-
from
|
|
20
|
-
from
|
|
21
|
-
from
|
|
22
|
-
from
|
|
23
|
-
from
|
|
24
|
-
from
|
|
25
|
-
from
|
|
26
|
-
from
|
|
15
|
+
from sqlguardllm._compiled import Compiled, RowFilter
|
|
16
|
+
from sqlguardllm._names import TableName, find, norm, parse_column_entry, parse_table_entry
|
|
17
|
+
from sqlguardllm.data.denied_functions import default_denylist
|
|
18
|
+
from sqlguardllm.messages import LANGUAGES, violation
|
|
19
|
+
from sqlguardllm.policy import Policy
|
|
20
|
+
from sqlguardllm.result import CheckResult, GuardViolation, PolicyError, Violation, ViolationCode
|
|
21
|
+
from sqlguardllm.rules.columns import check_columns
|
|
22
|
+
from sqlguardllm.rules.functions import check_functions
|
|
23
|
+
from sqlguardllm.rules.limit import apply_limit
|
|
24
|
+
from sqlguardllm.rules.row_filters import apply_filters, compile_filter
|
|
25
|
+
from sqlguardllm.rules.sources import collect_sources
|
|
26
|
+
from sqlguardllm.rules.statement import check_statements
|
|
27
27
|
|
|
28
28
|
R = TypeVar("R")
|
|
29
29
|
|
|
@@ -9,7 +9,7 @@ from pathlib import Path
|
|
|
9
9
|
from types import MappingProxyType
|
|
10
10
|
from typing import Any, Literal
|
|
11
11
|
|
|
12
|
-
from
|
|
12
|
+
from sqlguardllm.result import PolicyError
|
|
13
13
|
|
|
14
14
|
FunctionPolicy = Literal["denylist", "allowlist"]
|
|
15
15
|
|
|
@@ -101,7 +101,7 @@ class Policy:
|
|
|
101
101
|
def from_file(cls, path: str | Path) -> Policy:
|
|
102
102
|
"""Load a policy from a ``.json``, ``.yaml`` or ``.yml`` file.
|
|
103
103
|
|
|
104
|
-
YAML needs the optional extra: ``pip install "
|
|
104
|
+
YAML needs the optional extra: ``pip install "sqlguardllm[yaml]"``.
|
|
105
105
|
"""
|
|
106
106
|
file = Path(path)
|
|
107
107
|
text = file.read_text(encoding="utf-8")
|
|
@@ -109,7 +109,7 @@ class Policy:
|
|
|
109
109
|
try:
|
|
110
110
|
import yaml # noqa: PLC0415
|
|
111
111
|
except ImportError as exc: # pragma: no cover - depends on the environment
|
|
112
|
-
raise PolicyError('YAML policies need: pip install "
|
|
112
|
+
raise PolicyError('YAML policies need: pip install "sqlguardllm[yaml]"') from exc
|
|
113
113
|
data = yaml.safe_load(text)
|
|
114
114
|
else:
|
|
115
115
|
data = json.loads(text)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Results, violation codes and errors of
|
|
1
|
+
"""Results, violation codes and errors of sqlguardllm."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -39,7 +39,7 @@ class Violation:
|
|
|
39
39
|
|
|
40
40
|
@dataclass(frozen=True)
|
|
41
41
|
class CheckResult:
|
|
42
|
-
"""Outcome of :meth:`
|
|
42
|
+
"""Outcome of :meth:`sqlguardllm.Guard.check`.
|
|
43
43
|
|
|
44
44
|
Attributes:
|
|
45
45
|
ok: True when the query may run.
|
|
@@ -67,11 +67,11 @@ class CheckResult:
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
class PolicyError(ValueError):
|
|
70
|
-
"""The policy itself is invalid. Raised when a :class:`~
|
|
70
|
+
"""The policy itself is invalid. Raised when a :class:`~sqlguardllm.Guard` is created."""
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
class GuardViolation(Exception):
|
|
74
|
-
"""Raised by :meth:`
|
|
74
|
+
"""Raised by :meth:`sqlguardllm.Guard.enforce` when a query is rejected."""
|
|
75
75
|
|
|
76
76
|
def __init__(self, violations: tuple[Violation, ...]) -> None:
|
|
77
77
|
self.violations = violations
|
|
@@ -5,10 +5,10 @@ from __future__ import annotations
|
|
|
5
5
|
from sqlglot import exp
|
|
6
6
|
from sqlglot.optimizer.scope import Scope
|
|
7
7
|
|
|
8
|
-
from
|
|
9
|
-
from
|
|
10
|
-
from
|
|
11
|
-
from
|
|
8
|
+
from sqlguardllm._compiled import Compiled
|
|
9
|
+
from sqlguardllm._names import TableName, find, norm, table_name
|
|
10
|
+
from sqlguardllm.messages import violation
|
|
11
|
+
from sqlguardllm.result import Violation, ViolationCode
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def _visible_sources(scope: Scope) -> dict[str, exp.Expression | Scope]:
|
|
@@ -4,9 +4,9 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from sqlglot import exp
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from
|
|
9
|
-
from
|
|
7
|
+
from sqlguardllm._compiled import Compiled
|
|
8
|
+
from sqlguardllm.messages import violation
|
|
9
|
+
from sqlguardllm.result import Violation, ViolationCode
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def function_names(node: exp.Func, dialect_name: str) -> set[str]:
|
{sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/rules/row_filters.py
RENAMED
|
@@ -13,12 +13,12 @@ import sqlglot
|
|
|
13
13
|
from sqlglot import exp
|
|
14
14
|
from sqlglot.errors import SqlglotError
|
|
15
15
|
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
from
|
|
19
|
-
from
|
|
20
|
-
from
|
|
21
|
-
from
|
|
16
|
+
from sqlguardllm._compiled import Compiled, RowFilter
|
|
17
|
+
from sqlguardllm._names import TableName, find
|
|
18
|
+
from sqlguardllm.messages import violation
|
|
19
|
+
from sqlguardllm.result import PolicyError, Violation, ViolationCode
|
|
20
|
+
from sqlguardllm.rules.sources import PhysicalRef
|
|
21
|
+
from sqlguardllm.rules.statement import WRITE_NODES
|
|
22
22
|
|
|
23
23
|
_PLACEHOLDER = re.compile(r"\{([A-Za-z_]\w*(?:\.[A-Za-z_]\w*)*)\}")
|
|
24
24
|
_SCALARS = (bool, int, float, Decimal, str, datetime.date, datetime.datetime)
|
|
@@ -7,10 +7,10 @@ from dataclasses import dataclass
|
|
|
7
7
|
from sqlglot import exp
|
|
8
8
|
from sqlglot.optimizer.scope import Scope
|
|
9
9
|
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
from
|
|
10
|
+
from sqlguardllm._compiled import Compiled
|
|
11
|
+
from sqlguardllm._names import TableName, find, table_name
|
|
12
|
+
from sqlguardllm.messages import violation
|
|
13
|
+
from sqlguardllm.result import Violation, ViolationCode
|
|
14
14
|
|
|
15
15
|
_DUAL_DIALECTS = frozenset({"oracle", "mysql"})
|
|
16
16
|
|
|
@@ -4,8 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from sqlglot import exp
|
|
6
6
|
|
|
7
|
-
from
|
|
8
|
-
from
|
|
7
|
+
from sqlguardllm.messages import violation
|
|
8
|
+
from sqlguardllm.result import Violation, ViolationCode
|
|
9
9
|
|
|
10
10
|
_WRITE_NODE_NAMES = (
|
|
11
11
|
"Insert",
|
|
@@ -2,14 +2,14 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import sqlguardllm
|
|
6
6
|
from conftest import CONTEXT, standard_policy
|
|
7
|
-
from
|
|
8
|
-
from
|
|
7
|
+
from sqlguardllm import Guard, GuardViolation, PolicyError, ViolationCode
|
|
8
|
+
from sqlguardllm.messages import _TEMPLATES
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def test_version_is_exposed() -> None:
|
|
12
|
-
assert
|
|
12
|
+
assert sqlguardllm.__version__
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def test_enforce_returns_safe_sql(guard: Guard) -> None:
|
|
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|
|
5
5
|
import pytest
|
|
6
6
|
|
|
7
7
|
from conftest import CONTEXT, standard_policy
|
|
8
|
-
from
|
|
8
|
+
from sqlguardllm import Guard, Policy, ViolationCode
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def test_result_lists_physical_tables(guard: Guard) -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sqlguardllm-0.1.0a1/src/sqlguard → sqlguardllm-0.1.0a2/src/sqlguardllm}/data/denied_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|