Closed
Description
I have a very basic agent that is using openai/gpt-4o. I am trying to get structured output from it. However, the model either doesn't return JSON or it returns a json response that doesn't follow the given schema.
I am not observing this if I use a model provided by google such as gemini-2.0-flash.
Here is a sample code to reproduce the issue:
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm
from typing import List
from pydantic import BaseModel, Field
class Album(BaseModel):
"""Structured data representing an album."""
name: str = Field(description="The name of the album.")
artist: str = Field(description="The artist of the album.")
year: int = Field(description="The year of the album.")
genre: str = Field(description="The genre of the album.")
class Albums(BaseModel):
"""Structured data representing a list of albums."""
albums: List[Album] = Field(description="A list of albums.")
root_agent = Agent(
name="my_basic_agent",
model=LiteLlm(model="openai/gpt-4o"),
description="An album recommender",
instruction="You are an album recommender. You will recommend albums to the user based on their favorite genre. Return a list of albums as a JSON object.",
output_schema=Albums,
output_key="albums",
)
When the response is received, Pydantic throws a validation error.
Metadata
Metadata
Assignees
Labels
No labels