Skip to content

Benchmark of SQL guards for LLM agents

Agent frameworks ship their own SQL validators and, until now, nobody measured them against the same inputs. This benchmark does it in the open and can be reproduced in one command.

uv run python -m sqlguardllm.bench --json guards.json

The same command measures your own validator, in any language, without cloning this repository: see Run it on your own validator.

What it measures

Metric Meaning Better
Bypass rate Attacks the validator accepts. Attacks are the adversarial corpus cases that any read-only guard must reject whatever its policy: writes, statements that are not queries, stacked statements, row locks and dangerous functions lower
False-positive rate Legitimate queries the validator rejects, from benchmarks/guards/legitimate.yaml (columns named open, close, version, user, set, keywords inside strings and comments...) lower
Errors Cases with no usable answer (timeout, early exit, malformed or missing answer). Counted apart, never as accept or reject, and left out of the two rates zero
Median ms per check One validation on a warm validator (round trip for --adapter-cmd) lower

Policy-specific rules (hidden columns, table allowlists, row filters) are left out, because only sqlguardllm implements them; the comparison is about read-only safety.

First public table

Measured with sqlguardllm 0.5.0a8, Python 3.12, 69 attacks and 34 legitimate queries.

Validator Attacks accepted (bypass) Legitimate rejected (false positive) Median ms/check
sqlguardllm 0/69 (0%) 0/34 (0%) 0.118
keyword-list (baseline) 59/69 (86%) 3/34 (9%) 0.001
first-word (baseline) 56/69 (81%) 1/34 (3%) 0.000

The baselines are two typical home-made guards: a list of write keywords searched anywhere in the text, and "the first word must be SELECT/WITH with no ;". They are fast because they do not parse the SQL; that is also why they miss attacks inside a SELECT and reject harmless text. Timings depend on the machine; compare the rows, not the absolute values.

Third-party validators are not in this table. See the publication rule below.

Run it on your own validator

pip install sqlguardllm   # or: uv add --dev sqlguardllm
python -m sqlguardllm.bench --adapter-cmd "node my_guard.js"      # any language
python -m sqlguardllm.bench --adapter-py my_package.guard:accepts  # Python

Without adapter options the built-in validators run (sqlguardllm and the two baselines); --builtin NAME picks some of them. Options:

Option Meaning
--adapter-cmd CMD Start CMD as a process and speak JSON lines to it (below). Repeatable. CMD is split like a shell would and run without a shell, with your privileges: only pass commands you trust
--adapter-py module:function Python validator function(sql, dialect) -> bool, True meaning accepted. An exception or a non-bool answer is an error
--timeout SECONDS Time allowed per case for --adapter-cmd (default 5)
--json PATH Full report: counts, ids of bypassed, falsely rejected and errored cases, per category and per dialect
--badge PATH shields.io endpoint JSON for a single adapter
--corpus PATH Another corpus file with the same format

The output is a markdown table plus the bypass count per attack category (write, not_a_query, stacked, row_lock, function) and the results per dialect. The exit code is 0 whatever the results (it is a benchmark, not a gate) and 2 when the run cannot start (an adapter that does not start, a bad corpus, bad options).

JSON-lines protocol

The benchmark starts the process once and, for each case, writes one line to its stdin and reads one line from its stdout:

-> {"id": "pg-delete", "dialect": "postgres", "sql": "DELETE FROM invoices"}
<- {"id": "pg-delete", "accept": false}

accept is true when your validator lets the query through and false when it rejects it. Write only answers to stdout (logs go to stderr) and flush after every line. A complete example, a keyword list in Node, is in benchmarks/guards/adapters/node-example/.

Everything else is an error, reported separately and never counted as accept or reject: no answer within the timeout, the process exiting, a line that is not JSON, a missing or non-boolean accept, or an id that is not the one asked. After a timeout, an early exit or a wrong id the process is restarted so a late answer cannot be taken for the next case; after five restarts in a row the adapter is abandoned and its remaining cases are errors. Bypass and false-positive rates are taken over the answered cases, so an adapter that fails on everything shows n/a, not 0%.

Corpus

The corpus is a versioned JSON file, corpus-v1.json, shipped inside the package and also published at a stable URL: https://jmmana.github.io/sqlguardllm/assets/corpus-v1.json.

{"version": 1, "cases": [{"id": "pg-delete", "kind": "attack", "category": "not_a_query", "dialect": "postgres", "sql": "DELETE FROM invoices"}]}

kind is attack or legitimate; category is set only for attacks. The file is generated by benchmarks/guards/build_corpus.py from tests/corpus and benchmarks/guards/legitimate.yaml, and a test fails when it drifts from them. A corpus change gets a new file name (corpus-v2.json); corpus-v1.json never changes meaning.

Badge

python -m sqlguardllm.bench --adapter-cmd "node my_guard.js" --badge bench-badge.json

writes, for example, {"schemaVersion": 1, "label": "guard bench", "message": "bypass 0/69 · FP 0/34", "color": "brightgreen"}. The colour is green with no bypass, no false positive and no error, red with any bypass, and yellow otherwise. Host the file anywhere public and point shields.io at it:

![guard bench](https://img.shields.io/endpoint?url=https%3A%2F%2Fexample.org%2Fbench-badge.json)

GitHub Actions

A snippet for your own repository (this repository adds no workflow for it):

name: guard-benchmark
on: [push]
jobs:
  bench:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: {node-version: 22}
      - uses: actions/setup-python@v5
        with: {python-version: "3.12"}
      - run: pip install sqlguardllm
      - run: python -m sqlguardllm.bench --adapter-cmd "node my_guard.js" --json bench.json --badge bench-badge.json
      - uses: actions/upload-artifact@v4
        with: {name: guard-benchmark, path: "bench*.json"}

Publication rule

This repository does not publish third-party results; authors publish their own. Run the benchmark on your validator and share the table or the badge in your project, linking back to this page. Results for a third-party validator are published here only when every finding behind them is already public (published advisory, public upstream issue or released fix), or 90 days after the maintainers acknowledged a private report. Adapters and results that do not meet the rule stay out of this repository, including branch names, commit messages, test names and playground links. See AGENTS.md.

Checklist before adding a third-party adapter:

  • [ ] Every attack the adapter is expected to miss has a public source (advisory, upstream issue or release note), linked in the pull request.
  • [ ] No unpublished case appears in the corpus, test names, commits, branches or results.
  • [ ] The validator is pinned to an exact version and the version is shown in the table.
  • [ ] The maintainers were told before the table was published, and the wording credits their work.

Add a validator or a case

  • Validator: yours runs with --adapter-cmd or --adapter-py, no change here. A built-in one is a function returning accepts(sql, dialect) -> bool in src/sqlguardllm/bench/adapters.py, registered in BUILTIN_ADAPTERS, after the checklist above.
  • Attack: add it to tests/corpus/ (see the attack gallery); it is picked up when its codes are read-only ones. Then run uv run python benchmarks/guards/build_corpus.py to regenerate the corpus files.
  • Legitimate query: add it to benchmarks/guards/legitimate.yaml and regenerate the corpus the same way.