Skip to content

Commit 131fbd3

Browse files
seanzhougooglecopybara-github
authored andcommitted
fix: Fix Pydantic Schema Generation Error for ClientSession
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 <seanzhougoogle@google.com> PiperOrigin-RevId: 863765002
1 parent 798f65d commit 131fbd3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/google/adk/evaluation/app_details.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from __future__ import annotations
1616

17+
from typing import Any
18+
1719
from google.genai import types as genai_types
1820
from pydantic import Field
1921

@@ -32,8 +34,12 @@ class AgentDetails(EvalBaseModel):
3234
instructions: str = Field(default="")
3335
"""The instructions set on the Agent."""
3436

35-
tool_declarations: genai_types.ToolListUnion = Field(default_factory=list)
36-
"""A list of tools available to the Agent."""
37+
tool_declarations: list[Any] = Field(default_factory=list)
38+
"""A list of tools available to the Agent.
39+
40+
At runtime, this contains elements of type genai_types.ToolListUnion.
41+
We use list[Any] for Pydantic schema generation compatibility.
42+
"""
3743

3844

3945
class AppDetails(EvalBaseModel):

src/google/adk/evaluation/llm_as_judge_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import enum
1818
import statistics
19+
from typing import Any
1920
from typing import Optional
2021
from typing import Union
2122

@@ -78,7 +79,7 @@ def get_average_rubric_score(
7879
class _ToolDeclarations(EvalBaseModel):
7980
"""Internal data model used for serializing Tool declarations."""
8081

81-
tool_declarations: dict[str, genai_types.ToolListUnion]
82+
tool_declarations: dict[str, list[Any]]
8283

8384

8485
def get_tool_declarations_as_json_str(

0 commit comments

Comments
 (0)