# Repository Briefing: jmmana/sqlguardllm
> Source: https://repoforai.com/repo/jmmana/sqlguardllm (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/jmmana/sqlguardllm
- **Official Docs / Website**: https://jmmana.github.io/sqlguardllm/
- **Category**: Coding, Skills & MCP (AI 编程 / Skills / MCP)
- **Primary Language**: Python
- **License**: Apache-2.0
- **Engineering Health**: A (81/100 · Maintenance 35/35 · Adoption 6/25 · Releases 20/20 · License 20/20)
- **Latest Release**: v1.1.0 (2026-12-03) — https://github.com/jmmana/sqlguardllm/releases
- **Review Snapshot**: 2026-12-03 (Note: v1.1.0 on 2026-12-03 shipped after this review; verify latest release notes)
- **Deployment / Stack Signals**: Docker, MCP, CLI, API
- **Momentum**: 21 ★ total (+1 24h / +12 7d) · 1 forks
- **Topics**: `ai-agents`, `ai-safety`, `ai-security`, `database`, `guardrails`, `llm`, `llm-security`, `mcp`, `mcp-server`, `model-context-protocol`, `nl2sql`, `prompt-injection`
- **When to Use**: Best for: Text-to-SQL or MCP data tools that need a policy check before execution, especially when tenant filters and column restrictions must be applied consistently over a restricted database account. Skip if: You cannot route every generated query through the guard, need a substitute for database authorization, or require stable support for proxying, writes, or stored procedures.

## Overview
```text
### Architecture & Core Mechanics
SQLGuardLLM puts a Python policy engine between model-generated SQL and the database. It uses sqlglot to parse the input for a configured dialect, checks the entire syntax tree for a single read-only query under the default policy, and enforces table and column restrictions and dialect-specific function denials. Parse failures and missing filter context fail closed. An accepted query is regenerated from the rewritten tree; the original input is not the execution artifact.

For each reference to a filtered table, the engine substitutes an alias-preserving derived table and inserts escaped literals from trusted user context. That puts the row restriction at the table reference rather than attaching it only to the outer query, which matters for joins, subqueries, and CTEs. The guard then applies or tightens the result limit in the target dialect. The same engine is exposed through the Python API, CLI, HTTP service, and MCP; conformance tests compare decisions across Python, HTTP, Node.js, and .NET.

### Key Capabilities & Differentiators
The read-only policy can reject wildcard access to tables with hidden columns, apply null, redact, hash, or partial masking, and enforce aggregate-only access. Join and subquery limits and optional `EXPLAIN` cost checks govern query shape and estimated cost separately from output size. JSONL and OpenTelemetry are available for audit. Dialect coverage spans 30+ dialects, but the named CI execution targets are PostgreSQL 16 and 18, MySQL 8, and SQL Server 2022.

The project benchmark accepted 0 of 69 attack cases and rejected 0 of 34 legitimate queries. On those same inputs, keyword filtering accepted 59 attack cases and rejected 3 legitimate queries; checking for a leading `SELECT` accepted 56 and rejected 1. Those numbers describe the test set, not a security proof. The experimental tier adds proxying for mapped MCP SQL tools, approved writes with a signed ledger and conditional undo, allowlisted stored procedures, and session-level restrictions after reading configured untrusted columns.

### Trade-offs & Limitations
AST validation is more precise than keyword filtering and requires less hand-maintained matching logic, but it shifts work to schema-aware policy design and dialect testing. A 30+ dialect parsing surface is not equivalent to database-backed verification on every engine. Test representative queries against the deployed database, including joins and aggregations, and choose limits that preserve the answers users need. An output row cap limits returned data, not the amount of data scanned or the work needed to compute the result.

Keep least-privilege credentials, database grants, and native row-level security where available. They cover access paths that never pass through this guard. A shared HTTP service centralizes policy rollout but adds a network dependency; embedding avoids that hop but makes consistent rollout across applications your responsibility. Treat experimental writes as a separate trust boundary: they require a separate write credential and an approval-capable MCP client, and the ledger holds row data that must be protected.

### Hardware & Deployment Guide
Python 3.10+ can run the guard in process. Node.js 18+ and .NET 8 or 10 can run the embedded engine on supported platforms without a separate Python installation or service, or call `sqlguardllm serve` to centralize policy. For a sandbox evaluation, `uv run --extra mcp sqlguardllm mcp --demo` runs from a checkout using fictional data without an external database or policy file. A real deployment needs a policy matched to its schema, trusted identity context for row filters, and a restricted database connection for execution.

No Docker image is published. The supplied Dockerfile builds the HTTP service on `python:3.12-slim`, installs the `serve` extra, runs as UID 10001, exposes port 8787, checks `/v1/health`, and defaults to `/policy/policy.yaml`. v1.0.0 stabilizes the core API and 15 core violation codes; for MCP, the stable tool is `query`. Shadow mode is not included in v1.0.0, and the stability commitment does not extend to the experimental features.
```

## Key Capabilities
```text
- Execution boundary: sqlglot parses the full statement; accepted SQL is regenerated from the validated and rewritten tree.
- Tenant scoping: filtered table references become alias-preserving derived tables, using values from trusted session context.
- Data exposure: policy can hide or mask columns, require aggregation, and lower the output row cap in the target dialect.
- Test coverage: the project benchmark reports 0 of 69 attack cases accepted and 0 of 34 legitimate queries rejected; CI also exercises four named database versions.
- Integration surfaces: Python runs in process, Node.js and .NET can use the embedded engine or HTTP, and MCP exposes a stable read-only `query` tool.
- Stability boundary: v1.0.0 covers the core API and 15 core violation codes; proxying, writes, stored procedures, and tainted sessions remain experimental.
```

## Quick Start / Clone
```bash
pip install sqlguardllm
```
