# PII detection

> Detect, redact, and mask personal data in text from SQL, using Microsoft Presidio

This page includes setup, release pins, credentials, hosting and verification evidence. [JSON alternative](https://query.farm/products/orchard/api/v1/connectors/pii.json) contains the same setup facts for structured readers; choose one format.

## Runtime and release

Use DuckDB or Haybarn **2.0.1** with **VGI protocol 3.4**.
Catalog alias: `pii`. Release: [v0.5.0](https://github.com/Query-farm/vgi-pii/releases/tag/v0.5.0). Metadata generated: 2026-12-01T18:22:16+00:00.

## Choose where it runs

- On your machine: use an installation method below. No Query Farm account is required for local execution.
- Self-host: follow [the connector deployment instructions](https://github.com/Query-farm/vgi-pii) and [connection guide](https://query.farm/vgi/connect-to-a-worker/). Use your real endpoint and its authentication settings.
- Query Farm hosted: [create a deployment](https://auth.queryfarm.cloud/console/new?worker=pii). Hosting has a $10 monthly minimum per organization; usage and license fees may apply. Copy the deployment-specific ATTACH from the console.

## Service credentials and prerequisites

No service credentials are declared by this connector. Individual datasets, input files or deployments may have their own prerequisites.

Secret parameter required flags describe the upstream declaration; they do not override the service-level mode above. Keep secrets in environment variables or the deployment secret store. SQL values in angle brackets are placeholders, not automatic environment lookups. Native DuckDB and Haybarn 2.0.1 do not provide a SQL getenv() function, even when worker-supplied snippets mention it. Read environment variables in your application and pass credential values through client parameter bindings (for example, Python con.execute("CREATE SECRET stripe (TYPE stripe, api_key ?)", [os.environ["STRIPE_API_KEY"]]) after attaching the connector. Omit unused optional parameters and keep real values out of saved SQL and logs.

## Install the extension

In stock DuckDB:

```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;
```

In Haybarn:

```sql
INSTALL vgi FROM community;
LOAD vgi;
```

## Attach the connector

The local recipes below pin the catalog release for repeatability. A public demo endpoint follows its deployed release.

### uvx

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

```sql
ATTACH 'pii' AS pii (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/vgi-pii@v0.5.0 vgi-pii-worker'
);
```

### Docker

Attach the signed image

Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.

```sql
ATTACH 'pii' AS pii (
  TYPE vgi,
  LOCATION 'oci://ghcr.io/query-farm/vgi-pii:0.5.0'
);
```

## Redact personal information from support tickets

Service credentials required for this example: not declared by this example; check the connector requirements above.

```sql
WITH tickets(id, body) AS (VALUES (1, 'Hi, this is John Smith, my email is john.smith@example.com'), (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 jane@example.org')) 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
```

- [pii.main.redact — scalar_function](https://query.farm/products/orchard/connectors/pii/objects/scalar_function.bWFpbg.cmVkYWN0.md): exact declaration for this example.
- [pii.main.pii_types — scalar_function](https://query.farm/products/orchard/connectors/pii/objects/scalar_function.bWFpbg.cGlpX3R5cGVz.md): exact declaration for this example.
- [pii.main.has_pii — scalar_function](https://query.farm/products/orchard/connectors/pii/objects/scalar_function.bWFpbg.aGFzX3BpaQ.md): exact declaration for this example.

Execution evidence: **captured_result**.

```json
{
  "status": "captured_result",
  "capturedAt": "2026-12-01T06:21:29+00:00",
  "engineVersion": "2.0.1",
  "protocolVersion": "3.4.0",
  "releaseTag": "v0.5.0",
  "sample": {
    "columns": [
      "id",
      "redacted",
      "pii_found"
    ],
    "types": [
      "INTEGER",
      "VARCHAR",
      "VARCHAR[]"
    ],
    "rows": [
      [
        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\"]"
      ]
    ],
    "more": false
  }
}
```

## Connector reference

### PII Detection & Redaction in SQL

![Microsoft Presidio logo](https://raw.githubusercontent.com/microsoft/presidio/main/docs/assets/dps-icon.svg)

**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](https://microsoft.github.io/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](https://github.com/microsoft/presidio) (its analyzer and anonymizer engines) backed by a [spaCy](https://spacy.io/) named-entity-recognition pipeline using the pinned `en_core_web_sm` model from the [spaCy models](https://github.com/explosion/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.

```sql
SELECT pii.main.redact('Call John Smith at john@example.com');
-- 'Call <PERSON> at <EMAIL_ADDRESS>'
```

Learn more from the [Presidio documentation](https://microsoft.github.io/presidio/), the [Presidio source repository](https://github.com/microsoft/presidio), and the [spaCy NLP library](https://github.com/explosion/spaCy).

## Find the exact SQL object

[Browse 7 object declarations](https://query.farm/products/orchard/api/v1/connectors/pii/objects.json) or [search within this connector](https://query.farm/products/orchard/api/v1/search.json?kind=object&connector=pii&q=pii).

Follow one format of each needed object for complete argument types, defaults, named flags, return columns and examples. Existing links above can replace another search. For questions about hosting, credentials or supported operations, stop once the documentation answers the question; SQL and unrelated object lookups are unnecessary.

## Verification and interpretation

- Missing, null, or undeclared metadata means unknown; do not invent defaults, credential scope, platform support or endpoint URLs.
- Search is keyword retrieval, not proof of a capability. Read the exact object declaration before generating SQL.
- A table and a table function can have the same name. Preserve parentheses and use the matching overload and schema.
- Service credentials, external data availability and deployment authentication are separate requirements.
- Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL.

```json
{
  "generatedAt": "2026-12-01T18:22:16+00:00",
  "repository": "https://github.com/Query-farm/vgi-pii",
  "harvest": {
    "status": "ok",
    "method": "subprocess",
    "error": null,
    "vgi_version": "9773130dde"
  },
  "catalogVerification": {
    "verified": true,
    "status": "passed",
    "total": 8,
    "passed": 8,
    "failed": 0,
    "needs_credentials": 0,
    "location": "uvx --from git+https://github.com/Query-farm/vgi-pii@v0.5.0 vgi-pii-worker",
    "transport": "subprocess",
    "environment": {
      "vgi_extension_version": "9773130dde",
      "haybarn_version": "2.0.1rc3",
      "engine_version": "v2.0.1",
      "python": "3.12.4",
      "platform": "darwin_arm64",
      "protocol_version": "3.4.0"
    },
    "checked_at": "2026-12-01T06:16:30+00:00"
  },
  "interpretation": "Catalog verification records the harvest environment. It is not proof that every query or current live API call succeeds. Only an example with captured_result has a saved result for that exact SQL."
}
```
