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]

fix: fix error

Krrish Dholakiab0e6b8f0eeeb
diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py
index 462582b1f35..a51547898d9 100644
--- a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py
+++ b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py
@@ -22,9 +22,7 @@ from fastapi import HTTPException
import litellm
from litellm._logging import verbose_proxy_logger
from litellm.caching import DualCache
-from litellm.integrations.custom_guardrail import (
- CustomGuardrail,
-)
+from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM
from litellm.llms.custom_httpx.http_handler import (
get_async_httpx_client,
@@ -363,7 +361,7 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
prepared_request.headers,
)
- response = await self.async_handler.post(
+ httpx_response = await self.async_handler.post(
url=prepared_request.url,
data=prepared_request.body, # type: ignore
headers=prepared_request.headers, # type: ignore
@@ -373,19 +371,19 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
#########################################################
self.add_standard_logging_guardrail_information_to_request_data(
guardrail_provider=self.guardrail_provider,
- guardrail_json_response=response.json(),
+ guardrail_json_response=httpx_response.json(),
request_data=request_data or {},
guardrail_status=self._get_bedrock_guardrail_response_status(
- response=response
+ response=httpx_response
),
start_time=start_time.timestamp(),
end_time=datetime.now().timestamp(),
duration=(datetime.now() - start_time).total_seconds(),
)
#########################################################
- if response.status_code == 200:
+ if httpx_response.status_code == 200:
# check if the response was flagged
- _json_response = response.json()
+ _json_response = httpx_response.json()
redacted_response = _redact_pii_matches(_json_response)
verbose_proxy_logger.debug("Bedrock AI response : %s", redacted_response)
bedrock_guardrail_response = BedrockGuardrailResponse(**_json_response)
@@ -398,8 +396,8 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
else:
verbose_proxy_logger.error(
"Bedrock AI: error in response. Status code: %s, response: %s",
- response.status_code,
- response.text,
+ httpx_response.status_code,
+ httpx_response.text,
)
return bedrock_guardrail_response
@@ -597,11 +595,11 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
#########################################################
########## 2. Update the messages with the guardrail response ##########
#########################################################
- data[
- "messages"
- ] = self._update_messages_with_updated_bedrock_guardrail_response(
- messages=new_messages,
- bedrock_guardrail_response=bedrock_guardrail_response,
+ data["messages"] = (
+ self._update_messages_with_updated_bedrock_guardrail_response(
+ messages=new_messages,
+ bedrock_guardrail_response=bedrock_guardrail_response,
+ )
)
#########################################################
@@ -652,11 +650,11 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM):
#########################################################
########## 2. Update the messages with the guardrail response ##########
#########################################################
- data[
- "messages"
- ] = self._update_messages_with_updated_bedrock_guardrail_response(
- messages=new_messages,
- bedrock_guardrail_response=bedrock_guardrail_response,
+ data["messages"] = (
+ self._update_messages_with_updated_bedrock_guardrail_response(
+ messages=new_messages,
+ bedrock_guardrail_response=bedrock_guardrail_response,
+ )
)
#########################################################