refactor(realtime): call apply_guardrail directly, remove dedicated hook method

The async_realtime_input_transcription_hook in CustomGuardrail and
ContentFilterGuardrail was just a thin wrapper that called apply_guardrail —
the same interface used by /chat and /messages. Remove the wrapper and call
apply_guardrail directly from run_realtime_guardrails, keeping the pattern
consistent across all endpoints.
This commit is contained in:
Ishaan Jaffer 2026-02-23 20:44:03 -08:00
parent 24c8bff413
commit c9f0fa5af7
3 changed files with 4 additions and 35 deletions

View file

@ -334,21 +334,6 @@ class CustomGuardrail(CustomLogger):
return kwargs
async def async_realtime_input_transcription_hook(
self,
transcription: str,
user_api_key_dict: Optional[Any],
session_id: Optional[str] = None,
) -> None:
"""
Called when a user's voice transcription completes in a Realtime API session,
before the LLM generates a response.
Raise an exception to block the response.
Return None to allow the LLM to respond.
"""
return None
async def async_post_call_success_deployment_hook(
self,
request_data: dict,

View file

@ -155,10 +155,10 @@ class RealTimeStreaming:
):
continue
try:
await callback.async_realtime_input_transcription_hook(
transcription=transcript,
user_api_key_dict=self.user_api_key_dict,
session_id=item_id,
await callback.apply_guardrail(
inputs={"texts": [transcript], "images": []},
request_data={"user_api_key_dict": self.user_api_key_dict},
input_type="request",
)
except Exception as e:
# Extract the human-readable error from HTTPException detail dict,

View file

@ -1921,22 +1921,6 @@ class ContentFilterGuardrail(CustomGuardrail):
# We already reached the end of the generator
pass
async def async_realtime_input_transcription_hook(
self,
transcription: str,
user_api_key_dict,
session_id=None,
) -> None:
"""
Run content filter checks on a Realtime API speech transcription.
Raises ValueError if the transcription contains blocked content.
"""
await self.apply_guardrail(
inputs={"texts": [transcription], "images": []},
request_data={},
input_type="request",
)
@staticmethod
def get_config_model():
from litellm.types.proxy.guardrails.guardrail_hooks.litellm_content_filter import (