PII detection
Detect, redact, and mask personal data in text from SQL, using Microsoft Presidio
- 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/pii/index.md to help me query PII detection 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.
Redact personal information from support tickets
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY id
| id | redacted | pii_found |
|---|---|---|
| 1 | Hi, this is <PERSON>, my email is <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
| 2 | Please charge my card <CREDIT_CARD> today | ["CREDIT_CARD", "DATE_TIME"] |
| 4 | <PERSON> can be reached at <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
Quick start
Choose where to run PII detection, 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 with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'pii' AS pii (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-pii-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'pii' AS pii (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-pii:0.5.0'
);
3. Run a query
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY 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 'pii' AS pii
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY id
Query Farm operates PII detection 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 pii as the catalog alias for the query below.
4. Run a query
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY 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 with uvx
Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.
ATTACH 'pii' AS pii (
TYPE vgi,
LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-pii-worker'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'pii' AS pii (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-pii:0.5.0'
);
Overview
PII detection + redaction for SQL, powered by Microsoft Presidio
Find, redact, and anonymize personally-identifiable information (PII) in free text directly from DuckDB SQL — person names, email addresses, phone numbers, credit-card numbers, US SSNs, locations, URLs, IP addresses and more — powered by Microsoft Presidio.
This extension brings privacy scrubbing, data-loss-prevention (DLP) checks, and PII auditing to your data warehouse without exporting a single row to an external service. It is built for data engineers, privacy and security teams, and analysts who need to sanitize logs, user-generated content, support transcripts, and other text columns before sharing, training, or archiving them. Every function runs in-process over Apache Arrow, so detection happens right next to your data and PII never leaves your environment.
Detection is powered by Microsoft Presidio (its analyzer and anonymizer engines) backed by a spaCy named-entity-recognition pipeline using the pinned en_core_web_sm model from the spaCy models collection. Presidio combines this NLP model with pattern recognizers and checksum validation (for example, Luhn validation of credit-card numbers) to flag a broad catalog of entity types, each with a confidence score and character offsets you can inspect or threshold.
What you can do
Two complementary capabilities are grouped in the main schema. Detection answers whether text holds sensitive data, which categories it holds, and exactly where each value sits (with a confidence score you can threshold). Redaction rewrites the text so the sensitive values are gone -- either labelled by the kind of value that was there, or masked so even the shape is hidden. Detection powers filtering, alerting, and auditing; redaction powers safe sharing, export, and archival. Every operation accepts an optional ISO language argument (defaulting to English) and treats NULL or blank input gracefully.
SELECT pii.main.redact('Call John Smith at [email protected]');
-- 'Call <PERSON> at <EMAIL_ADDRESS>'Learn more from the Presidio documentation, the Presidio source repository, and the spaCy NLP library.
Catalog
Everything pii exposes once attached — read straight from the worker's
released build.
main 1 table · 6 functions
Detect, list, redact, and anonymize PII entities in free text
Schema examples (9)
Flag whether text contains any PII (a boolean predicate for filtering).
SELECT pii.main.has_pii('Call John Smith at [email protected]');
Replace each PII entity with a <TYPE> tag naming its kind.
SELECT pii.main.redact('Call John Smith at [email protected]');
Mask each PII entity's characters with '*'.
SELECT pii.main.anonymize('Call John Smith at [email protected]');
List the distinct PII entity types present in text.
SELECT pii.main.pii_types('Call John Smith at [email protected]');
5 more examples
Enumerate every detected PII entity with its offsets and confidence.
SELECT entity_type, text, start, end_pos, score
FROM pii.main.detect_pii('Call John Smith at [email protected]')
ORDER BY start;
Discover which entity types the analyzer can detect.
SELECT entity_type FROM pii.main.supported_entities() ORDER BY entity_type;
Scrub a ticket column: keep only tickets where has_pii fires, and show each one's tag-redacted text next to the sorted list of PII types found in it (the clean printer ticket is filtered out).
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY id;
| id | redacted | pii_found |
|---|---|---|
| 1 | Hi, this is <PERSON>, my email is <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
| 2 | Please charge my card <CREDIT_CARD> today | ["CREDIT_CARD", "DATE_TIME"] |
| 4 | <PERSON> can be reached at <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
PII prevalence report: for every entity type the analyzer recognises (the entity_types table), count how many tickets contain it according to pii_types, most common first; recognizable types never seen report 0.
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')), found AS (SELECT id, unnest(pii.main.pii_types(body)) AS entity_type FROM tickets) SELECT e.entity_type, count(DISTINCT f.id) AS tickets
FROM pii.main.entity_types AS e
LEFT JOIN found AS f USING (entity_type)
GROUP BY e.entity_type
ORDER BY tickets DESC, e.entity_type;
Tune the confidence threshold: list the entity types pii_types finds at the default 0.5 threshold that detect_pii no longer reports at score_threshold := 0.9 (here the 0.85-confidence PERSON and the 0.5-confidence URL; the 1.0 EMAIL_ADDRESS survives).
SELECT unnest(pii.main.pii_types('Hi, this is John Smith, my email is [email protected]')) AS entity_type
EXCEPT SELECT entity_type
FROM pii.main.detect_pii('Hi, this is John Smith, my email is [email protected]', score_threshold := 0.9)
ORDER BY entity_type;
entity_types
Every PII entity type the analyzer can recognise (default English), one per row.
Count how many PII entity types the analyzer recognises.
SELECT count(*) AS n FROM pii.main.entity_types;
Check whether the analyzer recognises credit-card numbers.
SELECT count(*) > 0 AS detects_cards
FROM pii.main.entity_types
WHERE entity_type = 'CREDIT_CARD';
PII prevalence report: for every entity type the analyzer recognises (the entity_types table), count how many tickets contain it according to pii_types, most common first; recognizable types never seen report 0.
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')), found AS (SELECT id, unnest(pii.main.pii_types(body)) AS entity_type FROM tickets) SELECT e.entity_type, count(DISTINCT f.id) AS tickets
FROM pii.main.entity_types AS e
LEFT JOIN found AS f USING (entity_type)
GROUP BY e.entity_type
ORDER BY tickets DESC, e.entity_type;
anonymize (text VARCHAR, language VARCHAR) +1 overload
Replace each PII entity's characters with a '*' mask (language 'en')
anonymize(text VARCHAR) → VARCHARanonymize(text VARCHAR, language VARCHAR) → VARCHAR
Mask each PII entity's characters (-> 'Call ********** at ****************').
SELECT pii.main.anonymize('Call John Smith at [email protected]');
Mask PII with an explicit ISO language.
SELECT pii.main.anonymize('Call John Smith at [email protected]', 'en');
has_pii (text VARCHAR, language VARCHAR) +1 overload
True if any PII entity is detected in text (language defaults to 'en')
has_pii(text VARCHAR) → BOOLEANhas_pii(text VARCHAR, language VARCHAR) → BOOLEAN
Detect whether text contains PII.
SELECT pii.main.has_pii('Call John Smith at [email protected]');
Detect PII with an explicit ISO language.
SELECT pii.main.has_pii('Call John Smith at [email protected]', 'en');
pii_types (text VARCHAR, language VARCHAR) +1 overload
Distinct PII entity types present in text, as a sorted VARCHAR[] (language 'en')
pii_types(text VARCHAR) → VARCHAR[]pii_types(text VARCHAR, language VARCHAR) → VARCHAR[]
List the distinct PII types in text (-> ['EMAIL_ADDRESS', 'PERSON', 'URL']).
SELECT pii.main.pii_types('Call John Smith at [email protected]');
List the distinct PII types with an explicit ISO language.
SELECT pii.main.pii_types('Call John Smith at [email protected]', 'en');
PII prevalence report: for every entity type the analyzer recognises (the entity_types table), count how many tickets contain it according to pii_types, most common first; recognizable types never seen report 0.
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')), found AS (SELECT id, unnest(pii.main.pii_types(body)) AS entity_type FROM tickets) SELECT e.entity_type, count(DISTINCT f.id) AS tickets
FROM pii.main.entity_types AS e
LEFT JOIN found AS f USING (entity_type)
GROUP BY e.entity_type
ORDER BY tickets DESC, e.entity_type;
redact (text VARCHAR, language VARCHAR) +1 overload
Replace each PII entity with its type tag, e.g. '
redact(text VARCHAR) → VARCHARredact(text VARCHAR, language VARCHAR) → VARCHAR
Tag-redact each PII entity (-> 'Call <PERSON> at <EMAIL_ADDRESS>').
SELECT pii.main.redact('Call John Smith at [email protected]');
Tag-redact PII with an explicit ISO language.
SELECT pii.main.redact('Call John Smith at [email protected]', 'en');
Scrub a ticket column: keep only tickets where has_pii fires, and show each one's tag-redacted text next to the sorted list of PII types found in it (the clean printer ticket is filtered out).
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY id;
| id | redacted | pii_found |
|---|---|---|
| 1 | Hi, this is <PERSON>, my email is <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
| 2 | Please charge my card <CREDIT_CARD> today | ["CREDIT_CARD", "DATE_TIME"] |
| 4 | <PERSON> can be reached at <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
detect_pii (text VARCHAR, language := VARCHAR, score_threshold := DOUBLE)
One row per detected PII entity (entity_type, text, start, end_pos, score)
List every PII entity found in the text, ordered by position.
SELECT entity_type, text, start, end_pos, score
FROM pii.main.detect_pii('Call John Smith at [email protected]')
ORDER BY start;
Keep only high-confidence detections via score_threshold.
SELECT entity_type, text
FROM pii.main.detect_pii('Email [email protected]', score_threshold := 0.8);
Tune the confidence threshold: list the entity types pii_types finds at the default 0.5 threshold that detect_pii no longer reports at score_threshold := 0.9 (here the 0.85-confidence PERSON and the 0.5-confidence URL; the 1.0 EMAIL_ADDRESS survives).
SELECT unnest(pii.main.pii_types('Hi, this is John Smith, my email is [email protected]')) AS entity_type
EXCEPT SELECT entity_type
FROM pii.main.detect_pii('Hi, this is John Smith, my email is [email protected]', score_threshold := 0.9)
ORDER BY entity_type;
7 more examples
SELECT pii.main.has_pii('Call John Smith at [email protected]') AS has_pii;
SELECT pii.main.redact('Call John Smith at [email protected]') AS redacted;
SELECT pii.main.anonymize('Call John Smith at [email protected]') AS masked;
SELECT pii.main.pii_types('Call John Smith at [email protected]') AS types;
SELECT entity_type, text, start, end_pos
FROM pii.main.detect_pii('Call John Smith at [email protected]')
ORDER BY start;
SELECT count(*) AS n FROM pii.main.supported_entities();
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is [email protected]'), (2, 'Please charge my card 4111-1111-1111-1111 today'), (3, 'The printer on floor 3 is jammed again'), (4, 'Jane Doe can be reached at [email protected]')) SELECT id, pii.main.redact(body) AS redacted, pii.main.pii_types(body) AS pii_found
FROM tickets
WHERE pii.main.has_pii(body)
ORDER BY id;
| id | redacted | pii_found |
|---|---|---|
| 1 | Hi, this is <PERSON>, my email is <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
| 2 | Please charge my card <CREDIT_CARD> today | ["CREDIT_CARD", "DATE_TIME"] |
| 4 | <PERSON> can be reached at <EMAIL_ADDRESS> | ["EMAIL_ADDRESS", "PERSON", "URL"] |
supported_entities (language := VARCHAR)
Every PII entity type the analyzer can detect (PERSON, EMAIL_ADDRESS, ...)
Find which detectable entity types relate to payment cards.
SELECT entity_type
FROM pii.main.supported_entities()
WHERE entity_type LIKE '%CARD%'
ORDER BY entity_type;
Count how many entity types the analyzer supports.
SELECT count(*) FROM pii.main.supported_entities();
Try these queries
Flag whether text contains any PII (a boolean predicate for filtering).
SELECT pii.main.has_pii('Call John Smith at [email protected]')
Uses has_pii
Replace each PII entity with a <TYPE> tag naming its kind.
SELECT pii.main.redact('Call John Smith at [email protected]')
Uses redact
Mask each PII entity's characters with '*'.
SELECT pii.main.anonymize('Call John Smith at [email protected]')
Uses anonymize
List the distinct PII entity types present in text.
SELECT pii.main.pii_types('Call John Smith at [email protected]')
Uses pii_types
Enumerate every detected PII entity with its offsets and confidence.
SELECT entity_type, text, start, end_pos, score
FROM pii.main.detect_pii('Call John Smith at [email protected]')
ORDER BY start
Uses detect_pii
Discover which entity types the analyzer can detect.
SELECT entity_type FROM pii.main.supported_entities() ORDER BY entity_type
Uses supported_entities
17 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- Does the text 'Contact Jane Doe at [email protected]' contain any personally-identifiable information? Return a single boolean value.
- List the distinct PII entity types present in the text 'Contact Jane Doe at [email protected]'.
- Produce a copy of the text 'Email [email protected] now' in which every PII value's characters are masked with asterisks.
- For the text 'Contact Jane Doe at [email protected]', return one row per detected PII entity showing the entity type and the matched substring.
- How many distinct PII entity types can this worker's analyzer detect?
- Does this worker's list of recognizable PII entity types include credit-card numbers (the CREDIT_CARD type)? Return a single boolean value.
PII detection 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
Anthropic
AI & language
Read-only view of your Anthropic organization's members, API keys, token usage and cost
Embed
AI & language
Turn text into embedding vectors on your own machine and rank it by cosine similarity for semantic search and RAG
Grammar
AI & language
Find, count, and auto-correct grammar, style, and spelling issues in free text using the open-source LanguageTool engine