From ab07c03556c37b429f4a6210fc6954d8253b95b8 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 22 Apr 2026 16:51:12 -0700 Subject: [PATCH] wire eval gate into async post_call_success_hook --- litellm/proxy/utils.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index f21a729f551..7f8832da005 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -2089,6 +2089,38 @@ class ProxyLogging: ) if callback_response is not None: response = callback_response + + ############ Eval Gate [Beta] ############################## + ############################################################ + try: + _agent_id = (data.get("metadata") or {}).get("agent_id") or data.get( + "agent_id" + ) + if _agent_id: + from litellm.proxy.eval_management.eval_engine import ( + run_evals_for_agent, + ) + from litellm.proxy.proxy_server import ( + prisma_client as _prisma_client, + ) + + if _prisma_client is not None: + response = await run_evals_for_agent( + agent_id=_agent_id, + response=response, + data=data, + user_api_key_dict=user_api_key_dict, + prisma_client=_prisma_client, + ) + except Exception as e: + from fastapi import HTTPException + + if isinstance(e, HTTPException): + raise + verbose_proxy_logger.warning( + f"[Evals] Unexpected error in eval gate: {e}" + ) + ############################################################ except Exception as e: raise e return response