
What You’ll Accomplish
Guardrails let you block dangerous queries before they execute. You can:- Prevent accidental
UPDATEorDELETEwithout aWHEREclause - Block
DROP TABLEand other destructive DDL commands - Enforce read-only access for specific user groups
- Require
LIMITclauses on large tables - Block queries that access sensitive columns
The Problem Guardrails Solve
Without guardrails, one typo can destroy production data:How Guardrails Work
Rule Types
| Type | Description | Use Case |
|---|---|---|
| Input Rules | Evaluate the query before execution | Block dangerous commands |
| Output Rules | Evaluate results after execution | Redact sensitive data in output |
Quick Start
Prerequisites
To get the most out of this guide, you will need to:- Either create an account in our managed instance or deploy your own hoop.dev instance
- You must be your account administrator to perform the following actions
- At least one database connection configured
- Admin access to create guardrails
Step 1: Create a Guardrail
Step 2: Add an Input Rule
In the Input Rules section:- Click Add Rule
- Select Pattern Match (Regex)
- Enter the pattern:
- Set Action to Block
- Enter the error message:
Blocked: UPDATE/DELETE requires a WHERE clause
The
(?i) makes the pattern case-insensitive, so it catches update, UPDATE, and Update.Step 3: Assign to Connections
- In the Connections section, select which connections this guardrail applies to
- Choose your production database connections
- Click Save
Step 4: Test the Guardrail
Try running an unsafe query:Common Guardrail Recipes
Recipe 1: Block Destructive DDL
Prevent accidental schema changes in production. Pattern:DDL commands are blocked. Use a migration tool or request elevated access.
What it catches:
DROP TABLE usersTRUNCATE TABLE ordersALTER TABLE customers DROP COLUMN email
Recipe 2: Read-Only Access
Block all write operations for analyst or read-only user groups. Patterns (create separate rules for each):| Pattern | Blocks |
|---|---|
(?i)^\s*INSERT\s+INTO | INSERT statements |
(?i)^\s*UPDATE\s+ | UPDATE statements |
(?i)^\s*DELETE\s+FROM | DELETE statements |
(?i)^\s*(CREATE|DROP|ALTER)\s+ | DDL commands |
This connection is read-only. Write operations are not permitted.
Recipe 3: Block SELECT * on Large Tables
Prevent queries that could return millions of rows. Pattern:SELECT * without LIMIT is blocked on large tables. Add a LIMIT clause or select specific columns.
What it catches:
SELECT * FROM orders(blocked)SELECT * FROM orders LIMIT 100(allowed)SELECT id, status FROM orders(allowed)
Recipe 4: Prevent Credential Access
Block queries that might expose passwords or secrets. Pattern:Queries selecting credential columns are blocked. Use the appropriate service to manage credentials.
Recipe 5: Require LIMIT on All Queries
Warn users when they forget to add LIMIT. Pattern:Consider adding a LIMIT clause to prevent large result sets.
Use Warn instead of Block when you want to educate users without stopping their work.
Recipe 6: Block Specific Table Access
Restrict access to sensitive tables likesalaries or api_keys.
Pattern:
Access to this table is restricted. Contact your administrator for access.
Testing Guardrails Safely
Testing Process
Test Cases to Run
For each guardrail, test:- Should block: A query that matches the pattern exactly
- Should allow: A similar query that doesn’t match
- Edge cases: Queries with different casing, extra whitespace, or variations
Viewing Blocked Queries
When a guardrail blocks a query, it’s logged in Sessions.Emergency Bypass
If a legitimate query is blocked and needs to run immediately:Option 1: Temporarily Disable the Guardrail
- Go to Manage > Guardrails
- Find the blocking guardrail
- Toggle it to Disabled
- Run your query
- Re-enable the guardrail immediately after
Option 2: Refine the Pattern
If the guardrail is catching legitimate queries, update the pattern:- Go to Manage > Guardrails > [guardrail name]
- Edit the rule that’s causing issues
- Refine the regex to be more specific
- Save and test
Option 3: Add an Exception
For specific users or groups that need to bypass certain rules:- Create a new connection without the guardrail
- Restrict access to that connection to specific groups
- Use this “elevated” connection for exceptional cases
Troubleshooting
Guardrail Not Blocking Expected Queries
Check:- Guardrail is enabled - Verify the toggle is on in Manage > Guardrails
- Connection is assigned - Check that the connection is in the guardrail’s connection list
- Pattern syntax is valid - Test your regex at regex101.com
- Case sensitivity - Add
(?i)at the start for case-insensitive matching
| Problem | Bad Pattern | Fixed Pattern |
|---|---|---|
| Missing case-insensitive | DROP TABLE | (?i)DROP TABLE |
| Missing word boundaries | DELETE | \bDELETE\b |
| Anchoring too strict | ^DROP | ^\s*DROP (allows leading whitespace) |
False Positives (Legitimate Queries Blocked)
Problem: Pattern is too broad Example:- Pattern:
DROP - Blocks:
SELECT * FROM drop_shipped_orders(has “DROP” in table name)
Performance Impact
Guardrails add minimal latency (typically 1-5ms per query). If you notice slowdowns:- Reduce rule count - Combine similar rules where possible
- Simplify patterns - Complex regex with backtracking is slower
- Use Input Rules - Input rules are faster than Output rules
Guardrails vs Other Features
| Feature | Purpose | When to Use |
|---|---|---|
| Guardrails | Block queries based on patterns | Prevent dangerous operations |
| Live Data Masking | Redact sensitive data in output | Protect PII in query results |
| Access Requests | Require approval for access | Time-limited or command-level approval |
| Access Control | Control who can access connections | Restrict connection visibility |
- Guardrails block
DROP TABLEcommands - Live Data Masking redacts SSN in
SELECTresults - Access Requests require approval before connecting
- Access Control limits who sees the connection
Next Steps
Guardrails Configuration
Detailed configuration options and rule syntax
Live Data Masking
Automatically redact sensitive data in query results
Access Requests
Require approval for access to sensitive connections
Session Recording
Audit all query executions including blocked queries