AST-Level Read-Only SQL Query & Injection Safety Validator
validate_sql_query_astStatically parses SQL statements via AST to verify strictly read-only SELECT clauses and reject mutations, stacked queries, or comment bypasses before execution.
Instructions
Performs static AST syntax tree parsing on SQL statements to verify strictly read-only SELECT clauses and reject mutations, stacked queries, or comment bypasses. Use when verifying that an agent-authored SQL statement is strictly read-only before running it on a database; for screening non-SQL bash commands or general agent prompts, use verify_agent_command_safety instead. Stateless read-only edge call (max 32 KB, 60 RPM): accepts 'sql_statement' ('dialect' defaults to 'postgres'), supports '?demo=true' or L402 (15 sats), and returns HTTP 400 if invalid.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dialect | No | SQL dialect ruleset used for AST token inspection; defaults to 'postgres' when omitted. | |
| sql_statement | Yes | SQL statement string to statically parse and audit for read-only SELECT compliance (e.g. 'SELECT id, email FROM users WHERE active = 1'). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| verdict | Yes | Execution decision ('ALLOW_EXECUTION' or 'BLOCK_EXECUTION'). | |
| safe_read_only | Yes | True when the query is a pure SELECT statement with zero injection clauses. | |
| blocked_clauses | Yes | List of destructive or injection SQL tokens detected. | |
| tables_accessed | Yes | Table identifiers referenced in FROM and JOIN clauses. |