diegosouzapw/OmniRoute · error
[PII] Blocked response due to PII detection
Error message
[PII] Blocked response due to PII detection
What it means
sanitizePII in block mode (PII_RESPONSE_SANITIZATION enabled): detections were found in the response and mode is 'block', so an error is thrown to fail the stream/response. Per Hard Rule #12 the matched pattern types are only logged server-side, never in the thrown message.
Solutions
- Review server logs for which PII pattern types were detected
- Switch PII mode from 'block' to 'warn' if blocking is too aggressive
- Redact the PII at the source (prompt or upstream provider) so responses are clean
- Confirm the PII_RESPONSE_SANITIZATION flag and mode are configured as intended
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/lib/piiSanitizer.ts:239 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/7b140e11e18219aa.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/piiSanitizer.ts:239
pattern: name,
count,
severity: patternDef?.severity || "medium",
});
}
if (detections.length > 0) {
if (mode === "warn") {
console.warn(
`[PII] Detected PII in response: ${detections.map((d) => `${d.pattern}(${d.count})`).join(", ")}`
);
} else if (mode === "block") {
// Log the matched pattern types server-side, but never put them in the
// thrown message — it can surface to the client via controller.error
// (Hard Rule #12: no internal detail in response/stream errors).
console.warn(
`[PII] Blocked response due to PII detection: ${detections.map((d) => d.pattern).join(", ")}`
);
throw new Error("[PII] Blocked response due to PII detection");
}
}
let sanitized = text;
if (mode === "redact" && ranges.length > 0) {
// Sort ranges from right to left to avoid shifting offsets
ranges.sort((a, b) => b.start - a.start);
// Merge overlapping or adjacent ranges
const mergedRanges: typeof ranges = [];
for (const r of ranges) {
if (mergedRanges.length === 0) {
mergedRanges.push(r);
} else {
const last = mergedRanges[mergedRanges.length - 1];
if (r.end >= last.start) {
last.start = Math.min(r.start, last.start);
last.end = Math.max(r.end, last.end);View on GitHub (pinned to a179ffed5b)