BerriAI/litellm · error · LassoGuardrailAPIError
API error: {error.response.status_code}
Error message
API error: {error.response.status_code} What it means
Catch-all LassoGuardrailAPIError for any Lasso API HTTP error other than 401 and 429 — httpx raised HTTPStatusError and the status code fell through the specific branches. The message embeds the raw status code (e.g. 'API error: 503'), which is the key diagnostic.
Source
Thrown at litellm/proxy/guardrails/guardrail_hooks/lasso/lasso.py:618
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")
verbose_proxy_logger.debug(
"Lasso masking applied",
extra={
"guardrail_name": getattr(self, "guardrail_name", "unknown"),
"message_type": message_type,
"violations_count": len(response.get("findings", {})),
"masked_fields": len(response.get("messages", [])),View on GitHub (pinned to 77b7c6c40c)
Solutions
- Read the status code from the message and the Lasso response details in the preceding log line, then act on that specific status.
- For 5xx, check the Lasso status page and retry later — these are server-side and transient in most cases.
- For 403/404, verify the guardrail's api_base/endpoint configuration and that your key's plan permits the API being called.
- For 400/413, reduce or reshape the payload, and upgrade litellm if the request schema changed between versions.
Defensive patterns
Strategy: try-catch
Type guard
from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import LassoGuardrailAPIError
import re
def lasso_status_code(err: Exception) -> int | None:
"""Extract the HTTP status embedded in 'API error: <code>' messages."""
if isinstance(err, LassoGuardrailAPIError):
m = re.search(r"API error: (\d{3})", str(err))
if m:
return int(m.group(1))
return None Try / catch
from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import LassoGuardrailAPIError
try:
result = await guardrail_hook(data)
except LassoGuardrailAPIError as e:
code = lasso_status_code(e)
if code and 500 <= code < 600:
# Lasso-side incident: circuit-break, then degrade per your policy
trip_lasso_circuit_breaker(cooldown_s=60)
raise
raise # 4xx (other than 401/429) = config/payload problem — fix, don't retry Prevention
- Pin your litellm version and check Lasso release notes before upgrading — request-shape mismatches surface as 400/404.
- Verify the guardrail's api_base matches the Lasso endpoint your key/workspace uses.
- Cap prompt sizes sent to the guardrail to avoid 413s.
- Treat repeated 5xx as an incident: alert, don't retry-loop.
When it happens
Trigger: The guardrail's call to the Lasso API returns an error status other than 401/429: 400 for a malformed/unsupported payload, 403 for permission or plan restrictions, 404 for a wrong api_base/endpoint, 413 for oversized payloads, or 5xx during a Lasso-side incident.
Common situations: Lasso 5xx outages or maintenance windows; a litellm version change sending a request shape the deployed Lasso endpoint rejects; a customized/wrong api_base in the guardrail config; extremely large prompts tripping 413.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- error_message
- Lasso API timeout
- Invalid API key
- Lasso API rate limit exceeded
- Failed to verify request safety with Lasso API: {error}
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/e7ebaaf5eda2d239.
Report an issue: GitHub.