Expand description
Output-side PII redaction for non-streaming chat-completion responses.
guardrail-rs inspects requests with the full pipeline
(guardrail_core::Pipeline). Responses are forwarded back to the client
largely unmodified — except that, when PiiRedactor is enabled, this
module scans known assistant-message text fields in the JSON response body
and redacts any PII the model echoed back (e.g. from retrieved documents,
tool outputs, or training-data leakage) before the response reaches the
caller.
§Supported shapes
| Provider | Field(s) scanned |
|---|---|
OpenAI /v1/chat/completions | choices[].message.content (string) |
Anthropic /v1/messages | content[] blocks where type == "text", field text |
OpenAI /v1/responses | output[] message items, content[] parts where type == "output_text", field text |
§Streaming responses
This module handles complete JSON documents only.
is_redactable_response returns false for text/event-stream
bodies; those are redacted incrementally by crate::sse instead. See
“Streaming responses” in docs/architecture.md.
Structs§
- Response
Redaction Summary - Summary of redactions applied to a response body, for the audit log.
Functions§
- is_
redactable_ response - Returns
trueifcontent_typeandis_streamingindicate a response body thatredact_response_bodycan process (a single JSON document). - redact_
response_ body - Scan a non-streaming JSON response body for PII in assistant-message text fields and redact it in place.
- try_
redact_ response_ body - Like
redact_response_body, but tells a body that isn’t JSON apart from one that needed no changes.