Skip to content

[Bug Fix] Presidio integration failing and making inference return 500 #10197

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions litellm/proxy/guardrails/guardrail_hooks/presidio.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,24 @@ async def async_pre_call_hook(
tasks = []

for m in messages:
if isinstance(m["content"], str):
content = m.get("content", None)
if content is None:
continue
if isinstance(content, str):
tasks.append(
self.check_pii(
text=m["content"],
text=content,
output_parse_pii=self.output_parse_pii,
presidio_config=presidio_config,
request_data=data,
)
)
responses = await asyncio.gather(*tasks)
for index, r in enumerate(responses):
if isinstance(messages[index]["content"], str):
content = messages[index].get("content", None)
if content is None:
continue
if isinstance(content, str):
messages[index][
"content"
] = r # replace content with redacted string
Expand Down Expand Up @@ -314,10 +320,11 @@ async def async_logging_hook(

for m in messages:
text_str = ""
if m["content"] is None:
content = m.get("content", None)
if content is None:
continue
if isinstance(m["content"], str):
text_str = m["content"]
if isinstance(content, str):
text_str = content
tasks.append(
self.check_pii(
text=text_str,
Expand All @@ -328,7 +335,10 @@ async def async_logging_hook(
) # need to pass separately b/c presidio has context window limits
responses = await asyncio.gather(*tasks)
for index, r in enumerate(responses):
if isinstance(messages[index]["content"], str):
content = messages[index].get("content", None)
if content is None:
continue
if isinstance(content, str):
messages[index][
"content"
] = r # replace content with redacted string
Expand Down Expand Up @@ -373,7 +383,9 @@ def get_presidio_settings_from_request_data(
self, data: dict
) -> Optional[PresidioPerRequestConfig]:
if "metadata" in data:
_metadata = data["metadata"]
_metadata = data.get("metadata", None)
if _metadata is None:
return None
_guardrail_config = _metadata.get("guardrail_config")
if _guardrail_config:
_presidio_config = PresidioPerRequestConfig(**_guardrail_config)
Expand Down
Loading