ANTIGRAVITY LABJP
Articles/Agents & Manager
Agents & Manager/2026-04-26Advanced

Antigravity × Gemma 4: Building an On-Prem PII Masking Agent — Production Design That Keeps Sensitive Data In-House

When customer data cannot leave your network, here is the on-prem PII masking pipeline I run in production using Antigravity and Gemma 4 — including the audit, key, and latency decisions that hold up under SOC2 review.

antigravity429gemma412piiprivacy5agent17

Premium Article

"I want to auto-classify customer support emails with AI, but I cannot send names and addresses to a cloud LLM." If you run a B2B SaaS, that wall probably feels familiar. I hit it personally when a contract refused OpenAI and Gemini API usage from their side, and I had to walk away from the project — for a few weeks, anyway.

Then I built a Gemma 4 pipeline running locally on top of Antigravity, and the conversation changed. This article is the production design I actually run today: a PII masking agent that never sends data outside the network. It is not a toy regex example. It survives misclassification, audit questions, and the ugly real-world edge cases that quietly break naive masking layers.

Why "Local LLM × Regex" Has to Be a Hybrid

If you try to build PII masking with regex alone, the wall arrives quickly. Extracting "Masaki Hirokawa" from "Dear Mr. Masaki Hirokawa, thank you for reaching out" via an exhaustive name dictionary is not realistic in any language with open-class names. Throw everything at an LLM instead, and you pay 200–500 ms per email. Try that against a million-emails-per-month workload and the bill or the latency will end the project.

The setup that worked for me is two-stage. Layer 1 lets regex handle the "definitely PII" structural matches — email addresses, credit card numbers, phone numbers — within deterministic bounds. Layer 2 hands the rest to Gemma 4, which catches the "you have to read the sentence to know" PII like person names, locations, and organizations. With this split I see roughly 70 ms average latency and a false-positive rate under 0.3%.

Order matters. If you put the LLM first, structured artifacts like email addresses sometimes get treated as noise and dropped. My principle: anything you can decide deterministically should be decided deterministically. Reserve the LLM for the parts where you cannot.

Architecture Overview — A Four-Layer Pipeline on Antigravity

The pipeline I run looks like this:

  • Layer 1: Regex prescreen (under 30 ms, deterministic)
  • Layer 2: Gemma 4 NER (Named Entity Recognition, ~70 ms)
  • Layer 3: Reversible / irreversible masking router (~3 ms)
  • Layer 4: Audit log appended to WORM storage

Wrapped as an Antigravity Manager Surface agent, the pipeline runs each layer in sequence and returns a tuple of (masked_text, audit_json). I covered the Manager Surface job-decomposition design in the Antigravity Manager Surface guide; this article assumes that base layer is already in place.

A real architectural decision shows up at Layer 2: 7B vs 27B. I landed on 7B with a LoRA fine-tune. The 27B was sharper out of the box, but inference cost was roughly 4× and the production economics did not hold up. More importantly, 7B was easier to control for the specific Japanese and bilingual edge cases I describe below. Whether 7B is right for you depends on your domain — measure it against representative samples before committing.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Indie developers who had to abandon AI features because customer data could not be sent to cloud LLMs can now stand up a production-grade masking pipeline that runs entirely on-prem
You will learn the concrete confidence thresholds and fallback strategies that keep both false positives and missed PII below the line — by combining regex and LLM in the right order
You can wire audit logging, reversible tokenization, and access control into your own product so SOC2 and GDPR questions stop being a blocker
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Agents & Manager2026-04-14
Antigravity × AgentKit 2.0 × Gemma 4: Cut API Costs by 80% with a Local Multi-Agent System in Production
A complete implementation guide to combining AgentKit 2.0 with locally-run Gemma 4, cutting cloud API costs by 80% while maintaining production-grade quality. Covers hybrid LLM routing, fault tolerance, and cost monitoring.
Agents & Manager2026-04-13
Building a Coding Agent System with Gemma 4 × Antigravity — A Complete Implementation Guide for Code Review, Test Generation, and Refactoring
A hands-on guide to building a 3-agent collaborative system using Gemma 4 and Antigravity AgentKit 2.0, covering code review, automated test generation, and refactoring suggestions. Includes production-quality code and pitfall solutions.
Agents & Manager2026-04-11
Antigravity × Gemma 4 Multi-Agent Workflow: Building Local LLM-Powered AI Systems
Learn how to combine Antigravity IDE with Gemma 4 to build multi-agent systems that run entirely on your local machine. From setup to a practical CI/CD pipeline, this guide has you covered.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →