run_query
Execute ad-hoc SQL queries against a data source with safety guards, returning results as a table or JSON. Confirm tables and columns first for best use.
Instructions
Execute an ad-hoc SQL query against a data source and return the resulting rows. Every query passes through the SQL safety guard, which blocks destructive statements (DROP/TRUNCATE/ALTER, DELETE/UPDATE without WHERE) and flags PII columns and expensive full scans; results are cached in memory. Behavior: returns up to max_rows rows as a markdown table or JSON, with the column list and a truncation note when there are more rows. Usage: confirm table and column names with list_tables and get_table_columns first; for natural-language questions, plan the SQL with smart_query before calling this. To run an already-saved query instead, use get_query_result.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL query to execute | |
| format | No | Output format: table (markdown) or json | table |
| max_age | No | Redash cache TTL in seconds (0 to 604800). Defaults to REDASH_DEFAULT_MAX_AGE env var | |
| max_rows | No | Max rows to return (1 to 10000, default 100) | |
| timeout_secs | No | Query execution timeout in seconds (1 to 300, default 30) | |
| data_source_id | Yes | Data source ID from list_data_sources |