I've had success for most part in Google_ADK but oddly I'm having an issue with an "output_schema" call with List of objects. I'm just doing a basic agent that returns 5 random U.S Presidents from an Open AI call. I created class for President with both name and year they took office. And then another class that has one list object of the five returned Presidents. I keep getting this error.
" Input should be an object [type=model_type, input_value=[{'name': 'James Madison'...ear_took_office': 1909}], input_type=list]
Real simple code but output schema oddly does not work. Anyone who can assist would be greatly appreciated. Code below.
agent.py
from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm
from pydantic import BaseModel,Field
class President(BaseModel):
name: str = Field(
description="The name of the U.S President"
)
year_took_office: int= Field(
description="The year the president took office"
)
class TopPresidents(BaseModel):
presidents: list[President] = "List of Presidents and the year they took office."
llm = LiteLlm(model="openrouter/gpt-4.1")
root_agent= LlmAgent(
name="root_agent",
#model="gemini-2.0-flash-lite",
model=llm,
description="You are an expert U.S Historian with knowledge of all former US Presidents",
instruction="""
Return the name of 5 random US Presidents and the year they took office.
- The returned output must have 5 Random United State Presidents.
DO NOT include any explanations or additional text outside the JSON response.
""",
output_schema=TopPresidents,
output_key="mypresidents"
)