From 74c3bb2f06a9b4355442a3bf2495fd531fef5791 Mon Sep 17 00:00:00 2001 From: LeizhenZhang Date: Sun, 25 Oct 2026 14:58:44 -0500 Subject: [PATCH] fix(guardrails): keep visit_AsyncFor's result typed The type-check gate measures in .venv-typecheck, where RestrictedPython is not installed, so `self.visit_For(node)` is Unknown there. Binding it to `transformed` and passing it on added one reportUnknownVariableType and one reportUnknownArgumentType over the merge-base ceiling. `guard_iter` rewrites `node.iter` on the node it is given and returns that same node, so keep working on `node`. In that environment sandbox.py now has 18 reportUnknownVariableType (base 19) and 2 reportUnknownArgumentType (base 2). All 67 tests in test_custom_code_security.py pass. --- .../guardrails/guardrail_hooks/custom_code/sandbox.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/guardrails/guardrail_hooks/custom_code/sandbox.py b/litellm/proxy/guardrails/guardrail_hooks/custom_code/sandbox.py index bf1b7bba876..08a7c18b78e 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/custom_code/sandbox.py +++ b/litellm/proxy/guardrails/guardrail_hooks/custom_code/sandbox.py @@ -82,9 +82,10 @@ class AsyncAwareTransformer(RestrictingNodeTransformer): return bounded def visit_AsyncFor(self, node: ast.AsyncFor) -> ast.AST: - transformed: Final = self.visit_For(node) - _use_async_iter_guards(transformed) - return transformed + # `guard_iter` rewrites `node.iter` on the node it is given and returns it. + self.visit_For(node) + _use_async_iter_guards(node) + return node def visit_AsyncWith(self, node: ast.AsyncWith) -> ast.AST: return self.visit_With(node)