Structured output breaks for gemini flash 2.5
I get the following error
Function calling with a response mime type: 'application/json' is unsupported
I don't get this error for flash 2.0. When using mastra agents.14 Replies
happening to me as well
doesn't happen on the vercel ai sdk, confirmed this
Yes, it wasn't happening few days back, but I recently upgraded mastra@beta
š Created GitHub issue: https://github.com/mastra-ai/mastra/issues/10666
š If you're experiencing an error, please provide a minimal reproducible example whenever possible to help us resolve it quickly.
š Thank you for helping us improve Mastra!
is it when a tool call is happening?
The above does not throw
for me, yes, i was trying with a tool @Abhi Aiyer
I thought it was to do with structure output, but it happens to me when I use memory
We'll take a look and see whats up!
@Mehul you mentioned this error doesn't happen with ai sdk? Can you show me how you're doing that? I seem to get the same error in ai sdk and this is because it's an issue with the model API itself see: https://discuss.ai.google.dev/t/function-calling-with-a-response-mime-type-application-json-is-unsupported/105093
There are ways we can possible handle this, but just want to make sure that is a broader issue first
Google AI Developers Forum
Function calling with a response mime type: 'application/json' is u...
Root Cause The Gemini API does not currently support structured tool calling / function calling with JSON outputs (unlike OpenAI models). The API only supports returning text or multimodal responses, not strongly typed JSON function responses when using tool calling. Confirmed via these discussions: firebase/genkit issue #703 deprecated-genera...
Could you share how to handle it without json?
To bypass this you can set
jsonPromptInjection to true and it will work
it won't use the native response_format
This is an option in the structuredOutput propertyI get the error only with the memory tool call, my initial assumption of structured data was wrong
google gemini (only 2.5) doesn't natively support pass tools along with structured outputs. It's a limitation of the gemini API that we have ways to get around it using
jsonPromptInjection instead of the native response format.
Semantic recall and working memory both use tools to work, so those tools are passed to the agent, so even if you don't have any tools you're manually passing in, those count as tools
I'm adding a callout in our docs for this issue https://github.com/mastra-ai/mastra/pull/10719, We're going to redo the structured output section soon to make it have better discoverability. For now we'll leave it at that and if the documentation doesn't solve this then we'll build some magic into the framework to automatically add that option for gemini models. But we do want to leave that as the last resort as it's better for the user to be aware something is happening and have to opt inThanks, Although I was able to use it with semantic recall, but adding a tool was causing the issue.