From 131fbd39482980572487a30fea13236d2badd543 Mon Sep 17 00:00:00 2001 From: "Xiang (Sean) Zhou" Date: Sat, 31 Jan 2026 16:25:38 -0800 Subject: [PATCH] fix: Fix Pydantic Schema Generation Error for ClientSession MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: The test test_openapi_json_schema_accessible was failing because Pydantic couldn't generate a JSON schema for mcp.client.session.ClientSession, which is part of genai_types.ToolListUnion. Root Cause: The AgentDetails model in src/google/adk/evaluation/app_details.py:37 had tool_declarations: genai_types.ToolListUnion, and ToolListUnion includes mcp.client.session.ClientSession which doesn't have Pydantic core schema support. This model is used in the FastAPI app through EvalCase → Invocation → AppDetails → AgentDetails, causing OpenAPI schema generation to fail. Solution: Changed the type annotation from genai_types.ToolListUnion to list[Any] in two places: AgentDetails.tool_declarations _ToolDeclarations.tool_declarations This allows Pydantic to generate the OpenAPI schema while maintaining runtime compatibility (the field still accepts the same values). Co-authored-by: Xiang (Sean) Zhou PiperOrigin-RevId: 863765002 --- src/google/adk/evaluation/app_details.py | 10 ++++++++-- src/google/adk/evaluation/llm_as_judge_utils.py | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/google/adk/evaluation/app_details.py b/src/google/adk/evaluation/app_details.py index 7de5ccf2..85473f85 100644 --- a/src/google/adk/evaluation/app_details.py +++ b/src/google/adk/evaluation/app_details.py @@ -14,6 +14,8 @@ from __future__ import annotations +from typing import Any + from google.genai import types as genai_types from pydantic import Field @@ -32,8 +34,12 @@ class AgentDetails(EvalBaseModel): instructions: str = Field(default="") """The instructions set on the Agent.""" - tool_declarations: genai_types.ToolListUnion = Field(default_factory=list) - """A list of tools available to the Agent.""" + tool_declarations: list[Any] = Field(default_factory=list) + """A list of tools available to the Agent. + + At runtime, this contains elements of type genai_types.ToolListUnion. + We use list[Any] for Pydantic schema generation compatibility. + """ class AppDetails(EvalBaseModel): diff --git a/src/google/adk/evaluation/llm_as_judge_utils.py b/src/google/adk/evaluation/llm_as_judge_utils.py index 3d6fd923..cf1309ca 100644 --- a/src/google/adk/evaluation/llm_as_judge_utils.py +++ b/src/google/adk/evaluation/llm_as_judge_utils.py @@ -16,6 +16,7 @@ from __future__ import annotations import enum import statistics +from typing import Any from typing import Optional from typing import Union @@ -78,7 +79,7 @@ def get_average_rubric_score( class _ToolDeclarations(EvalBaseModel): """Internal data model used for serializing Tool declarations.""" - tool_declarations: dict[str, genai_types.ToolListUnion] + tool_declarations: dict[str, list[Any]] def get_tool_declarations_as_json_str(