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]

Update test_bedrock_guardrails.py

=a3f0a3c05f0f
diff --git a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py
index efe32411c10..d5e624df52c 100644
--- a/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py
+++ b/tests/test_litellm/proxy/guardrails/guardrail_hooks/test_bedrock_guardrails.py
@@ -1050,143 +1050,6 @@ async def test_bedrock_guardrail_parameter_takes_precedence_over_env(monkeypatch
print(f"Parameter precedence test passed. URL: {prepped_request.url}")
-
-async def test_bedrock_guardrail_respects_custom_runtime_endpoint(monkeypatch):
- """Test that BedrockGuardrail respects aws_bedrock_runtime_endpoint when set"""
-
- # Clear any existing environment variable to ensure clean test
- monkeypatch.delenv("AWS_BEDROCK_RUNTIME_ENDPOINT", raising=False)
-
- # Create guardrail with custom runtime endpoint
- custom_endpoint = "https://custom-bedrock.example.com"
- guardrail = BedrockGuardrail(
- guardrailIdentifier="test-guardrail",
- guardrailVersion="DRAFT",
- aws_bedrock_runtime_endpoint=custom_endpoint,
- )
-
- # Mock credentials
- mock_credentials = MagicMock()
- mock_credentials.access_key = "test-access-key"
- mock_credentials.secret_key = "test-secret-key"
- mock_credentials.token = None
-
- # Test data
- data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
- optional_params = {}
- aws_region_name = "us-east-1"
-
- # Mock the _load_credentials method to avoid actual AWS credential loading
- with patch.object(
- guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
- ):
- # Call _prepare_request which internally calls get_runtime_endpoint
- prepped_request = guardrail._prepare_request(
- credentials=mock_credentials,
- data=data,
- optional_params=optional_params,
- aws_region_name=aws_region_name,
- )
-
- # Verify that the custom endpoint is used in the URL
- expected_url = f"{custom_endpoint}/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
- assert (
- prepped_request.url == expected_url
- ), f"Expected URL to contain custom endpoint. Got: {prepped_request.url}"
-
- print(f"Custom runtime endpoint test passed. URL: {prepped_request.url}")
-
-
-async def test_bedrock_guardrail_respects_env_runtime_endpoint(monkeypatch):
- """Test that BedrockGuardrail respects AWS_BEDROCK_RUNTIME_ENDPOINT environment variable"""
-
- custom_endpoint = "https://env-bedrock.example.com"
-
- # Set the environment variable
- monkeypatch.setenv("AWS_BEDROCK_RUNTIME_ENDPOINT", custom_endpoint)
-
- # Create guardrail without explicit aws_bedrock_runtime_endpoint
- guardrail = BedrockGuardrail(
- guardrailIdentifier="test-guardrail", guardrailVersion="DRAFT"
- )
-
- # Mock credentials
- mock_credentials = MagicMock()
- mock_credentials.access_key = "test-access-key"
- mock_credentials.secret_key = "test-secret-key"
- mock_credentials.token = None
-
- # Test data
- data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
- optional_params = {}
- aws_region_name = "us-east-1"
-
- # Mock the _load_credentials method
- with patch.object(
- guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
- ):
- # Call _prepare_request which internally calls get_runtime_endpoint
- prepped_request = guardrail._prepare_request(
- credentials=mock_credentials,
- data=data,
- optional_params=optional_params,
- aws_region_name=aws_region_name,
- )
-
- # Verify that the custom endpoint from environment is used in the URL
- expected_url = f"{custom_endpoint}/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
- assert (
- prepped_request.url == expected_url
- ), f"Expected URL to contain env endpoint. Got: {prepped_request.url}"
-
- print(f"Environment runtime endpoint test passed. URL: {prepped_request.url}")
-
-
-async def test_bedrock_guardrail_uses_default_endpoint_when_no_custom_set(monkeypatch):
- """Test that BedrockGuardrail uses default endpoint when no custom endpoint is set"""
-
- # Ensure no environment variable is set
- monkeypatch.delenv("AWS_BEDROCK_RUNTIME_ENDPOINT", raising=False)
-
- # Create guardrail without any custom endpoint
- guardrail = BedrockGuardrail(
- guardrailIdentifier="test-guardrail", guardrailVersion="DRAFT"
- )
-
- # Mock credentials
- mock_credentials = MagicMock()
- mock_credentials.access_key = "test-access-key"
- mock_credentials.secret_key = "test-secret-key"
- mock_credentials.token = None
-
- # Test data
- data = {"source": "INPUT", "content": [{"text": {"text": "test content"}}]}
- optional_params = {}
- aws_region_name = "us-west-2"
-
- # Mock the _load_credentials method
- with patch.object(
- guardrail, "_load_credentials", return_value=(mock_credentials, aws_region_name)
- ):
- # Call _prepare_request which internally calls get_runtime_endpoint
- prepped_request = guardrail._prepare_request(
- credentials=mock_credentials,
- data=data,
- optional_params=optional_params,
- aws_region_name=aws_region_name,
- )
-
- # Verify that the default endpoint is used
- expected_url = f"https://bedrock-runtime.{aws_region_name}.amazonaws.com/guardrail/{guardrail.guardrailIdentifier}/version/{guardrail.guardrailVersion}/apply"
- assert (
- prepped_request.url == expected_url
- ), f"Expected default URL. Got: {prepped_request.url}"
-
- print(f"Default endpoint test passed. URL: {prepped_request.url}")
-
@pytest.mark.asyncio
async def test_bedrock_guardrail_200_with_exception_in_output_raises_and_logs_failure():
"""