Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 9 min read How-to mediumAdept

pg_redact: Content-aware PII redaction with Jev, enforced in Postgres

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.

Assumes: PostgreSQL functionsJSONBregular expressions

Related posts

  • How to Handle PII in Staging Databases Without Losing Realistic Data

    Neon mediumAdept

    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). Scripts and libraries break silently when schemas add new PII columns, synthetic data loses production's skew and messiness, and replication with masking is robust but operationally heavy. The recommended approach is Neon's copy-on-write branches combined with user-defined masking rules, so a masked staging copy of production can be created or refreshed cheaply.

  • Create Environments with Masked Production Data Using Neon Branches

    Neon mediumAdept

    Neon combines copy-on-write database branches with the PostgreSQL Anonymizer (anon) extension to create production-like non-prod environments without exposing PII. The workflow branches from production, applies column-level static masking rules via SECURITY LABEL declarations and faker functions (anon.fake, anon.partial, anon.noise), runs anon.anonymize_database(), and then uses the anonymized branch as the base for per-PR previews, CI, local dev and contractor access. Masking preserves schema, types and referential integrity, and the anonymization step can be automated with a GitHub Action on pull request creation.

  • Branching With or Without PII: The Future of Environments

    Neon easyNovice

    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. Branching itself relies on separated compute and storage, WAL stored by Safekeepers with LSN markers for point-in-time branches, and copy-on-write layers in the Pageserver, with per-branch compute scaling to zero. The post argues this replaces manually maintained dev, preview, CI and staging databases. The beta uses static masking that runs once at branch creation, leaves the parent untouched, and keeps rules branch-specific.

  • How we handle sensitive data in BigQuery

    incident.io mediumAdept

    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. Non-sensitive columns are allow-listed via PR-edited YAML files, and a slim run diffs against the previous YAML version stored in GCS so only affected tables are processed. dbt is split into a customer-facing pipeline with unmasked access and an internal analytics pipeline that persists masked values downstream. Tagging once at the source cuts human error, at the cost of being unable to derive non-sensitive values such as email domains. The job also syncs a Notion data catalogue and sends Slack alerts.

  • Partial data dumps using Postgres Row Level Security

    Supabase mediumAdept

    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. Example policies filter by hardcoded IDs, email domain, recency (e.g. last two months of analytics events), or an `is_exportable` flag column. Alternatives include fully masked database copies (Snaplet) and copy-on-write database forking (Database Lab Engine on ZFS).

The quest for software engineering knowledge.

Look:
Layout: