Run custom SQL in Snowflake safely

Recipe ToolsDatabaseMarketing

What it does

When someone calls the Snowflake Custom SQL Wrapper, this automation sanitizes the SQL input to block unsafe patterns. The validated query runs in Snowflake and returns the results, or stops with an error if the SQL is invalid.

Who it's for

Data and analytics teams who need to execute custom SQL queries in Snowflake through a callable interface.

How teams use this

Execute analytics queries safely

Run custom SQL in Snowflake through a callable interface with built-in validation to prevent injection attacks. The sanitization check happens before execution so only safe queries run.

Integrate SQL execution into workflows

Call this wrapper from other automations to execute Snowflake queries without building SQL logic into each workflow. Add the callable interface to parent workflows so teams reuse the same sanitized query execution.

Audit SQL execution in logs

Log each query attempt and result to the job report so the team can track what SQL ran, when it ran, and whether it succeeded. Include query timestamps and validation outcomes in the report for compliance.

How it works

  1. Receive the SQL query call. Someone calls the Snowflake Custom SQL Wrapper and passes a SQL query as input to this automation.
  2. Validate the SQL input. Check if the SQL contains dangerous patterns like template injection syntax. If unsafe syntax is found, log the attempt and stop the job with an error.
  3. Execute the sanitized query. Run the validated SQL query in Snowflake and retrieve the results from the database.
  4. Return the results to caller. Send the Snowflake response back to the caller so they receive the query output or error details.