{"record":{"id":"7b140e11e18219aa","repo":"diegosouzapw/OmniRoute","slug":"pii-blocked-response-due-to-pii-detection","errorCode":null,"errorMessage":"[PII] Blocked response due to PII detection","messagePattern":"\\[PII\\] Blocked response due to PII detection","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/piiSanitizer.ts","lineNumber":239,"sourceCode":"      pattern: name,\n      count,\n      severity: patternDef?.severity || \"medium\",\n    });\n  }\n\n  if (detections.length > 0) {\n    if (mode === \"warn\") {\n      console.warn(\n        `[PII] Detected PII in response: ${detections.map((d) => `${d.pattern}(${d.count})`).join(\", \")}`\n      );\n    } else if (mode === \"block\") {\n      // Log the matched pattern types server-side, but never put them in the\n      // thrown message — it can surface to the client via controller.error\n      // (Hard Rule #12: no internal detail in response/stream errors).\n      console.warn(\n        `[PII] Blocked response due to PII detection: ${detections.map((d) => d.pattern).join(\", \")}`\n      );\n      throw new Error(\"[PII] Blocked response due to PII detection\");\n    }\n  }\n\n  let sanitized = text;\n  if (mode === \"redact\" && ranges.length > 0) {\n    // Sort ranges from right to left to avoid shifting offsets\n    ranges.sort((a, b) => b.start - a.start);\n\n    // Merge overlapping or adjacent ranges\n    const mergedRanges: typeof ranges = [];\n    for (const r of ranges) {\n      if (mergedRanges.length === 0) {\n        mergedRanges.push(r);\n      } else {\n        const last = mergedRanges[mergedRanges.length - 1];\n        if (r.end >= last.start) {\n          last.start = Math.min(r.start, last.start);\n          last.end = Math.max(r.end, last.end);","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/piiSanitizer.ts#L221-L257","documentation":"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.","triggerScenarios":"Thrown at src/lib/piiSanitizer.ts:239 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}