Skip to main content

sqlguardllm

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, EXEC or row locks, at any depth. A DELETE hidden 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.*, DuckDB read_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: 1.0 stable — the core API and the 15 core violation codes follow semver.

Learn more

Licensed under Apache-2.0.

Metadata

Release files for sqlguardllm 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlguardllm 1.0.0
File Size Uploaded Provenance Actions
sqlguardllm-1.0.0.tar.gz 325.2 kB With provenance Details for sqlguardllm-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlguardllm 1.0.0
File Interpreter ABI Platform Actions
sqlguardllm-1.0.0-py3-none-any.whl Python 3 none any Details for sqlguardllm-1.0.0-py3-none-any.whl

Total release size: 476.5 kB

Release files / sqlguardllm-1.0.0.tar.gz

Download URL sqlguardllm-1.0.0.tar.gz
Size 325.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c4f0f7423a93afc5a3f71601575e4a81a06ba0b689c36a6e0cdfa611ed70e0ea
BLAKE2b-256 checksum
How to use checksums
f60f39a8a215a68306d9b15dfda2ff606846264c42f10df749e633453ba560d4
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 Dec 1, 2026.

Transparency log

Release files / sqlguardllm-1.0.0-py3-none-any.whl

Download URL sqlguardllm-1.0.0-py3-none-any.whl
Size 151.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fe7fd9da9143ec1384f307e22c7c0819acad7f94ad20f2628cb6a4498948ca7
BLAKE2b-256 checksum
How to use checksums
fb900554f56ee6a464ef909c3365e085bac4801b00910529204800b683dbad9d
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 Dec 1, 2026.

Transparency log

Security for sqlguardllm 1.0.0

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.

Select from 2 files

Attestation for sqlguardllm-1.0.0.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 Dec 1, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page