fix(lakera-guardrail): ensure lakera_api_key is always str to fix mypy error

Appending `or ""` keeps the type as `str` (not `str | None`), fixing:
  lakera_ai.py:267: error: Unsupported operand types for + ("str" and "None")

Also prevents lakera_ai_v2.py from silently sending "Bearer None" when the
key is absent; a missing key now yields a clear 401 from the Lakera API.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Julio Quinteros Pro 2026-02-17 19:51:18 -03:00
parent f8f2a86ce1
commit fad4d4cff0
2 changed files with 2 additions and 2 deletions

View file

@ -59,7 +59,7 @@ class lakeraAI_Moderation(CustomGuardrail):
self.async_handler = get_async_httpx_client(
llm_provider=httpxSpecialProvider.GuardrailCallback
)
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY")
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY") or ""
self.moderation_check = moderation_check
self.category_thresholds = category_thresholds
self.api_base = (

View file

@ -54,7 +54,7 @@ class LakeraAIGuardrail(CustomGuardrail):
self.async_handler = get_async_httpx_client(
llm_provider=httpxSpecialProvider.GuardrailCallback
)
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY")
self.lakera_api_key = api_key or os.environ.get("LAKERA_API_KEY") or ""
self.project_id = project_id
self.api_base = (
api_base or get_secret_str("LAKERA_API_BASE") or "https://api.lakera.ai"