-
-
Notifications
You must be signed in to change notification settings - Fork 108
Description
Hello @OskarStark, @chr-hertel,
I'm encountering an issue with the output_structure option (which maps to Capability::OUTPUT_STRUCTURED) when using Gemini models, specifically versions 2.0.
Problem Description
When trying to use the AI Agent with a gemini-2.0 model and the output_structure option to get a formatted JSON response, the call does not work as expected.
Upon investigation, I checked the official Google AI documentation regarding structured output (JSON Schema): https://ai.google.dev/gemini-api/docs/structured-output?hl=en
This documentation is very clear and states (regarding JSON Schema support via responseJsonSchema):
"It only works with Gemini 2.5."
This confirms that Gemini 2.0 models (like gemini-2.0-flash, etc.) do not support this feature.
Issues Identified in symfony/ai
The current problem is twofold:
Incorrect Model Catalog: The ModelCatalog (likely for the Google/VertexAI bridge) appears to list Capability::OUTPUT_STRUCTURED for Gemini 2.0 models. This is in direct contradiction with Google's official documentation.
Lack of Exception: The most problematic part is that the AgentProcessor (or a similar class) does not throw any exception (e.g., LogicException or UnsupportedPlatformException) when a capability (OUTPUT_STRUCTURED) is requested but not actually supported by the model. This check seems to have been removed (see this comment in #728). The call fails silently or in an unexpected way, which makes diagnosis and debugging very difficult.
Suggested Improvements
To fix this behavior and improve the component's robustness, I suggest the following actions:
Update the Catalog: Remove Capability::OUTPUT_STRUCTURED from all Gemini models with a version lower than 2.5 in the relevant ModelCatalog files (Google, VertexAI, etc.).
Restore/Add an Exception: Add a check back into the AgentProcessor (or wherever the options are validated) to throw a clear exception if the user tries to use an option (like output_structure) that is not declared in the selected model's capabilities ($model->getCapabilities()).
This would provide "fail-fast" behavior and immediately inform the developer of the incompatibility between their request and the chosen model.
Thank you for your work on this component!