feat(pillar): add masking support for automatic content sanitization #17206
+284
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Add masking support to Pillar Security guardrail
Relevant issues
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🆕 New Feature
Changes
Summary
Adds support for automatic content masking in the Pillar Security guardrail. When
on_flagged_action: "mask"is configured, sensitive content (PII, secrets, etc.) detected by Pillar is automatically sanitized before being sent to the LLM, allowing requests to proceed safely.Key Changes
Masking Action Support
"mask"toSUPPORTED_ON_FLAGGED_ACTIONSmasked_session_messagesfrom Pillar API responseplr_mask: "true"header when masking is enabledImplementation Details
_process_pillar_response()to handle masking mode_prepare_headers()to automatically setplr_maskheader based onon_flagged_action_process_pillar_response()to return modified dataDocumentation
Tests
pillar_mask_guardrailfixturepillar_flagged_response_with_masked_messagesfixture with realistic PII masking exampleplr_maskheader being sent correctlyTesting
All new tests pass:
test_pre_call_hook_flagged_content_mask- Verifies messages are replaced with masked versionstest_pre_call_hook_mask_header_sent- Verifiesplr_mask: "true"header is senttest_pre_call_hook_mask_header_not_sent_when_monitor- Verifies header is"false"when not maskingtest_mask_with_pii_in_conversation- Tests realistic PII masking scenariotest_mask_empty_masked_messages_fallback- Tests edge case handlingUsage Example
When content is flagged, LiteLLM automatically replaces messages with masked versions from Pillar's
masked_session_messagesresponse, allowing the request to proceed with sanitized content.