fix(guardrails): keep Agent 365 missing-secret startup error readable after log redaction

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
yucheng 2026-09-10 08:08:33 +00:00
parent aee5b7a0d8
commit f4033ab84a
2 changed files with 6 additions and 2 deletions

View file

@ -29,7 +29,9 @@ def initialize_guardrail(litellm_params: "LitellmParams", guardrail: "Guardrail"
if not client_id:
raise ValueError("Microsoft Agent 365: client_id is required")
if not client_secret:
raise ValueError("Microsoft Agent 365: client_secret (or api_key) is required")
raise ValueError(
"Microsoft Agent 365: client secret is required. Set client_secret, api_key, or AGENT365_CLIENT_SECRET"
)
guardrail_name: Final = guardrail.get("guardrail_name")
if not guardrail_name:

View file

@ -7,6 +7,7 @@ import pytest
from fastapi import HTTPException
from litellm.exceptions import Timeout as LitellmTimeout
from litellm.litellm_core_utils.secret_redaction import redact_string
from litellm.proxy._types import UserAPIKeyAuth
from litellm.proxy.guardrails.guardrail_hooks.agent_365 import (
Agent365Guardrail,
@ -165,8 +166,9 @@ class TestInitializeGuardrail:
tenant_id="tenant-abc",
client_id="client-xyz",
)
with pytest.raises(ValueError, match="client_secret"):
with pytest.raises(ValueError, match="client_secret") as exc_info:
initialize_guardrail(params, {"guardrail_name": "a365"})
assert redact_string(str(exc_info.value)) == str(exc_info.value)
def test_env_var_fallbacks(self, monkeypatch):
monkeypatch.delenv("AGENT365_RESOURCE_APP_ID", raising=False)