Skip to main content

Module response

Module response 

Source
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

ProviderField(s) scanned
OpenAI /v1/chat/completionschoices[].message.content (string)
Anthropic /v1/messagescontent[] blocks where type == "text", field text
OpenAI /v1/responsesoutput[] 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§

ResponseRedactionSummary
Summary of redactions applied to a response body, for the audit log.

Functions§

is_redactable_response
Returns true if content_type and is_streaming indicate a response body that redact_response_body can 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.