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.
This commit is contained in:
Ishaan Jaffer 2026-02-23 20:31:51 -08:00
parent b3b931c9a9
commit 2d73090090

View file

@ -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(