Revert "push guardrail"

This reverts commit 90024d73ed.
This commit is contained in:
Ishaan Jaffer 2026-02-17 20:56:33 -08:00
parent cdd6e6633c
commit 19bbaca4be
6 changed files with 5 additions and 60 deletions

View file

@ -439,40 +439,21 @@ class CustomGuardrail(CustomLogger):
return result
return True
# MCP event hooks map back to their base call-phase counterparts so that
# guardrails configured with event_hook="pre_call" also fire for MCP calls.
_MCP_EVENT_HOOK_FALLBACKS = {
GuardrailEventHooks.pre_mcp_call.value: GuardrailEventHooks.pre_call.value,
GuardrailEventHooks.during_mcp_call.value: GuardrailEventHooks.during_call.value,
}
def _event_hook_is_event_type(self, event_type: GuardrailEventHooks) -> bool:
"""
Returns True if the event_hook is the same as the event_type
eg. if `self.event_hook == "pre_call" and event_type == "pre_call"` -> then True
eg. if `self.event_hook == "pre_call" and event_type == "post_call"` -> then False
MCP event hooks also match their base counterparts:
eg. if `self.event_hook == "pre_call" and event_type == "pre_mcp_call"` -> then True
"""
if self.event_hook is None:
return True
et_value = event_type.value
fallback = self._MCP_EVENT_HOOK_FALLBACKS.get(et_value)
if isinstance(self.event_hook, list):
return et_value in self.event_hook or (
fallback is not None and fallback in self.event_hook
)
return event_type.value in self.event_hook
if isinstance(self.event_hook, Mode):
tag_values = self.event_hook.tags.values()
return et_value in tag_values or (
fallback is not None and fallback in tag_values
)
return self.event_hook == et_value or self.event_hook == fallback
return event_type.value in self.event_hook.tags.values()
return self.event_hook == event_type.value
def get_guardrail_dynamic_request_body_params(self, request_data: dict) -> dict:
"""

View file

@ -71,9 +71,7 @@ try:
from mcp.shared.tool_name_validation import (
validate_tool_name, # pyright: ignore[reportAssignmentType]
)
from mcp.shared.tool_name_validation import (
SEP_986_URL,
)
from mcp.shared.tool_name_validation import SEP_986_URL
except ImportError:
from pydantic import BaseModel
@ -1845,15 +1843,6 @@ class MCPServerManager:
if modified_kwargs.get("arguments") != arguments:
arguments = modified_kwargs["arguments"]
# Propagate guardrail information so MCP spend logs can record it
synth_meta = modified_data.get("metadata") or {}
gi = synth_meta.get("standard_logging_guardrail_information")
if gi:
if not hasattr(proxy_logging_obj, "_mcp_guardrail_information"):
proxy_logging_obj._mcp_guardrail_information = {}
call_key = f"{server_name}:{name}"
proxy_logging_obj._mcp_guardrail_information[call_key] = gi
except (
BlockedPiiEntityError,
GuardrailRaisedException,

View file

@ -1638,9 +1638,6 @@ if MCP_AVAILABLE:
raise
if litellm_logging_obj:
# Propagate guardrail info from pre_call_tool_check into logging metadata
from litellm.proxy.proxy_server import proxy_logging_obj as _plo
litellm_logging_obj.post_call(original_response=response)
end_time = datetime.now()
await litellm_logging_obj.async_post_mcp_tool_call_hook(
@ -1796,6 +1793,7 @@ if MCP_AVAILABLE:
host_progress_callback: Optional[Callable] = None,
) -> CallToolResult:
"""Handle tool execution for managed server tools"""
# Import here to avoid circular import
from litellm.proxy.proxy_server import proxy_logging_obj
call_tool_result = await global_mcp_server_manager.call_tool(
@ -1810,17 +1808,6 @@ if MCP_AVAILABLE:
proxy_logging_obj=proxy_logging_obj,
host_progress_callback=host_progress_callback,
)
# DEMO: propagate guardrail info from pre_call_tool_check into the
# litellm_logging_obj so it appears in spend logs.
if proxy_logging_obj and hasattr(proxy_logging_obj, "_mcp_guardrail_information"):
call_key = f"{server_name}:{name}"
gi = proxy_logging_obj._mcp_guardrail_information.pop(call_key, None)
if gi and litellm_logging_obj:
lp = litellm_logging_obj.model_call_details.setdefault("litellm_params", {})
lp_meta = lp.setdefault("metadata", {})
lp_meta["standard_logging_guardrail_information"] = gi
verbose_logger.debug("CALL TOOL RESULT: %s", call_tool_result)
return call_tool_result

View file

@ -172,8 +172,6 @@ class ContentFilterGuardrail(CustomGuardrail):
GuardrailEventHooks.pre_call,
GuardrailEventHooks.post_call,
GuardrailEventHooks.during_call,
GuardrailEventHooks.pre_mcp_call,
GuardrailEventHooks.during_mcp_call,
],
event_hook=event_hook or GuardrailEventHooks.pre_call,
default_on=default_on,

View file

@ -524,7 +524,6 @@ class ProxyLogging:
synthetic_data = {
"messages": [synthetic_message],
"model": kwargs.get("model", "mcp-tool-call"),
"metadata": {},
"user_api_key_user_id": kwargs.get("user_api_key_user_id"),
"user_api_key_team_id": kwargs.get("user_api_key_team_id"),
"user_api_key_end_user_id": kwargs.get("user_api_key_end_user_id"),

View file

@ -671,15 +671,6 @@ class LiteLLM_Proxy_MCP_Handler:
if litellm_logging_obj:
try:
# Propagate guardrail info from pre_call_tool_check into logging metadata
if proxy_logging_obj and hasattr(proxy_logging_obj, "_mcp_guardrail_information"):
call_key = f"{server_name}:{sanitized_tool_name}"
gi = proxy_logging_obj._mcp_guardrail_information.pop(call_key, None)
if gi:
lp = litellm_logging_obj.model_call_details.setdefault("litellm_params", {})
lp_meta = lp.setdefault("metadata", {})
lp_meta["standard_logging_guardrail_information"] = gi
litellm_logging_obj.post_call(original_response=result)
end_time = datetime.now()
await litellm_logging_obj.async_post_mcp_tool_call_hook(