I wrote up a demo of using JSON schema when calling Gemini APIs. Let me know what you think:
Informative article, thanks for the write-up.
How did you come up with the JSON schemes? Wrote them manually or have them generated by a library? Asking because I’m facing an issue with nullable string properties and the generated value of type
which is an array using multiple primitive types instead of a single one.
See here for more details.
Cheers, JoKi
Sorry for the delay getting back to you, I was sick like a dog. Usually I just look at the docs at JSONSchema’s web site and I can figure it out just fine. However, recently, AI Studio added a tool to let you built it, visually, and when you export the code, it’s done for you. That’s probably the easiest way.
Ok, so I understand that you don’t generate the schema based on code or provide a flexible way to have it generated by a library? Yes, I saw the AIS tooling which works for fixed scenarios but wouldn’t cater for an ad hoc approach or using many schemas.
The AIS tooling requires you to repeat yourself defining the type/class/schema. OK, for a few ones but not sustainable in a larger or dynamic system.
Thanks for the insight.
Well to be clear, I do not do that in my demo as it wouldn’t make sense. If I am building a demo to generate X, it would make sense to have a defined schema. But to be clear, JSON Schema is… json. You 100% could generate it dynamically, and pass it to Gemini, nothing in the API prevents that. It just depends on your use case.
Yes, that’s exactly what I’m doing in the Gemini SDK for .NET.
I had to implement/integrate own code to generate JSON Schema based on passed in types on the fly depending on what the SDK users what to provide as the response schema for their request. I initially started with the necessity that the user has to define it themselves but now it’s dynamic and more convenient for SDK users.
Thanks for the insight.