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
- Query Farm hosting
- Available · $10/month organization minimum
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;
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'mask' AS mask (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-mask:0.5.0'
);
3. Run a query
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;
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'mask' AS mask
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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;
Query Farm operates Mask for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use mask as the catalog alias for the query below.
4. Run a query
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;
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'mask' AS mask (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-mask:0.5.0'
);
Overview
Reversible format-preserving encryption, deterministic tokenization, and irreversible partial redaction of sensitive values.
Mask brings production-grade data masking to DuckDB — reversible format-preserving encryption (FPE), deterministic tokenization, and irreversible redaction of sensitive values, all callable as plain SQL scalar functions over Apache Arrow. It is built for data engineers, analysts, and privacy teams who need to de-identify PII such as credit card numbers, Social Security numbers, email addresses, and account IDs directly in their queries, views, and pipelines, with no external service or pre-processing step.
Under the hood, Mask uses real, vetted, permissively-licensed cryptography — never hand-rolled ciphers. Format-preserving encryption is implemented with the NIST SP 800-38G FF1 algorithm from the fpe crate (docs), keyed with AES-256 from the RustCrypto aes crate (docs). Deterministic tokenization uses HMAC-SHA-256, and keys are derived with SHA-256, both from the RustCrypto hashing and MAC crates (hmac, sha2). FPE preserves a value's shape: a 16-digit card stays a Luhn-valid 16-digit card, an SSN stays SSN-shaped, and an email keeps its @domain — so masked data still passes format validation and flows through schemas unchanged.
Mask offers three complementary de-identification strategies, and you choose between them based on whether the original value must be recoverable later. Reversible format-preserving encryption protects a value under a secret key while keeping its shape, so authorized holders of the key can recover it and downstream format checks still pass — ideal for masked views, reversible data sharing, and generating referentially-consistent synthetic test data that mirrors production shape. Deterministic tokenization replaces an identifier with a stable, non-reversible HMAC-SHA-256 pseudonym so equal inputs always map to equal tokens and masked columns stay joinable across tables for analytics without ever exposing the real value. Irreversible redaction stars out the sensitive portion of a value for human-facing display, keeping only a small non-secret hint such as the last four digits. Mask supports GDPR- and HIPAA-driven anonymization and pseudonymization workflows; note that key management (KMS/HSM, rotation) is intentionally out of scope — the worker simply takes a key. Learn more about format-preserving encryption and the RustCrypto project that powers Mask.
Catalog
Everything mask exposes once attached — read straight from the worker's
released build.
main 4 functions
Data-masking functions: format-preserving encryption, tokenization, and redaction.
Schema 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;
| 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');
mask_fpe (value VARCHAR, format VARCHAR, key VARCHAR)
Format-preserving encrypt a value under a shape profile (card/ssn/digits/alnum/email) and key; output keeps the input shape
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;
mask_redact (value VARCHAR, mode VARCHAR)
Irreversible partial masking: mode 'last4' keeps the last four characters, 'first4' the first four, 'email' the first local char + domain, 'all' stars everything
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;
| 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;
mask_token (value VARCHAR, key VARCHAR)
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.
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;
mask_unfpe (value VARCHAR, format VARCHAR, key VARCHAR)
Inverse of mask_fpe: recover the original value under the same format profile and key
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');
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;
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.
Related workers
Indicators of compromise
Security & forensics
Pull indicators of compromise out of threat reports and defang or refang them safely
Secret scanning
Security & forensics
Find leaked API keys, tokens and private keys in text from SQL, offline and with redacted output
CVE
Security & forensics
Look up CVE records, flag known-exploited CVEs, score exploit likelihood, find open-source package advisories, and compute CVSS v3.1 scores