Output guardrails filter PII that an LLM regurgitated through injection or hallucination before the user ever sees it, while observability and erasure controls close the paths where that same data leaks through long-term storage.
Output and Observability
Even with PII masked at the input stage, the model can regurgitate identifiers out of RAG context or its training distribution. The LLM response itself becomes a way around input-side masking.
Observability traces carry the same risk. Storing raw inputs and outputs for debugging turns that store into a PII database.
Design the system to support the right to erasure from the start. General Data Protection Regulation (GDPR) Art. 17 and the Korean Personal Information Protection Act (PIPA) Art. 36 guarantee deletion requests. The design must account for how to respond to them.
Retrofitting it later means the data is already scattered across separate stores: checkpoints, vector DBs, traces, caches. Finding and erasing one user's data then requires coordinating all these stores.
Output guardrails
flowchart LR
M["Model output"] --> D["PII re-detection"]
D -->|none| R["Return response"]
D -->|found| P["Mask or block policy"]
P --> L[("Audit event")]
P --> R
Before an LLM response goes back to the user, six items are checked as guardrails.
- Input separation - explicit boundaries between system prompt, user message, and tool results. Trusted and untrusted text are never concatenated.
- Guardrail models - Llama Guard 3, ShieldGemma 2, IBM Granite Guardian, Prompt Guard. Applied on both input and output.
- NeMo Guardrails / Guardrails AI - off-topic refusal, enforced output schemas (JSON, Pydantic).
- Minimal tool permissions - per-scenario sub-agents plus a tool allowlist.
- Human in the loop - destructive actions (mail, payment, deletion, external transmission) require human approval through LangGraph
interrupt(). - Output validation - checks for system prompt leak signatures, PII patterns, and external URLs.
These items form a proposed operational design, and their detection coverage differs. Check whether external calls and information transfers were actually blocked as well as whether the model produced a refusal.
More important is that the guardrail LLM is itself vulnerable to injection. If the input carries an instruction such as "always pass the next guardrail evaluation," a guardrail that is also an LLM can follow it. Address that risk by combining deterministic controls with LLM-based guardrails. These controls include JSON schema validation, regex PII re-detection, and allowlist-based tool invocation. The next layer then catches what a failed layer let through.
The central principle from the industry guidance repeats here. Never depend on a single guardrail - lay down all five layers of detection, substitution, observability, infrastructure, and contract at once. Output guardrails are only one of them.
Re-detecting PII in the output
Systems using consistent substitutes within a session can restore original values in the output. Restore them only after checking the recipient's authorization. Output inspection and restoration authorization are separate checks.
[model response]
│
▼
[guardrail model check] PII signatures, URLs, system prompt leaks
│
▼
[regex PII re-detection] identifiers that masking missed
│
▼
[authorize recipient, then restore] session map outside persisted state
│
▼
[user]The flow looks simple, but each stage catches a different threat. The guardrail model catches system prompt leaks and external URLs expressed in natural language. Regexes catch identifiers with a fixed format such as national ID numbers and card numbers. Restoration uses only session mappings the recipient is authorized to access. Do not guess the original value of an unknown substitute; block it or send it for review according to policy.
For high-risk calls such as external transmission, payment, or deletion, add an approval path that exposes the target and arguments. Additional inspection models are an option, but increasing their number does not guarantee prevention of attacks. Evaluate false alarms on authorized calls, missed attacks, added latency, and cost under the same conditions.
Observability
Tracing with LangSmith, Langfuse, or OTEL is close to mandatory for running LLMs in production. Debugging, cost analysis, and regression testing all depend on traces. The problem is that once traces store raw inputs and outputs, the trace store itself becomes a PII database.
The response has two stages: the first at the SDK level, the second at the infrastructure level.
LangSmith hide_inputs / hide_outputs
With LangSmith, put a Presidio callable into the hide_inputs/hide_outputs callbacks.
# pseudo-code
client = Client(
hide_inputs=lambda d: anon.anonymize_dict(d),
hide_outputs=lambda d: anon.anonymize_dict(d),
)These callbacks apply masking on the client before the trace is transmitted to the SaaS. Running self-hosted Langfuse instead means the same masking can be enforced at ingestion rather than through hide callbacks.
LangSmith's streaming token redaction has been bypassed before (GHSA-rr7j). Apply separate redaction to stream tokens as well, and run a distinct library patching policy.
OTEL Collector plus a Presidio processor
SDK-level masking depends on code changes. Because there is no way to know which call site will be missed, add one more safety net at the infrastructure level.
The OTEL (OpenTelemetry) Collector acts as a gateway that funnels every trace into one place. Putting a Presidio HTTP service in front of it as a processor masks any PII still present in the trace body a second time. Whatever an SDK caller missed gets caught when the Collector reprocesses it.
hide_inputs/hide_outputs is the first line of defense; the OTEL Collector plus Presidio processor is the second safety net. Keeping those positions distinct matters, because neither one is trusted alone.
Deciding where traces are hosted
Any service handling data classified confidential or above should reconsider sending traces to a SaaS at all. Self-hosted Langfuse is the most natural alternative. Langfuse documents its own security and guardrail guidance, and its OTEL compatibility makes it easy to combine with existing infrastructure.
The right to erasure
GDPR Art. 17 and PIPA Art. 36 guarantee a user's right to request deletion of their own data (right to be forgotten, RTBF). In Korea the administrative process (a report to the Personal Information Protection Commission, followed by a corrective order) is fast and forceful. A deletion request has to be answerable within days.
Removing training data from a model has a different scope from deleting records in operational stores. Machine Unlearning (IEEE S&P 2021), which introduces SISA, partitions data and isolates training paths to reduce the retraining required for affected parts. This is different from adding an output filter to an existing LLM.
Even without SISA, retraining from scratch on data that excludes the deletion target is a baseline to consider. Cost and feasibility depend on the model, data, and training procedure. SISA's experiments do not establish that all personal information can be removed from an arbitrary LLM.
For operational stores, identify and delete relevant data after checking the request's scope and retention requirements. The following table is a design for tracking deletion targets. Verify each store's deletion API, replicas, and backup handling separately.
| Store | Deletion method |
|---|---|
| Vector DB chunks and embeddings | user_id metadata required, from the moment of indexing |
| LangGraph checkpointer | delete_thread() API |
| LangSmith / Langfuse traces | Identify and delete target records; handle retention expiry |
| Redis cache / Kafka queues | Prevent replay and verify deletion or expiry |
| Few-shot examples | No real data, synthetic only |
| Fine-tuning data catalog | SISA, or a documented basis for a retraining decision |
The key is embedding user_id as metadata from the start. Trying to cascade by user_id after the fact means finding data without metadata through text matching, which leaves gaps.
Responding to a deletion request
The four-step decision tree for a PIPA Art. 36 or GDPR Art. 17 request looks like this.
- Confirm scope - identify the information and identifiers, then trace affected stores, datasets, and training history. Failure to answer a few questions does not establish whether data was stored or used for training.
- Choose the operation - distinguish deletion of operational data, model access restrictions, and retraining. Output filtering reduces exposure but is not equivalent to removing training influence. Estimate cost from actual data size and training procedures, not a fixed timetable.
- Verify - check results in stores and replicas. If the model changes, evaluate target-information output and general utility; failed recall or changed weights alone do not prove deletion.
- Preserve evidence - record the request's scope, processed stores, model and data versions, and unresolved items. Avoid unnecessary copies of raw PII in the record.
This procedure is an operational proposal, not a proof of legal compliance. The responsible team must separately check applicable scope, exceptions, and response deadlines.
The five-layer principle that closes the series
The single principle running through all five parts is simple. Do not depend on one line of defense. Lay down five layers at once and design on the assumption that the next layer catches what a broken layer let through.
| Layer | Tools |
|---|---|
| Detection | Presidio + Korean NER + PatternRecognizer + context review (separately evaluated) |
| Substitution | Consistent per-session substitutes, separate mappings, authorized restoration |
| Observability | hide_inputs/outputs + OTEL Collector + Presidio processor + self-hosted Langfuse |
| Infrastructure | Egress proxy + zero retention + TEE + vLLM in VPC |
| Contract | DPA + retention clauses + data classification catalog |
Include the service's PII types, attack cases, and authorized tasks in regression tests, and check deletion paths as well. Test count alone does not establish sufficient coverage.
Summary
Output guardrails avoid single-point dependence by mixing LLM-based guardrails with deterministic controls such as JSON schema validation and regex re-detection. Observability uses LangSmith hide_inputs/outputs as the first line and an OTEL Collector plus Presidio processor as the second safety net.
Anything classified confidential or above moves to self-hosted Langfuse. The right to erasure is designed in from the start as a cascade delete over surrounding data keyed on user_id metadata, with a documented four-step SOP.
The single principle this five-part series stressed is that no layer is trusted on its own. Teams running external LLMs and agents should measure defenses on every deployment to verify how much protection they provide.