Integrations · Data and spreadsheets
Validate email addresses in Snowflake
Two SQL functions for Snowflake: validate_email(email) returns the status of an address (valid, invalid, catch_all, unknown or disposable), and validate_email_details(email) returns an object with the reason, the suggested action and, for a row that could not be checked, an error code instead of a status.
SELECT email, validate_email(email) AS status FROM customers;
SELECT email, validate_email_details(email):reason::VARCHAR AS reason FROM customers;Download email-validation-snowflake.zip: it unpacks into a folder email-validation-snowflake holding the SQL scripts (sql/), the Python handler of the functions that run inside Snowflake (external-access/ev_validate.py, also written out in full in sql/external-access.sql), the AWS Lambda handler of the external function (handler/) and LICENSE (MIT). It has not run in a real Snowflake account yet: it was built from Snowflake's documentation and tested against stand-ins.
Pick a path
Browser only: the path inside Snowflake needs nothing but a SQL file in Snowsight's Workspaces. The AWS path needs the AWS console and a build of the Lambda function from the download.
Both paths give the same two functions with the same results, so your SQL is the same after setup.
| Item | What you set up | Files |
|---|---|---|
| Inside Snowflake | A network rule for our API host, a secret holding your key, an external access integration and two Python functions. Nothing outside Snowflake | sql/external-access.sql |
| External function on AWS | A Lambda function behind Amazon API Gateway in your AWS account, and an API integration in Snowflake. The key stays in AWS Secrets Manager, never in SQL | handler/, sql/1-api-integration-aws.sql, sql/2-external-functions.sql |
The first is less to set up. It needs external access on your Snowflake account, which Snowflake turns on for trial accounts only on request.
What it costs
Every non-NULL row a query passes to these functions is checked each time the query runs, and a definite result costs one credit; the same address twice in one batch is checked once. unknown results, malformed addresses and test addresses on sandbox.email-validation.org are free. A check of an address checked before also costs a credit (repeat checks).
- A query over a million rows can spend a million credits, and running it again spends them again: nothing in the functions remembers an earlier answer. A view that calls them checks again whenever it is read.
- Snowflake does not promise to pass each row exactly once: it sends a failed batch again, and a query plan may call a function on more rows than the query returns (a
LIMITorWHEREafter the call does not reliably stop it). - A query that fails part-way keeps none of its results, but the rows it already checked were charged.
So check each address once into a table and join to it (below), and give the key a daily credit cap. Grant USAGE on the functions only to roles that should spend credits. Snowflake bills its own credits for the warehouse time the functions wait for answers.
Set up inside Snowflake
- Create an API key on the API keys page with the permission Validate addresses and a daily credit cap.
- In Snowsight, open Projects → Workspaces and create a SQL file (+ → SQL File). Put
sql/external-access.sqlin it, set it to the database and schema where the functions should live, and run it statement by statement. Workspaces runs in your browser: copy the script from the box below, with no download or unzipping. It needsCREATE INTEGRATIONon the account (ACCOUNTADMINhas it) andCREATE NETWORK RULE,CREATE SECRETandCREATE FUNCTIONon the schema. - The
CREATE SECRETstatement is the only one that holds the key: run it on its own, typing the key in place of the placeholder, and do not save it in a shared workspace. Snowflake's documentation does not say whether that statement's text is hidden in query history, so treat its history entry as holding the key. - For EU data residency, set the network rule to
api-eu.email-validation.organdEV_REGION = "eu"in both copies of the code in the script before you run it.
The functions check each distinct address of a batch once, a few at a time, and stop starting checks well before Snowflake's time limit for a Python function; rows left over come back with the error "not_sent".
The script
Or open external-access.sql as plain text in a new tab, select all of it and copy it from there.
Set up the external function on AWS
Follow Snowflake's guide "Creating an external function for AWS" for the console steps, with these values:
Secret. In AWS Secrets Manager, a secret holding the API key (the plain key, or JSON
{"api_key": "..."}).Lambda. Node.js 22.x or later. Zip the two handler files at the zip's top level, not in a folder:
cd email-validation-snowflake/handler && zip ../ev-snowflake-lambda.zip aws-lambda.mjs core.mjsUpload that zip, set the handler to
aws-lambda.handlerand the timeout to 30 seconds, add the "AWS Parameters and Secrets Lambda Extension" layer, allow the function's rolesecretsmanager:GetSecretValueon the secret, and setEV_API_KEY_SECRET_IDto the secret's name. Set reserved concurrency to cap how many batches run at once.API Gateway. A REST API with a regional endpoint, a resource
/validatewith methodPOST, Lambda proxy integration andAWS_IAMauthorization, deployed to a stage. Leave execution logging of full request and response data off: it would keep the addresses.API integration. Run
sql/1-api-integration-aws.sqlwith your IAM role's ARN and the stage URL, then put theAPI_AWS_IAM_USER_ARNandAPI_AWS_EXTERNAL_IDthatDESCRIBE INTEGRATIONshows into the role's trust policy.Functions. Run
sql/2-external-functions.sqlwith the stage URL. Its last statement is a free test on test addresses.
Optional Lambda settings: EV_REGION (eu for our EU host), EV_CONCURRENCY (checks in flight per batch, default 10), EV_CHECK_TIMEOUT_S (default 10) and EV_BATCH_TIME_LIMIT_MS (default 25000: the handler answers by then, before API Gateway gives up on the Lambda; a timeout there would make Snowflake send the batch again and charge its checked rows again).
Our API allows 20 validation requests a second and 100 in flight until your account has made a purchase, and 500 a second after one. Snowflake sends several batches at once, so cap the Lambda's reserved concurrency times EV_CONCURRENCY under yours. When our API asks to slow down before anything in a batch was charged, the handler answers Snowflake 429, and Snowflake sends the batch again more slowly.
Check each address once
sql/3-check-once.sql works with either path. Each run checks only the distinct addresses that have no status yet in the table EV_EMAIL_RESULTS, at most 10,000 per run (the LIMIT caps what one run spends), and keeps the results. Run it when new addresses arrive, and read the results with a join that costs nothing:
SELECT c.*, r.status AS ev_status, r.reason AS ev_reason, r.action AS ev_action
FROM customers c
LEFT JOIN ev_email_results r ON r.email = c.email;Start with a small LIMIT and raise it once a run succeeds: a run writes its checks in one statement, so a run that fails keeps nothing of what it checked.
Try it free
SELECT validate_email('no_mailbox@sandbox.email-validation.org'); -- invalid
SELECT validate_email('disposable@sandbox.email-validation.org'); -- disposableWhat the functions return
validate_email(email) returns one of the five statuses, or NULL for a NULL or empty address and for a row that could not be checked. validate_email_details(email) returns an object with the same keys on every row ({status, reason, action, did_you_mean, domain, free_email, role_account, disposable, catch_all_domain, mx_found, processed_at, credits_used, request_id, error, error_detail}). Statuses and reasons explains each value.
When a row is not checked
A row that could not be checked never gets an invented status: its status is NULL and error says why.
error | Meaning | Charged |
|---|---|---|
rate_limited, abuse_throttled | The account's request rate limit | No |
service_unavailable, upstream_capacity | A short outage on our side | No |
insufficient_credits, key_daily_cap | No credits left, or the key's daily credit cap reached | No |
invalid_request, internal_error | The API refused or failed this one address | No |
"no_answer" | Sent, but no answer arrived in time | Maybe |
unexpected_response | An answer that is neither a result nor our error | Maybe |
"not_sent" | Not sent: the batch stopped after one of the codes above, or ran out of time | No |
After a rate limit, an outage, the daily cap or no credits, no further address of that batch is sent. The check-once script checks rows without a status again on its next run, except "no_answer" and unexpected_response rows, which may have been charged (one commented line in the script includes them). A key that is wrong, or lacks Validate addresses, fails the whole query with a message that names the error and request id, never the key.
Privacy
The functions send each address only in the body of a POST to https://api.email-validation.org (or https://api-eu.email-validation.org), with the key in the Authorization header, never to another host, and follow no redirect. They never log an address or the key: the Lambda writes one line per batch with counts, error codes and request ids, and the Python functions write nothing. What keeps addresses is under your control: Snowflake's query history (any address written into the SQL), its cached query results, EV_EMAIL_RESULTS, and API Gateway logs of full requests if you turn them on.
Licence
The download is under the MIT licence (LICENSE in the zip): you may use, change and share it.