mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix(proxy): keep queued moderation running past a V1 pre_call guardrail
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
Some checks failed
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Modules / fmt, validate, test (aws) (push) Has been cancelled
Terraform Modules / fmt, validate, test (gcp) (push) Has been cancelled
A V1 CustomGuardrail with moderation_check pre_call returned out of during_call_hook before asyncio.gather, abandoning already-queued CustomLogger moderation coroutines and skipping every later callback. Skip only that guardrail instead. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
e5d02fecf7
commit
c7028761aa
2 changed files with 24 additions and 1 deletions
|
|
@ -2767,7 +2767,7 @@ class ProxyLogging:
|
|||
# V1 implementation - backwards compatibility
|
||||
if callback.event_hook is None and hasattr(callback, "moderation_check"):
|
||||
if callback.moderation_check == "pre_call":
|
||||
return
|
||||
continue
|
||||
else:
|
||||
# Main - V2 Guardrails implementation
|
||||
from litellm.types.guardrails import GuardrailEventHooks
|
||||
|
|
|
|||
|
|
@ -656,6 +656,29 @@ class _InheritsModerationOverride(_RejectsInModeration):
|
|||
pass
|
||||
|
||||
|
||||
class _V1PreCallGuardrail(CustomGuardrail):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(guardrail_name="v1-pre-call")
|
||||
self.moderation_check = "pre_call"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.filterwarnings("error::RuntimeWarning")
|
||||
async def test_during_call_hook_runs_moderation_override_after_v1_pre_call_guardrail(monkeypatch):
|
||||
moderator = _RejectsInModeration()
|
||||
monkeypatch.setattr(litellm, "callbacks", [_V1PreCallGuardrail(), moderator])
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
await ProxyLogging(user_api_key_cache=DualCache()).during_call_hook(
|
||||
data={"messages": [{"role": "user", "content": "hi"}]},
|
||||
user_api_key_dict=UserAPIKeyAuth(api_key="sk-1234"),
|
||||
call_type="acompletion",
|
||||
)
|
||||
|
||||
assert exc_info.value.status_code == 400
|
||||
assert moderator.moderated == ["acompletion"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_during_call_hook_runs_moderation_override_inherited_from_parent(monkeypatch):
|
||||
moderator = _InheritsModerationOverride()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue