Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions javelin_sdk/services/guardrails_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _handle_guardrails_response(self, response: httpx.Response) -> None:
def apply_trustsafety(
self, text: str, config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
data: Dict[str, Any] = {"text": text}
data: Dict[str, Any] = {"input": {"text": text}}
if config:
data["config"] = config
response = self.client._send_request_sync(
Expand All @@ -43,7 +43,7 @@ def apply_trustsafety(
def apply_promptinjectiondetection(
self, text: str, config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
data: Dict[str, Any] = {"text": text}
data: Dict[str, Any] = {"input": {"text": text}}
if config:
data["config"] = config
response = self.client._send_request_sync(
Expand All @@ -56,8 +56,12 @@ def apply_promptinjectiondetection(
self._handle_guardrails_response(response)
return response.json()

def apply_guardrails(self, text: str, guardrails: list) -> Dict[str, Any]:
data = {"text": text, "guardrails": guardrails}
def apply_guardrails(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better type safety and code clarity, it's recommended to use a more specific type for the guardrails parameter instead of the generic list. Based on its usage, List[Dict[str, Any]] would be more appropriate.

You'll need to add List to your imports from the typing module.

Suggested change
def apply_guardrails(
def apply_guardrails(self, text: str, guardrails: "List[Dict[str, Any]]", config: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:

self, text: str, guardrails: list, config: Optional[Dict[str, Any]] = None
) -> Dict[str, Any]:
data: Dict[str, Any] = {"input": {"text": text}, "guardrails": guardrails}
if config:
data["config"] = config
response = self.client._send_request_sync(
Request(
method=HttpMethod.POST,
Expand Down
Loading