From 4fd0cbffb5c0bc72287313ebd0e28173400a05dc Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 21 Aug 2026 00:51:00 +0000 Subject: [PATCH] fix(guardrails): annotate policy pipeline state casts Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index f0cf087b139..2525b3d032c 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -432,12 +432,20 @@ def _policy_state_metadata(data: Mapping[str, object]) -> Mapping[str, object]: def _policy_pipelines(data: Mapping[str, object]) -> tuple[tuple[str, "GuardrailPipeline"], ...]: pipelines: Final = _policy_state_metadata(data).get("_guardrail_pipelines") - return tuple(cast("Sequence[tuple[str, GuardrailPipeline]]", pipelines)) if pipelines else () + return ( + tuple(cast("Sequence[tuple[str, GuardrailPipeline]]", pipelines)) # cast-ok: the policy engine wrote the slot + if pipelines + else () + ) def _pipeline_managed_guardrail_names(data: Mapping[str, object]) -> frozenset[str]: managed: Final = _policy_state_metadata(data).get("_pipeline_managed_guardrails") - return frozenset(cast("Collection[str]", managed)) if managed else frozenset() + return ( + frozenset(cast("Collection[str]", managed)) # cast-ok: the policy engine wrote these guardrail names + if managed + else frozenset() + ) def _prompt_block_text(block: object) -> str: