Learning Objectives
By the end of this chapter, you will be able to:
- Use masking techniques as guard rails to meet a performance objective.
- Select guardrail techniques to protect against malicious user inputs to a Gen AI application.
- Use legal/licensing requirements for data sources to avoid legal risk.
- Recommend an alternative for problematic text mitigation in a data source feeding a GenAI application.
Executive Summary
- Masking is a governance control with a performance side effect, not the other way around: regex masking is fast and cheap, NER masking is more accurate but adds latency and GPU spend, and format-preserving tokenization adds a round-trip map that the post-processor must reverse.
- A defensible guardrail stack at the Associate level has five layers wired in this order: input scanner, system prompt isolation, retrieval sanitation, output scanner, AI Gateway policy. Each layer catches a class of attacks the next layer misses.
- Source data licensing is a Unity Catalog governance problem: every Bronze table that lands a third-party corpus carries a
licensetag, anallowed_usetag, and anattribution_requiredtag, and a CI check fails the pipeline if any tag is blank. - Problematic text inside a corpus has four mitigation paths: filter the row out, mask the offending span, replace with a synthesized equivalent, or quarantine for SME review. The choice is driven by how core the chunk is to recall and how reversible the contamination is.
Assumptions
- Reader has completed Chapters 1 through 4 and is comfortable with chains, retrievers, pyfunc models, Vector Search indexes, MCP servers, and the Mosaic AI Agent Framework.
- All code targets Unity Catalog as the governance plane; Hive Metastore paths are not considered.
- Region-specific PII rules vary by jurisdiction; this chapter teaches the Databricks primitives that enforce a policy, not the policy text of any single regulation.
