Skip to content

Commit 0013865

Browse files
shawn-yang-googlecopybara-github
authored andcommitted
fix: forward reference resolution in Pydantic schema generation.
PiperOrigin-RevId: 831019476
1 parent ef03bef commit 0013865

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

vertexai/_genai/_agent_engines_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ def _is_pydantic_serializable(param: inspect.Parameter) -> bool:
590590
if param.annotation == inspect.Parameter.empty:
591591
return True
592592

593+
if "ForwardRef" in repr(param.annotation):
594+
return True
595+
593596
if isinstance(param.annotation, str):
594597
return False
595598

@@ -641,7 +644,12 @@ def _generate_schema(
641644
name: (
642645
# 1. We infer the argument type here: use Any rather than None so
643646
# it will not try to auto-infer the type based on the default value.
644-
(param.annotation if param.annotation != inspect.Parameter.empty else Any),
647+
(
648+
param.annotation
649+
if param.annotation != inspect.Parameter.empty
650+
and "ForwardRef" not in repr(param.annotation)
651+
else Any
652+
),
645653
pydantic.Field(
646654
# 2. We do not support default values for now.
647655
# default=(

0 commit comments

Comments
 (0)