You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
fromgoogle.adk.agentsimportAgentfromgoogle.adk.models.lite_llmimportLiteLlmfromtypingimportListfrompydanticimportBaseModel, FieldclassAlbum(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.")
classAlbums(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.
smilovanovic, whoisarpit, patched-admin, rohan3107 and maziar-passage