---
title: "pg_redact: Content-aware PII redaction with Jev, enforced in Postgres"
description: "Column-level masking in Postgres can't redact PII buried in free text, and regex alone can't tell an SSN from an invoice number. pg_redact generates candidate spans with regex and capitalization rules, asks TypeSafe's Jev model to label each one (name, email, phone, address, id_number, none) with calibrated probabilities, and stores spans above 0.5 confidence as JSONB next to the message."
url: "https://swe.quest/articles/pg-redact-content-aware-pii-redaction-with-jev-enforced-in-postgres-4dd923bfce10e406"
canonical: "https://neon.com/blog/pg-redact-content-aware-pii-redaction-with-jev-enforced-in-postgres"
source: "Neon"
published: "2026-10-01"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["postgres","privacy","llms"]
---

# pg\_redact: Content-aware PII redaction with Jev, enforced in Postgres

A post on [Neon](https://swe.quest/sources/neon.md), published 2026-10-01, 9 min read, How-to. Original: [https://neon.com/blog/pg-redact-content-aware-pii-redaction-with-jev-enforced-in-postgres](https://neon.com/blog/pg-redact-content-aware-pii-redaction-with-jev-enforced-in-postgres)

## Summary

Column-level masking in Postgres can't redact PII buried in free text, and regex alone can't tell an SSN from an invoice number. pg\_redact generates candidate spans with regex and capitalization rules, asks TypeSafe's Jev model to label each one (name, email, phone, address, id\_number, none) with calibrated probabilities, and stores spans above 0.5 confidence as JSONB next to the message. A plpgsql redact() function compares each span's sensitivity rank against the caller's clearance, replacing longest spans first. Because labels and enforcement are decoupled, role clearances and sensitivity levels can change without reclassifying text.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Privacy](https://swe.quest/tags/privacy.md) (Security)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- PostgreSQL functions ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- JSONB
- regular expressions

## Keywords

pg\_redact, Jev, TypeSafe, Neon, PostgreSQL Anonymizer, JSONB, plpgsql

## Related posts

- [How to Handle PII in Staging Databases Without Losing Realistic Data](https://swe.quest/articles/how-to-handle-pii-in-staging-databases-without-losing-realistic-data-41c0818c53e7c05e.md): Neon · 2025-11-17 · Medium · 11 min read · Privacy, PostgreSQL, Testing, Databases
  Four common ways to get realistic but PII-safe staging data are compared, with code for each: manual CSV export plus Python anonymization scripts, Faker-based masking libraries with deterministic seeding to preserve referential integrity, fully synthetic data generators, and replication into staging with SQL masking views or the PostgreSQL Anonymizer extension (declarative security labels, dynamic masking, anonymized dumps, k-anonymity checks).
- [Create Environments with Masked Production Data Using Neon Branches](https://swe.quest/articles/create-environments-with-masked-production-data-using-neon-branches-29a6a3b3a1320ce4.md): Neon · 2025-05-15 · Medium · 7 min read · PostgreSQL, Privacy, Testing, CI/CD
  Neon combines copy-on-write database branches with the PostgreSQL Anonymizer (anon) extension to create production-like non-prod environments without exposing PII.
- [Branching With or Without PII: The Future of Environments](https://swe.quest/articles/branching-with-or-without-pii-the-future-of-environments-9928f840495df503.md): Neon · 2025-11-11 · Easy · 12 min read · PostgreSQL, Privacy, Databases, CI/CD
  Neon branches can now be created with anonymized data: schema and data are copied from a parent such as production, then masked with the PostgreSQL Anonymizer extension using per-column rules (dummy emails, names, phone numbers, random values) while foreign keys and constraints stay intact.
- [How we handle sensitive data in BigQuery](https://swe.quest/articles/how-we-handle-sensitive-data-in-bigquery-1b75e2ab86e89799.md): incident.io · 2024-11-14 · Medium · 10 min read · Privacy, Analytics & OLAP, Data pipelines, Python, Identity & auth
  incident.io masks sensitive data in BigQuery by default: a daily Python job applies PII and confidential policy tags to every untagged STRING/BYTES column replicated by Fivetran, so humans see only SHA256-hashed values.
- [Partial data dumps using Postgres Row Level Security](https://swe.quest/articles/partial-data-dumps-using-postgres-row-level-security-7b8cbab5206adee8.md): Supabase · 2022-06-28 · Medium · 4 min read · PostgreSQL, Privacy, Identity & auth, Testing
  Postgres Row Level Security can produce a seed.sql containing only safe, non-customer rows: create a restricted \`exporter\` role, attach RLS select policies that filter which rows it can see, then run \`pg\_dump --data-only --enable-row-security\` as that role.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
