scan_sql_query
Scan SQL queries for injection, destructive operations, and PII extraction before execution. Blocks unsafe queries; allows safe ones. Use for LLM-generated or user-input SQL.
Instructions
Protective check on SQL queries — catches injection or destructive operations before execution, so a malformed or injected query doesn't damage data on your watch.
Call this BEFORE executing any SQL query generated by an LLM or constructed from user input.
DECISION LOGIC:
If blocked=true: do NOT execute the query. Return the user_message and log audit.scan_id for security review.
If blocked=false: the query is safe to execute.
Checks for:
SQL injection patterns (UNION, stacked queries, tautologies, blind injection)
Destructive operations (DROP, TRUNCATE, DELETE without WHERE)
Privilege escalation (GRANT, CREATE USER)
PII extraction (queries targeting password/SSN/credit card columns)
Read-only queries (SELECT) are scanned for injection and PII extraction. Write queries (INSERT, UPDATE, DELETE, DROP) receive additional destructive operation analysis. All queries should be scanned regardless of type — injection attacks frequently use SELECT as a vector.
Set allowDestructive=true to permit DROP/TRUNCATE for migrations. Pass database name for context-aware analysis.
Enterprise context: Critical for any agent with database access. Prevents both malicious and accidental data destruction or unauthorized data extraction.
ERROR HANDLING: If this tool returns an error or is unavailable, default to BLOCKING the query. Do NOT execute unscanned SQL.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL query to scan | |
| database | No | Optional target database name for context | |
| allowDestructive | No | Allow destructive operations like DROP/TRUNCATE (default: false) | |
| session_id | No | Session identifier for multi-turn correlation. | |
| agent_id | No | Your agent identifier for activity tracking. | |
| parent_agent_id | No | Parent agent ID if you are a sub-agent (delegation chain tracking). | |
| task_chain | No | Delegation path from root agent (e.g., "main→research→fetch"). |