How jmmana/sqlguardllm works
sqlguardllm is a SQL firewall for LLM applications and agents. The principal workflow is: an application supplies model-generated SQL, a policy and trusted user context; the guard parses and validates the query, then rewrites permitted queries with row filters and a row cap, returning either safe SQL or violations. The Python package is the central runtime, exposed through HTTP, stdio/MCP and language clients. The README documents additional write, procedure, masking, auditing and integration capabilities; several are represented at their documented subsystem level because their implementation was not sampled.
Main entry points: guard.py Guard · SqlGuardLlm.cs .NET client · index.ts Node client · engine_stdio.py Stdio engine
Components 24
Policy and guard
- Policy
src/sqlguardllm/policy.py - Policy sets
src/sqlguardllm/policy_set.py - Guard
src/sqlguardllm/guard.py - Results
src/sqlguardllm/result.py - Violation messages
src/sqlguardllm/messages.py
Validation and rewrite
- SQL rules
src/sqlguardllm/rules - Row filters
src/sqlguardllm/rules/row_filters.py - Procedure rules
src/sqlguardllm/rules/procedures.py
Runtime interfaces
- HTTP server
src/sqlguardllm/server.py - Stdio engine
src/sqlguardllm/engine_stdio.py - MCP server
src/sqlguardllm/mcp_server.py - Database proxy
src/sqlguardllm/proxy.py - CLI
src/sqlguardllm/cli.py
Language integrations
- Node client
clients/node/src/index.ts - Embedded engine locator
clients/node/src/engine.ts - .NET client
clients/dotnet/src/SqlGuardLlm/SqlGuardLlm.cs - .NET adapters
clients/dotnet/src/SqlGuardLlm.Extensions - EF Core interceptor
clients/dotnet/src/SqlGuardLlm.EntityFrameworkCore/SqlGuardCommandInterceptor.cs - Semantic Kernel filter
clients/dotnet/src/SqlGuardLlm.SemanticKernel/SqlGuardFunctionFilter.cs - LangChain tools
clients/langchain/src/langchain_sqlguardllm/tools.py
Deployment features
- Audit log
src/sqlguardllm/audit.py - Policy explanation
src/sqlguardllm/explain.py
Other components
- LLM application
- SQL database
Connections 27
- LLM application → HTTP server: submits SQL
README.md - LLM application → Node client: uses client
README.md - LLM application → .NET client: uses client
README.md - Policy → Guard: configures
src/sqlguardllm/guard.py - Guard → SQL rules: validates and rewrites
src/sqlguardllm/guard.py - Guard → Row filters: applies filters
src/sqlguardllm/guard.py - Guard → Procedure rules: checks procedures
src/sqlguardllm/guard.py - Guard → Results: returns decision
src/sqlguardllm/guard.py - Guard → Violation messages: formats violations
src/sqlguardllm/guard.py - Guard → Audit log: records decision
src/sqlguardllm/guard.py - Guard → Policy explanation: explains policy
src/sqlguardllm/guard.py - Policy sets → Policy: contains policies
src/sqlguardllm/policy_set.py - Policy sets → Guard: selects guard
src/sqlguardllm/policy_set.py - HTTP server → Guard: checks requests
src/sqlguardllm/server.py - Stdio engine → Guard: dispatches checks
src/sqlguardllm/engine_stdio.py - Stdio engine → Policy: loads policy
src/sqlguardllm/engine_stdio.py - MCP server → Guard: serves guard tools
- Database proxy → Guard: guards queries
- CLI → Guard: runs guard
- Node client → Embedded engine locator: locates engine
clients/node/src/index.ts - Node client → Stdio engine: uses engine protocol
- .NET client → HTTP server: sends requests
clients/dotnet/src/SqlGuardLlm/SqlGuardLlm.cs - .NET adapters → .NET client: registers client
clients/dotnet/src/SqlGuardLlm.Extensions/ServiceCollectionExtensions.cs - EF Core interceptor → .NET client: intercepts commands
- Semantic Kernel filter → .NET client: filters functions
- LangChain tools → Guard: wraps guard
- LLM application → SQL database: executes returned SQL
README.md