Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

feat add test for custom guardrails

Ishaan Jaff918e4fcfe5c3
diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml
index acb792aec99..6be2454a2cd 100644
--- a/litellm/proxy/proxy_config.yaml
+++ b/litellm/proxy/proxy_config.yaml
@@ -1,8 +1,9 @@
model_list:
- - model_name: gpt-4
+ - model_name: fake-openai-endpoint
litellm_params:
- model: openai/gpt-4o
- api_key: os.environ/OPENAI_API_KEY
+ model: openai/fake
+ api_key: fake-key
+ api_base: https://exampleopenaiendpoint-production.up.railway.app/
guardrails:
- guardrail_name: "custom-pre-guard"
diff --git a/tests/otel_tests/test_guardrails.py b/tests/otel_tests/test_guardrails.py
index 34f14186e13..2b5bfc644e1 100644
--- a/tests/otel_tests/test_guardrails.py
+++ b/tests/otel_tests/test_guardrails.py
@@ -217,3 +217,24 @@ async def test_bedrock_guardrail_triggered():
print(e)
assert "GUARDRAIL_INTERVENED" in str(e)
assert "Violated guardrail policy" in str(e)
+
+
+async def test_custom_guardrail_during_call_triggered():
+ """
+ - Tests a request where our bedrock guardrail should be triggered
+ - Assert that the guardrails applied are returned in the response headers
+ """
+ async with aiohttp.ClientSession() as session:
+ try:
+ response, headers = await chat_completion(
+ session,
+ "sk-1234",
+ model="fake-openai-endpoint",
+ messages=[{"role": "user", "content": f"Hello do you like litellm?"}],
+ guardrails=["custom-during-guard"],
+ )
+ pytest.fail("Should have thrown an exception")
+ except Exception as e:
+ print(e)
+ assert "Guardrail failed words - `litellm` detected" in str(e)