From 2d730900906733e60e5cbf6a9aa5c260aed3b1c5 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Mon, 23 Feb 2026 20:31:51 -0800 Subject: [PATCH] fix(realtime): speak exact content filter error message via TTS Extract the human-readable error string from HTTPException.detail so the spoken warning says e.g. "Content blocked: keyword 'system update' detected" instead of the raw str(e) repr. --- litellm/litellm_core_utils/realtime_streaming.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/litellm/litellm_core_utils/realtime_streaming.py b/litellm/litellm_core_utils/realtime_streaming.py index 2d013f3bbb9..c0c699dcfdc 100644 --- a/litellm/litellm_core_utils/realtime_streaming.py +++ b/litellm/litellm_core_utils/realtime_streaming.py @@ -147,11 +147,17 @@ class RealTimeStreaming: session_id=item_id, ) except Exception as e: - safe_msg = ( - str(e) - if str(e) - else "I'm sorry, that request was blocked by the content filter." - ) + # Extract the human-readable error from HTTPException detail dict, + # falling back to str(e) for other exception types. + try: + detail = e.detail # type: ignore[attr-defined] + safe_msg = ( + detail.get("error") + if isinstance(detail, dict) + else str(detail) + ) or "I'm sorry, that request was blocked by the content filter." + except AttributeError: + safe_msg = str(e) or "I'm sorry, that request was blocked by the content filter." # Ask OpenAI to speak the warning — TTS audio plays naturally in the client await self.backend_ws.send( json.dumps(