
One key challenge with our new Gemini 2.5-based television news story segmentation initiative has lain in coaxing Gemini to produce parseable JSON. Asked to produce output strictly in JSON, with nothing but JSON in its output, Gemini would routinely violate its coherence constraints and introduce various brief textual snippets before, after and in between JSON objects. It would also routinely introduce slight typographical, formatting and other issues that rendered one or more of the output JSON objects unparseable. In fact, with some prompt variants, as many as half the output JSON objects were invalid. The enormous creativity in Gemini's JSON output meant that even with a large and ever-growing library of various cleaning routines designed to salvage the resulting JSON, we continued to struggle to extract workable JSON from Gemini. Enter Gemini's Structured Output capability, where a prompt can be accompanied with a precise JSON output schema. Since we've switched to Structure Output, the JSON output from Gemini has been nearly flawless and we are able to pass its output directly to downstream applications that require perfectly structured JSON.
In essence, using Structured Output, each API call includes a "responseSchema" block that provides the required JSON output schema and Gemini coerces its output to precisely match this schema. No extraneous textual narrative is included and JSON objects are precisely formatted. You can see below the specific schema we have developed for story segmentation.
{ "generationConfig": { "responseMimeType": "application/json", "responseSchema": { "items": { "properties": { "DESCRIPTION": { "type": "STRING" }, "SENTENCEIDS": { "type": "STRING" }, "STORYID": { "type": "NUMBER" }, "TITLE": { "type": "STRING" } }, "type": "OBJECT" }, "propertyOrdering": [ "STORYID", "TITLE", "DESCRIPTION", "SENTENCEIDS" ], "required": [ "STORYID", "TITLE", "DESCRIPTION", "SENTENCEIDS" ], "type": "ARRAY" } } }