Anyone tried to define a JSON schema to the gemini-1.5-flash
model with the response “application/json” and does it respect the schema at all? It works fine with all other models.
I’ve tried defining a schema in Go SDK and I’ve tried to raise an issue about that but it seems it is not the problem of the SDK but the API instead. Anyone tried replicating it in other programming languages and encounter the same issue?
Welcome to the forum. There is a difference between Gemini-1.5-pro and Gemini-1.5-flash in json format responses. It is explained here: Ringkasan Gemini API | Google AI for Developers | Google for Developers
The relevant passage is " While Gemini 1.5 Flash models only accept a text description of the JSON schema you want returned, the Gemini 1.5 Pro models let you pass a schema object (or a Python type equivalent), and the model output will strictly follow that schema. This is also known as controlled generation or constrained decoding ."
Basically, you indicate in a somewhat loose fashion the json format you want when using flash, and it actually mostly works (unless the schema is quite complicated, at which point the model starts forgetting to fill in various fields)
Try it, it might be good enough for your application. If the schema is complex, I think Gemini-1.5-pro will be your only option, it can handle a proper schema (with some caveats, Google says a subset of the json schema is acceptable and a few people have found features not included in the subset Google implemented).
For some sample code, you can see the cookbook : cookbook/quickstarts/JSON_mode.ipynb at main · google-gemini/cookbook · GitHub
1 Like