From 6788afd267fdd7d81115e9e79bb36a11d5f56350 Mon Sep 17 00:00:00 2001 From: shivam Date: Wed, 30 Sep 2026 00:44:00 +0000 Subject: [PATCH] fix(guardrails): tolerate unmodeled Responses input items in Azure prompt extraction Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/guardrails/guardrail_hooks/azure/base.py | 9 +-------- .../guardrail_hooks/azure/test_azure_prompt_shield.py | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/azure/base.py b/litellm/proxy/guardrails/guardrail_hooks/azure/base.py index 5527c6341ab..5b1474467b5 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/azure/base.py +++ b/litellm/proxy/guardrails/guardrail_hooks/azure/base.py @@ -2,8 +2,6 @@ import re from collections.abc import Mapping from typing import Any, Final, cast -from pydantic import TypeAdapter - from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.prompt_templates.common_utils import ( get_last_user_message, @@ -24,7 +22,6 @@ AZURE_CONTENT_SAFETY_TEXT_RECORD_LENGTH: Final = 1000 AZURE_CONTENT_SAFETY_DEFAULT_API_VERSION: Final = "2024-09-01" JAVELIN_API_VERSION_STORED_BY_OLDER_RELEASES: Final = "v1" -_RESPONSE_INPUT_PARAM_ADAPTER: Final = TypeAdapter(ResponseInputParam) def resolve_content_safety_api_version(configured: str | None) -> str: @@ -143,10 +140,6 @@ class AzureGuardrailBase: if not isinstance(responses_input, (str, list)): return None - validated_input: Final = ( - responses_input - if isinstance(responses_input, str) - else _RESPONSE_INPUT_PARAM_ADAPTER.validate_python(responses_input) - ) + validated_input: Final = cast(ResponseInputParam, responses_input) chat_messages: Final = ResponsesAPIRequestUtils.responses_input_to_chat_messages(validated_input) return get_last_user_message(chat_messages) diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/azure/test_azure_prompt_shield.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/azure/test_azure_prompt_shield.py index 109a1ce8b3c..46bde80fa3f 100644 --- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/azure/test_azure_prompt_shield.py +++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/azure/test_azure_prompt_shield.py @@ -373,6 +373,15 @@ def _recorded_guardrail_info(container): "Explain this", id="message-item", ), + pytest.param( + [ + {"type": "some_future_item", "payload": {"x": 1}}, + {"type": "function_call_output", "call_id": "c1", "output": "tool says hi"}, + {"role": "user", "content": "Final question"}, + ], + "Final question", + id="unmodeled-item", + ), ], ) @pytest.mark.asyncio