<aside> 🎙️

Date: Friday, October 16, 2026 · Week 3, Day 19 · Type: Build Day + Live Session 6 (7:30 PM IST, 90 min)

</aside>

Learning Manual

19.1 Security Threats in Generative AI — direct prompt injections (jailbreaks), indirect prompt injections (hidden in scanned PDFs/websites).

19.2 PII Protection — detecting and masking sensitive personal data (credit card numbers, social security numbers, emails) before calling APIs.

19.3 Input/Output Guardrails — sanitizing incoming user prompts and validating that outgoing responses do not leak system instructions.

The Daily Build

Build an Input/Output Security Guardrail function that scans incoming text for common prompt injection patterns, masks PII using regex/heuristics, and checks outgoing LLM responses to ensure no sensitive system instructions are leaked.

Architecture Diagram

+-------------+     +-------------------+     +------------------+     +--------------------+
| User Input  | --> | Injection Checker | --> | PII Masker       | --> | LLM Application    |
+-------------+     +-------------------+     +------------------+     +--------------------+
                                                                                 |
                                                                                 v
                                                                       [Output Safety Check]
                                                                                 |
                                                                                 v
                                                                       [Sanitized Response]

Interview Questions

  1. What is an indirect prompt injection attack, and how could an attacker exploit an AI reading support emails?
  2. Why is client-side input validation insufficient to protect an LLM against jailbreaking attacks?
  3. How does the Dual-LLM Guardrail pattern work, and what is its impact on overall API latency?

Problem Statement

Problem 19. Write a PII sanitization function in Python mask_pii_entities(text: str) -> str using regular expressions that detects and replaces all email addresses, 16-digit credit card numbers, and US phone numbers with [REDACTED_EMAIL], [REDACTED_CARD], and [REDACTED_PHONE].

AI-DSA Primitive

Data Structure: Regex Finite State Matcher.

Mechanics: Deterministic Finite Automaton (DFA) matching character sequences against pattern state transitions in O(N) linear time.

Real-World Production Use: Core engine inside Microsoft Presidio and data masking proxies.

Software Design Pattern