Skip to content

Mask

Encrypt, tokenize, or redact card numbers, SSNs, emails, and other PII in query results

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/mask/index.md to help me query Mask with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

See what you can query

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT c.id, mask.main.mask_token(c.email, 'my-secret-key') AS customer_key,
  mask.main.mask_redact(c.email, 'email') AS email_display,
  mask.main.mask_redact(c.card, 'last4') AS card_display,
  mask.main.mask_fpe(c.ssn, 'ssn', 'my-secret-key') AS ssn_protected
FROM (VALUES (1, '[email protected]', '4012888888881881', '123-45-6789'), (2, '[email protected]', '5555555555554444', '987-65-4321')) AS c(id, email, card, ssn)
ORDER BY c.id;
Result
id customer_key email_display card_display ssn_protected
1 ef52da3b7b396a173a84c0da9448a8c5 a****@example.com ************1881 173-65-7533
2 36c37772c21aad26ff80f7ea5c65cd96 b**@example.org ************4444 721-01-2999

Quick start

Choose where to run Mask, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'mask' AS mask (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-mask'
);

3. Run a query

query.sql
SELECT c.id, mask.main.mask_token(c.email, 'my-secret-key') AS customer_key,
  mask.main.mask_redact(c.email, 'email') AS email_display,
  mask.main.mask_redact(c.card, 'last4') AS card_display,
  mask.main.mask_fpe(c.ssn, 'ssn', 'my-secret-key') AS ssn_protected
FROM (VALUES (1, '[email protected]', '4012888888881881', '123-45-6789'), (2, '[email protected]', '5555555555554444', '987-65-4321')) AS c(id, email, card, ssn)
ORDER BY c.id;
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'mask' AS mask (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Reversible format-preserving encryption, deterministic tokenization, and irreversible partial redaction of sensitive values.

Catalog

Everything mask exposes once attached — read straight from the worker's released build.

mask 1 schema
main 4 functions

Data-masking functions: format-preserving encryption, tokenization, and redaction.

Schema examples (7)
Examples (7)

Build a masked view of a customer table in one query: a joinable token for the email (mask_token), display-safe email and card hints (mask_redact), and a reversibly encrypted, still SSN-shaped SSN (mask_fpe).

SELECT c.id, mask.main.mask_token(c.email, 'my-secret-key') AS customer_key,
  mask.main.mask_redact(c.email, 'email') AS email_display,
  mask.main.mask_redact(c.card, 'last4') AS card_display,
  mask.main.mask_fpe(c.ssn, 'ssn', 'my-secret-key') AS ssn_protected
FROM (VALUES (1, '[email protected]', '4012888888881881', '123-45-6789'), (2, '[email protected]', '5555555555554444', '987-65-4321')) AS c(id, email, card, ssn)
ORDER BY c.id;
Result
id customer_key email_display card_display ssn_protected
1 ef52da3b7b396a173a84c0da9448a8c5 a****@example.com ************1881 173-65-7533
2 36c37772c21aad26ff80f7ea5c65cd96 b**@example.org ************4444 721-01-2999

Join an orders extract that was shared with emails replaced by tokens back to the customer table by tokenizing the customer emails with the same key, then total spend per customer showing only the redacted email (alice 200, bob 65, carol 15).

WITH customers(email, region) AS (VALUES ('[email protected]', 'EU'), ('[email protected]', 'US'), ('[email protected]', 'US')), shared_orders AS (SELECT mask.main.mask_token(o.email, 'my-secret-key') AS customer_key, o.amount FROM (VALUES ('[email protected]', 120), ('[email protected]', 40), ('[email protected]', 80), ('[email protected]', 15), ('[email protected]', 25)) AS o(email, amount)) SELECT mask.main.mask_redact(c.email, 'email') AS customer, c.region, SUM(s.amount) AS total_spend
FROM customers AS c
JOIN shared_orders AS s ON s.customer_key = mask.main.mask_token(c.email, 'my-secret-key')
GROUP BY ALL
ORDER BY total_spend DESC;

Format-preserving encrypt a column of card numbers and, in the same query, check that mask_unfpe recovers every original under the same profile and key (round_trips is true on every row).

WITH enc AS (SELECT card, mask.main.mask_fpe(card, 'card', 'my-secret-key') AS encrypted FROM (VALUES ('4012888888881881'), ('5555555555554444'), ('4111111111111111')) AS cards(card)) SELECT card, encrypted, mask.main.mask_unfpe(encrypted, 'card', 'my-secret-key') = card AS round_trips
FROM enc
ORDER BY card;

Format-preserving encrypt a credit-card number into another Luhn-valid 16-digit card.

SELECT mask.main.mask_fpe('4012888888881881', 'card', 'my-secret-key');
3 more examples

Round-trip an SSN: mask_unfpe reverses mask_fpe under the same key and profile.

SELECT mask.main.mask_unfpe(mask.main.mask_fpe('123-45-6789', 'ssn', 'k'), 'ssn', 'k');

Produce a stable, non-reversible tokenized pseudonym for an account identifier.

SELECT mask.main.mask_token('customer-42', 'my-secret-key');

Irreversibly redact a card number, keeping only the last four digits.

SELECT mask.main.mask_redact('4012888888881881', 'last4');
Scalar functions
mask_fpe (value VARCHAR, format VARCHAR, key VARCHAR) 2 examples

Format-preserving encrypt a value under a shape profile (card/ssn/digits/alnum/email) and key; output keeps the input shape

Arguments
value VARCHAR
The sensitive string to transform; its shape is preserved and NULL flows through to NULL
format VARCHAR
Shape profile selecting which characters are encryptable and what structure to keep. The machine-readable choices constraint carries the exact vocabulary.
key VARCHAR
Secret key the AES key is derived from (via SHA-256); the same key reverses mask_fpe, and an empty key is rejected
ReturnsVARCHAR
Examples (2)

Format-preserving encrypt a credit-card number; the result is a different but still Luhn-valid 16-digit card.

SELECT mask.main.mask_fpe('4012888888881881', 'card', 'my-secret-key');

Format-preserving encrypt a column of card numbers and, in the same query, check that mask_unfpe recovers every original under the same profile and key (round_trips is true on every row).

WITH enc AS (SELECT card, mask.main.mask_fpe(card, 'card', 'my-secret-key') AS encrypted FROM (VALUES ('4012888888881881'), ('5555555555554444'), ('4111111111111111')) AS cards(card)) SELECT card, encrypted, mask.main.mask_unfpe(encrypted, 'card', 'my-secret-key') = card AS round_trips
FROM enc
ORDER BY card;
Link
mask_redact (value VARCHAR, mode VARCHAR) 8 examples

Irreversible partial masking: mode 'last4' keeps the last four characters, 'first4' the first four, 'email' the first local char + domain, 'all' stars everything

Arguments
value VARCHAR
The string to partially mask for display; NULL flows through to NULL
mode VARCHAR
Redaction strategy: 'last4' keeps the final four characters, 'first4' the leading four, 'email' keeps the first local character plus the @domain, 'all' stars everything
ReturnsVARCHAR
Examples (8)

Irreversibly redact a card number, keeping only the last four digits (************1881).

SELECT mask.main.mask_redact('4012888888881881', 'last4');

Build a masked view of a customer table in one query: a joinable token for the email (mask_token), display-safe email and card hints (mask_redact), and a reversibly encrypted, still SSN-shaped SSN (mask_fpe).

SELECT c.id, mask.main.mask_token(c.email, 'my-secret-key') AS customer_key,
  mask.main.mask_redact(c.email, 'email') AS email_display,
  mask.main.mask_redact(c.card, 'last4') AS card_display,
  mask.main.mask_fpe(c.ssn, 'ssn', 'my-secret-key') AS ssn_protected
FROM (VALUES (1, '[email protected]', '4012888888881881', '123-45-6789'), (2, '[email protected]', '5555555555554444', '987-65-4321')) AS c(id, email, card, ssn)
ORDER BY c.id;
Result
id customer_key email_display card_display ssn_protected
1 ef52da3b7b396a173a84c0da9448a8c5 a****@example.com ************1881 173-65-7533
2 36c37772c21aad26ff80f7ea5c65cd96 b**@example.org ************4444 721-01-2999
SELECT mask.main.mask_redact('4012888888881881', 'last4') AS redacted;
5 more examples
SELECT mask.main.mask_redact('[email protected]', 'email') AS redacted;
SELECT mask.main.mask_fpe('4012888888881881', 'card', 'my-secret-key') AS encrypted;
SELECT mask.main.mask_unfpe(mask.main.mask_fpe('123-45-6789', 'ssn', 'k'), 'ssn', 'k') AS recovered;
SELECT mask.main.mask_token('customer-42', 'my-secret-key') AS token;
WITH customers(email, region) AS (VALUES ('[email protected]', 'EU'), ('[email protected]', 'US'), ('[email protected]', 'US')), shared_orders AS (SELECT mask.main.mask_token(o.email, 'my-secret-key') AS customer_key, o.amount FROM (VALUES ('[email protected]', 120), ('[email protected]', 40), ('[email protected]', 80), ('[email protected]', 15), ('[email protected]', 25)) AS o(email, amount)) SELECT mask.main.mask_redact(c.email, 'email') AS customer, c.region, SUM(s.amount) AS total_spend
FROM customers AS c
JOIN shared_orders AS s ON s.customer_key = mask.main.mask_token(c.email, 'my-secret-key')
GROUP BY ALL
ORDER BY total_spend DESC;
Link
mask_token (value VARCHAR, key VARCHAR) 2 examples

Deterministic pseudonym (HMAC-SHA-256) of a value under a key; same input+key yields the same token, so it is joinable across tables. Not reversible.

Arguments
value VARCHAR
The identifier to tokenize; identical inputs map to identical tokens so they stay joinable, and NULL flows through to NULL
key VARCHAR
Secret key for the HMAC-SHA-256 (domain-separated from the FPE key); the same key+value always yields the same token, and an empty key is rejected
ReturnsVARCHAR
Examples (2)

Produce a stable, non-reversible pseudonym for an account ID; the same input and key always yield the same token, so it stays joinable across tables.

SELECT mask.main.mask_token('customer-42', 'my-secret-key');

Join an orders extract that was shared with emails replaced by tokens back to the customer table by tokenizing the customer emails with the same key, then total spend per customer showing only the redacted email (alice 200, bob 65, carol 15).

WITH customers(email, region) AS (VALUES ('[email protected]', 'EU'), ('[email protected]', 'US'), ('[email protected]', 'US')), shared_orders AS (SELECT mask.main.mask_token(o.email, 'my-secret-key') AS customer_key, o.amount FROM (VALUES ('[email protected]', 120), ('[email protected]', 40), ('[email protected]', 80), ('[email protected]', 15), ('[email protected]', 25)) AS o(email, amount)) SELECT mask.main.mask_redact(c.email, 'email') AS customer, c.region, SUM(s.amount) AS total_spend
FROM customers AS c
JOIN shared_orders AS s ON s.customer_key = mask.main.mask_token(c.email, 'my-secret-key')
GROUP BY ALL
ORDER BY total_spend DESC;
Link
mask_unfpe (value VARCHAR, format VARCHAR, key VARCHAR) 1 example

Inverse of mask_fpe: recover the original value under the same format profile and key

Arguments
value VARCHAR
The sensitive string to transform; its shape is preserved and NULL flows through to NULL
format VARCHAR
Shape profile selecting which characters are encryptable and what structure to keep. The machine-readable choices constraint carries the exact vocabulary.
key VARCHAR
Secret key the AES key is derived from (via SHA-256); the same key reverses mask_fpe, and an empty key is rejected
ReturnsVARCHAR
Example

Round-trip an SSN: mask_unfpe reverses mask_fpe under the same format and key, recovering '123-45-6789'.

SELECT mask.main.mask_unfpe(mask.main.mask_fpe('123-45-6789', 'ssn', 'my-secret-key'), 'ssn', 'my-secret-key');
Link

Try these queries

Join an orders extract that was shared with emails replaced by tokens back to the customer table by tokenizing the customer emails with the same key, then total spend per customer showing only the redacted email (alice 200, bob 65, carol 15).

WITH customers(email, region) AS (VALUES ('[email protected]', 'EU'), ('[email protected]', 'US'), ('[email protected]', 'US')), shared_orders AS (SELECT mask.main.mask_token(o.email, 'my-secret-key') AS customer_key, o.amount FROM (VALUES ('[email protected]', 120), ('[email protected]', 40), ('[email protected]', 80), ('[email protected]', 15), ('[email protected]', 25)) AS o(email, amount)) SELECT mask.main.mask_redact(c.email, 'email') AS customer, c.region, SUM(s.amount) AS total_spend
FROM customers AS c
JOIN shared_orders AS s ON s.customer_key = mask.main.mask_token(c.email, 'my-secret-key')
GROUP BY ALL
ORDER BY total_spend DESC;

Uses mask_tokenmask_redact

Format-preserving encrypt a column of card numbers and, in the same query, check that mask_unfpe recovers every original under the same profile and key (round_trips is true on every row).

WITH enc AS (SELECT card, mask.main.mask_fpe(card, 'card', 'my-secret-key') AS encrypted FROM (VALUES ('4012888888881881'), ('5555555555554444'), ('4111111111111111')) AS cards(card)) SELECT card, encrypted, mask.main.mask_unfpe(encrypted, 'card', 'my-secret-key') = card AS round_trips
FROM enc
ORDER BY card;

Uses mask_fpemask_unfpe

Format-preserving encrypt a credit-card number into another Luhn-valid 16-digit card.

SELECT mask.main.mask_fpe('4012888888881881', 'card', 'my-secret-key');

Uses mask_fpe

Round-trip an SSN: mask_unfpe reverses mask_fpe under the same key and profile.

SELECT mask.main.mask_unfpe(mask.main.mask_fpe('123-45-6789', 'ssn', 'k'), 'ssn', 'k');

Uses mask_unfpemask_fpe

Produce a stable, non-reversible tokenized pseudonym for an account identifier.

SELECT mask.main.mask_token('customer-42', 'my-secret-key');

Uses mask_token

Irreversibly redact a card number, keeping only the last four digits.

SELECT mask.main.mask_redact('4012888888881881', 'last4');

Uses mask_redact

6 more examples in the Catalog, each listed under the table or function it uses.

Mask is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.