Skip to content

Instantly share code, notes, and snippets.

View Nishkalkashyap's full-sized avatar
In pursuit of excellence

Nishkal Kashyap Nishkalkashyap

In pursuit of excellence
View GitHub Profile
@Nishkalkashyap
Nishkalkashyap / gemini.object-converter.ts
Last active April 4, 2025 06:05
Zod Schema Converter for Google Generative AI Compatibility
/**
* Gemini generated object to original schema compatible object converter
*
* Utility to convert Gemini generated objects back to their original schema format.
* Pairs with gemini.schema-converter.ts
*/
import { z } from "zod";
function findDiscriminatorKey(schema: z.ZodTypeAny): string | null {
if (schema instanceof z.ZodUnion) {