Skip to content

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
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
Result
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.

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 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'
);

3. Run a query

query.sql
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
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 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'
);

Overview

PII detection + redaction for SQL, powered by Microsoft Presidio

Catalog

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

pii 1 schema
main 1 table · 6 functions

Detect, list, redact, and anonymize PII entities in free text

Schema examples (9)
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;
Result
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;
Tables
entity_types 3 examples1 col

Every PII entity type the analyzer can recognise (default English), one per row.

Columns
entity_typenot null VARCHAR
A PII entity type the analyzer can detect, e.g. PERSON, EMAIL_ADDRESS.
ConstraintsPRIMARY KEY (entity_type)
Examples (3)

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;
Link
Scalar functions
anonymize (text VARCHAR, language VARCHAR) +1 overload 2 examples

Replace each PII entity's characters with a '*' mask (language 'en')

Arguments
text VARCHAR
Text to anonymize.
language VARCHAR
ISO language code, e.g. 'en'.
Overloads
anonymize(text VARCHAR) → VARCHARanonymize(text VARCHAR, language VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (2)

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');
Link
has_pii (text VARCHAR, language VARCHAR) +1 overload 2 examples

True if any PII entity is detected in text (language defaults to 'en')

Arguments
text VARCHAR
Text to scan for PII.
language VARCHAR
ISO language code, e.g. 'en'.
Overloads
has_pii(text VARCHAR) → BOOLEANhas_pii(text VARCHAR, language VARCHAR) → BOOLEAN
ReturnsBOOLEAN
Examples (2)

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');
Link
pii_types (text VARCHAR, language VARCHAR) +1 overload 3 examples

Distinct PII entity types present in text, as a sorted VARCHAR[] (language 'en')

Arguments
text VARCHAR
Text to scan for PII types.
language VARCHAR
ISO language code, e.g. 'en'.
Overloads
pii_types(text VARCHAR) → VARCHAR[]pii_types(text VARCHAR, language VARCHAR) → VARCHAR[]
ReturnsVARCHAR[]
Examples (3)

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;
Link
redact (text VARCHAR, language VARCHAR) +1 overload 3 examples

Replace each PII entity with its type tag, e.g. '' (language 'en')

Arguments
text VARCHAR
Text to redact.
language VARCHAR
ISO language code, e.g. 'en'.
Overloads
redact(text VARCHAR) → VARCHARredact(text VARCHAR, language VARCHAR) → VARCHAR
ReturnsVARCHAR
Examples (3)

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;
Result
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"]
Link
Table functions
detect_pii (text VARCHAR, language := VARCHAR, score_threshold := DOUBLE) 10 examples

One row per detected PII entity (entity_type, text, start, end_pos, score)

Positional arguments
text VARCHAR
Text to scan for PII.
Named arguments
language := VARCHAR
ISO language code (e.g. 'en'). · default "en"
score_threshold := DOUBLE
Minimum detection confidence in [0, 1] (default 0.5). · default 0.5
Returns columns
entity_type VARCHAR
Detected PII entity type, e.g. PERSON, EMAIL_ADDRESS.
text VARCHAR
The matched substring from the input text.
start INTEGER
Start character offset of the match (inclusive).
end_pos INTEGER
End character offset of the match (exclusive).
score DOUBLE
Detection confidence in the range [0, 1].
Examples (10)

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;
Result
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"]
Link
supported_entities (language := VARCHAR) 2 examples

Every PII entity type the analyzer can detect (PERSON, EMAIL_ADDRESS, ...)

Named arguments
language := VARCHAR
ISO language code (e.g. 'en'). · default "en"
Returns columns
entity_type VARCHAR
An entity type the analyzer can detect, e.g. PERSON.
Examples (2)

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();
Link

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.