3 ms·
Google's Gemini API is a bit odd with structured outputs. If you specify an Application/JSON response mimetype, it will reliably respond with a consistent JSON
by minimaxir 1y ago
Google's Gemini API is a bit odd with structured outputs. If you specify an Application/JSON response mimetype, it will reliably respond with a consistent JSON output without any prompt engineering shenanigans. For my workflows, this setting plus providing a JSON Schema in the system prompt works even with complex schema.
The Gemini API has a canonical implementation of structured outputs where you can instead pass the JSON schema as a separate parameter to control the grammar more closely. However, this setting will reorder the JSON schema fields to be alphabetical beforehand, which is especially not desired behavior as the order of JSON fields in a schema is often very deliberate to control generation.
- Inviz 1y agogemini api has propertyOrdering field for that
- msp26 1y agothat only works for the outer level, not for any nested fields
- thm 1y agoJSON is still not available when you enable Grounding with Search.
- gdudeman 1y agoI was burned by this for a while because I assumed structured output ordering would be preserved. You can specify ordering in the Gemini API with propertyOrdering: "propertyOrdering": ["recipeName", "ingredients"]