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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(lasso): Upgrade to Lasso API v3 and fix ULID generation (#15941)
oroxenberga75e75ae1a8a
diff --git a/docs/my-website/docs/proxy/guardrails/lasso_security.md b/docs/my-website/docs/proxy/guardrails/lasso_security.mdindex b16749af54a..21528790afe 100644--- a/docs/my-website/docs/proxy/guardrails/lasso_security.md+++ b/docs/my-website/docs/proxy/guardrails/lasso_security.md@@ -6,6 +6,16 @@ import TabItem from '@theme/TabItem';Use [Lasso Security](https://www.lasso.security/) to protect your LLM applications from prompt injection attacks, harmful content generation, and other security threats through comprehensive input and output validation.+## Prerequisites++The Lasso guardrail requires the `ulid-py` package (version 1.1.0 or higher) for generating unique conversation identifiers:++```shell+pip install ulid-py>=1.1.0+```++This package is used to create lexicographically sortable identifiers for tracking conversations and sessions in the Lasso Security platform.+## Quick Start### 1. Define Guardrails on your LiteLLM config.yaml@@ -25,7 +35,7 @@ guardrails:guardrail: lassomode: "pre_call"api_key: os.environ/LASSO_API_KEY- api_base: "https://server.lasso.security/gateway/v3/classify" # Optional: defaults to v3 endpoint+ api_base: "https://server.lasso.security"- guardrail_name: "lasso-post-guard"litellm_params:guardrail: lassodiff --git a/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py b/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.pyindex d0f07520374..99d2b82400f 100644--- a/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py+++ b/litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py@@ -10,10 +10,11 @@ import uuidfrom typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Type, Union, TypedDicttry:- from ulid import ULID+ import ulidULID_AVAILABLE = Trueexcept ImportError:+ ulid = None # type: ignoreULID_AVAILABLE = Falsetry:@@ -114,8 +115,8 @@ class LassoGuardrail(CustomGuardrail):Generate a ULID (Universally Unique Lexicographically Sortable Identifier).Falls back to UUID if ULID library is not available."""- if ULID_AVAILABLE:- return str(ULID()) # type: ignore+ if ULID_AVAILABLE and ulid is not None:+ return str(ulid.new()) # type: ignoreelse:verbose_proxy_logger.debug("ULID library not available, using UUID")return str(uuid.uuid4())@@ -222,7 +223,7 @@ class LassoGuardrail(CustomGuardrail):if self.mask:headers = self._prepare_headers(response_data)payload = self._prepare_payload(response_messages, "COMPLETION", response_data)- api_url = f"{self.api_base}/gateway/v1/classifix"+ api_url = f"{self.api_base}/gateway/v3/classifix"try:lasso_response = await self._call_lasso_api(headers=headers, payload=payload, api_url=api_url)@@ -370,7 +371,7 @@ class LassoGuardrail(CustomGuardrail):try:headers = self._prepare_headers(data, cache)payload = self._prepare_payload(messages, message_type, data, cache)- api_url = f"{self.api_base}/gateway/v1/classifix"+ api_url = f"{self.api_base}/gateway/v3/classifix"response = await self._call_lasso_api(headers=headers, payload=payload, api_url=api_url)self._process_lasso_response(response)@@ -513,7 +514,7 @@ class LassoGuardrail(CustomGuardrail):api_url: Optional[str] = None,) -> LassoResponse:"""Call the Lasso API and return the response."""- url = api_url or f"{self.api_base}/gateway/v2/classify"+ url = api_url or f"{self.api_base}/gateway/v3/classify"verbose_proxy_logger.debug(f"Calling Lasso API with messageType: {payload.get('messageType')}")response = await self.async_handler.post(url=url,