From 0013865221a87255f18d7aa4fee7d62326355221 Mon Sep 17 00:00:00 2001 From: Shawn Yang Date: Tue, 11 Nov 2025 12:16:14 -0800 Subject: [PATCH] fix: forward reference resolution in Pydantic schema generation. PiperOrigin-RevId: 831019476 --- vertexai/_genai/_agent_engines_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vertexai/_genai/_agent_engines_utils.py b/vertexai/_genai/_agent_engines_utils.py index 69945a8cd3..bf4842da73 100644 --- a/vertexai/_genai/_agent_engines_utils.py +++ b/vertexai/_genai/_agent_engines_utils.py @@ -590,6 +590,9 @@ def _is_pydantic_serializable(param: inspect.Parameter) -> bool: if param.annotation == inspect.Parameter.empty: return True + if "ForwardRef" in repr(param.annotation): + return True + if isinstance(param.annotation, str): return False @@ -641,7 +644,12 @@ def _generate_schema( name: ( # 1. We infer the argument type here: use Any rather than None so # it will not try to auto-infer the type based on the default value. - (param.annotation if param.annotation != inspect.Parameter.empty else Any), + ( + param.annotation + if param.annotation != inspect.Parameter.empty + and "ForwardRef" not in repr(param.annotation) + else Any + ), pydantic.Field( # 2. We do not support default values for now. # default=(