BerriAI/litellm · error · LassoGuardrailAPIError

Lasso API timeout

Error message

Lasso API timeout

What it means

Raised as LassoGuardrailAPIError by LassoGuardrail._handle_api_error when the outbound httpx call to the Lasso Security API raises a httpx.TimeoutException. It means the guardrail could not verify or mask the request within the HTTP client timeout, so the proxied call fails instead of letting unverified content through. The original error was already logged with guardrail_name, message_type, and error_type before this re-raise.

Source

Thrown at litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py:611

        """Handle API errors with specific error types."""
        if isinstance(error, HTTPException):
            raise error

        # Log error with context
        verbose_proxy_logger.error(
            "Error calling Lasso API: %s",
            error,
            extra={
                "guardrail_name": getattr(self, "guardrail_name", "unknown"),
                "message_type": message_type,
                "error_type": type(error).__name__,
            },
        )

        # Handle specific error types if httpx is available
        if HTTPX_AVAILABLE:
            if isinstance(error, httpx.TimeoutException):
                raise LassoGuardrailAPIError("Lasso API timeout")
            elif isinstance(error, httpx.HTTPStatusError):
                if error.response.status_code == 401:
                    raise LassoGuardrailMissingSecrets("Invalid API key")
                elif error.response.status_code == 429:
                    raise LassoGuardrailAPIError("Lasso API rate limit exceeded")
                else:
                    raise LassoGuardrailAPIError(f"API error: {error.response.status_code}")

        # Generic error handling
        raise LassoGuardrailAPIError(f"Failed to verify request safety with Lasso API: {error}")

    def _log_masking_applied(
        self,
        message_type: Literal["PROMPT", "COMPLETION"],
        response: dict[str, Any],
    ) -> None:
        """Log masking application with structured context."""
        conversation_id: Final = getattr(self, "conversation_id", "unknown")

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Retry the request with exponential backoff — transient Lasso latency is the most common cause of a timeout.
  2. Increase the httpx timeout used by the Lasso guardrail's client (e.g. httpx.Timeout(connect=5, read=30, write=10, pool=5)) so Lasso has time to scan large payloads.
  3. Verify egress from the proxy host/container to the Lasso API endpoint (e.g. curl -m 30 against the lasso api_base) and fix firewall, DNS, or proxy issues.
  4. Reduce prompt size or traffic bursts through the guardrail; if timeouts persist across all requests, check Lasso status pages and your organization's quota.

Example fix

# before
client = httpx.AsyncClient()  # default ~5s timeout; Lasso scan of a big prompt times out

# after
client = httpx.AsyncClient(
    timeout=httpx.Timeout(connect=5.0, read=30.0, write=10.0, pool=5.0)
)
Defensive patterns

Strategy: retry

Validate before calling

# Preflight: verify the Lasso endpoint answers within budget before serving traffic
import httpx, os

def lasso_reachable(timeout: float = 10.0) -> bool:
    base = os.environ.get("LASSO_API_BASE", "https://api.lasso.security")
    try:
        r = httpx.get(f"{base}/health", timeout=timeout)  # any lightweight route
        return r.status_code < 500
    except httpx.TimeoutException:
        return False
    except httpx.HTTPError:
        return False

Try / catch

from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import LassoGuardrailAPIError

try:
    result = await guardrail_hook(data)
except LassoGuardrailAPIError as e:
    if "timeout" in str(e).lower():
        # transient: back off and retry once or twice, then fail
        await asyncio.sleep(2)
        result = await guardrail_hook(data)
    else:
        raise

Prevention

When it happens

Trigger: Any Lasso guardrail hook (pre_call, during_call, post_call) POSTs the prompt/completion to the Lasso API; the connect/read/write/pool phase exceeds the httpx client timeout, httpx raises TimeoutException, and _handle_api_error converts it to LassoGuardrailAPIError('Lasso API timeout').

Common situations: Large prompts that take Lasso longer to scan than the configured timeout; network latency or an egress firewall between the proxy host and the Lasso endpoint; a Lasso-side slowdown or partial outage; deployments running with the default httpx timeout under high load.

Understand the failure class

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/bd226af635168be9. Report an issue: GitHub.