-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
feat(guardrails): add Microsoft Purview DLP guardrail #24966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 45 commits into
litellm_internal_staging
from
litellm_mc_purview_guardrails
May 22, 2026
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
c51b8fd
feat(guardrails): add Microsoft Purview DLP guardrail
Sameerlite 592e418
fix(guardrails/purview): raise_for_status on HTTP errors, cap scope c…
Sameerlite 246d9f6
fix(guardrails/purview): propagate litellm_call_id as correlation_id …
Sameerlite 40e4b50
chore: fixes
yuneng-berri f09e335
refactor(guardrails): delegate get_user_prompt to get_last_user_message
cursoragent ce10c1b
fix(purview): make protection scope cache true LRU on hits
cursoragent 2525883
Fix mypy
Sameerlite d58b2f1
fix(guardrails/purview): harden user-id resolution and broaden DLP text
Sameerlite 4b759c0
fix(guardrails/purview): scan /v1/completions prompt and TextChoices
Sameerlite f20cf90
fix(purview-dlp): return data after DLP pass; per-call executor; dedu…
cursoragent 9b69e66
fix(purview): fix LRU cache refresh position and add Responses API sc…
cursoragent f2113fd
fix(purview): message separator, non-blocking logging_hook, TextChoic…
cursoragent 514f99f
fix(purview): suppress API errors in logging-only mode and scan tool-…
cursoragent c70c430
chore(ui): restructure pre-built Next.js output to directory-based ro…
cursoragent 2346ae2
fix(purview): comprehensive security hardening — identity spoofing, s…
cursoragent 85f2d04
Revert "chore(ui): restructure pre-built Next.js output to directory-…
Sameerlite c92bb00
fix(purview): fail closed on identity spoofing, token prompts, and pa…
Sameerlite 19126a5
fix(purview): use threading.Lock and getattr for LitellmParams
cursoragent 3ea81f6
refactor(purview): dedupe trust-level user resolution and drop dead code
cursoragent cc47081
fix(purview): fail-closed on responses API transform error; avoid dup…
cursoragent 212815d
fix(purview): fail-closed blocking DLP; revert directory-based UI HTML
Sameerlite 93e4f4a
Remove dead code in purview_dlp: _resolve_user_id_for_blocking never …
cursoragent 061b292
fix(purview): exclude caller-controlled end_user_id from blocking DLP
Sameerlite 30b5e82
style(purview): apply Black formatting to base.py
Sameerlite 5876b82
fix(purview): use post-await timestamp for cache TTL
cursoragent 6bfd1f0
fix(purview_dlp): fail closed when stream_chunk_builder returns None
cursoragent 9fea60d
fix(purview_dlp): resolve user_id before buffering stream
cursoragent e4870f7
merge main (#28629)
Sameerlite be1dde1
Revert "merge main (#28629)"
Sameerlite 97d7656
merge litellm_internal_staging
Sameerlite a55cb5e
refactor(purview): remove unused logging_only constructor param
mateo-berri 4769456
fix(purview): log post-call success hook via @log_guardrail_information
mateo-berri db6cade
fix(purview): raise HTTPException 400 on Responses API transform failure
mateo-berri bc14231
Fix Purview audit prompt extraction for Responses API logging hook
cursoragent 193fca0
fix(purview_dlp): check call_type for responses before messages in pr…
cursoragent c7517b7
fix(purview_dlp): don't reject empty-string prompts as token-id prompts
cursoragent 16e0eeb
fix(purview_dlp): scan ResponsesAPI streaming completed event for DLP
mateo-berri fd38a2a
fix(purview_dlp): fail closed on incomplete Responses API streams
cursoragent b269c24
fix(purview_dlp): wrap upstream DLP errors as HTTPException(400) in b…
mateo-berri 95cbf33
test(purview_dlp): cover HTTP error paths for token + Graph POST
mateo-berri 734a0cb
fix(purview): include Responses API function_call arguments in DLP scan
cursoragent b7ff50c
fix(purview_dlp): scan ResponsesAPIResponse in stream_chunk_builder f…
mateo-berri bd454cc
fix(purview_dlp): preserve upstream Graph status on `_check_content` …
mateo-berri cdd2c8f
fix(purview_dlp): reject nested token-id completion prompts
mateo-berri 87fc3bc
fix(purview): drop caller-influenceable identity fallbacks in audit r…
mateo-berri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
litellm/proxy/guardrails/guardrail_hooks/microsoft_purview/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from litellm.types.guardrails import SupportedGuardrailIntegrations | ||
|
|
||
| from .purview_dlp import MicrosoftPurviewDLPGuardrail | ||
|
|
||
| if TYPE_CHECKING: | ||
| from litellm.types.guardrails import Guardrail, LitellmParams | ||
|
|
||
|
|
||
| def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"): | ||
| import litellm | ||
|
|
||
| tenant_id = getattr(litellm_params, "tenant_id", None) | ||
| client_id = getattr(litellm_params, "client_id", None) | ||
|
|
||
| # client_secret can be passed via the standard api_key field or as | ||
| # a dedicated client_secret parameter. | ||
| client_secret = litellm_params.api_key or getattr( | ||
| litellm_params, "client_secret", None | ||
| ) | ||
|
|
||
| if not tenant_id: | ||
| raise ValueError("Microsoft Purview: tenant_id is required") | ||
| if not client_id: | ||
| raise ValueError("Microsoft Purview: client_id is required") | ||
| if not client_secret: | ||
| raise ValueError("Microsoft Purview: client_secret (or api_key) is required") | ||
|
|
||
| guardrail_name = guardrail.get("guardrail_name") | ||
| if not guardrail_name: | ||
| raise ValueError("Microsoft Purview: guardrail_name is required") | ||
|
|
||
| purview_guardrail = MicrosoftPurviewDLPGuardrail( | ||
| guardrail_name=guardrail_name, | ||
| tenant_id=str(tenant_id), | ||
| client_id=str(client_id), | ||
| client_secret=str(client_secret), | ||
| purview_app_name=str( | ||
| getattr(litellm_params, "purview_app_name", None) or "LiteLLM" | ||
| ), | ||
| user_id_field=str(getattr(litellm_params, "user_id_field", None) or "user_id"), | ||
| event_hook=litellm_params.mode, | ||
| default_on=litellm_params.default_on, | ||
| ) | ||
|
|
||
| litellm.logging_callback_manager.add_litellm_callback(purview_guardrail) | ||
| return purview_guardrail | ||
|
|
||
|
|
||
| guardrail_initializer_registry = { | ||
| SupportedGuardrailIntegrations.MICROSOFT_PURVIEW.value: initialize_guardrail, | ||
| } | ||
|
|
||
| guardrail_class_registry = { | ||
| SupportedGuardrailIntegrations.MICROSOFT_PURVIEW.value: MicrosoftPurviewDLPGuardrail, | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.