This release is a pre-release and may not be stable for production use.
sqlguardllm — the SQL firewall for LLM apps
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 understands.
pip install sqlguardllm
from sqlguardllm import Guard, Policy
guard = Guard(
Policy(
dialect="postgres",
tables={"invoices", "branches", "customers"},
hidden_columns={"customers.email"},
row_filters={"invoices": "branch_id IN ({user.branches})"},
max_rows=1000,
)
)
result = guard.check(sql_from_llm, context={"user": {"branches": [1, 2]}})
if result.ok:
rows = db.execute(result.sql) # read-only, row-filtered, limited
else:
print(result.messages) # ["The query tries to change data or structure (DELETE)"]
What it guarantees
- One statement that is a query. Nothing stacked after a
;. - Read-only across the whole syntax tree: no
INSERT,UPDATE,DELETE,MERGE,SELECT … INTO, DDL,COPY,ATTACH,PRAGMA,EXECor row locks, at any depth. ADELETEhidden in a CTE is caught. - Allowlisted tables and hidden columns, CTE-aware;
SELECT *, whole-row references and predicates on hidden columns are rejected. - Denied functions per dialect: file readers, sleeps, shells, network calls and functions that run SQL from a string (
pg_read_file,query_to_xml,LOAD_FILE,OPENROWSET,DBMS_PIPE.*, DuckDBread_csv…). - Row-level filters: every occurrence of a table becomes a filtered derived table, with the user's values bound as escaped literals.
- Row limit in the dialect's own syntax (
LIMIT,TOP,FETCH FIRST). - Fails closed: what can't be understood is rejected with a reason.
Pure Python, one dependency (sqlglot), no network, no LLM. Status: alpha — the API may still change before 1.0; violation codes are stable.
Learn more
- Source, design and attack gallery: https://github.com/jmmana/sqlguardllm
- Threat model: https://github.com/jmmana/sqlguardllm/blob/main/docs/THREAT_MODEL.md
- Report a bypass privately: https://github.com/jmmana/sqlguardllm/security/advisories/new
Licensed under Apache-2.0.
Metadata
Release files for sqlguardllm 0.2.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqlguardllm-0.2.0a1.tar.gz | 37.9 kB | With provenance | Details for sqlguardllm-0.2.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqlguardllm-0.2.0a1-py3-none-any.whl | Python 3 | none | any | Details for sqlguardllm-0.2.0a1-py3-none-any.whl |
Total release size: 68.7 kB
Release files / sqlguardllm-0.2.0a1.tar.gz
| Download URL | sqlguardllm-0.2.0a1.tar.gz |
|---|---|
| Size | 37.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dea19ad2ce1e900e319778b977b17f1cba55c527c1a24656eb958c5f8d87b40
|
|
BLAKE2b-256 checksum How to use checksums |
1db98e447596a896cc4b57f4255fb79c3cd3059b139a11c3cb017f0c24c5cc11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logRelease files / sqlguardllm-0.2.0a1-py3-none-any.whl
| Download URL | sqlguardllm-0.2.0a1-py3-none-any.whl |
|---|---|
| Size | 30.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8c25485fc71e5a0994be4c79857f544d4158845684b385b65c895b0a967878b
|
|
BLAKE2b-256 checksum How to use checksums |
3dc317aa8f987f88dd82ed7bf638f0b34f6f4b54da79c089b4a49e3a88aa2e56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for sqlguardllm 0.2.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sqlguardllm-0.2.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.