From 57a2ec3beb7fcfb7ec7ccd379a19d2db951da9ef Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 22 Oct 2025 09:37:19 -0700 Subject: [PATCH] fix: _extract_fields_recursive --- litellm/proxy/guardrails/guardrail_endpoints.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py index c146536e63..c1756500c6 100644 --- a/litellm/proxy/guardrails/guardrail_endpoints.py +++ b/litellm/proxy/guardrails/guardrail_endpoints.py @@ -841,6 +841,11 @@ def _extract_fields_recursive( "TypeVar", ): continue + # Handle Optional[T] where T is still a TypeVar + if hasattr(field_annotation, "__args__"): + non_none_args = [arg for arg in field_annotation.__args__ if arg is not type(None)] + if non_none_args and isinstance(non_none_args[0], TypeVar): + continue # Get field metadata description = field.description or field_name