sql-guard TypeScript package validates AI-generated PostgreSQL via AST before execution
Developer has released sql-guard, a TypeScript package designed to validate AI-generated PostgreSQL queries before they are executed by an application. The tool parses SQL into an abstract syntax tree (AST) and checks it against a developer-defined allowlist policy, catching issues that simple text pattern-matching cannot reliably detect. The package blocks unauthorized table access, disallows unrecognized function calls, and rejects multi-statement input by default, making its initial policy deliberately strict. It returns structured violation details and error codes, and offers an assertSafeSql() method that throws an error to halt execution on rejection. The package focuses solely on query structure validation and is not a substitute for parameterized queries, row-level security, or other database access controls.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in