Registry / ai-ml / gemini-zod

gemini-zod

JSON →
library0.1.2jsnpmunverified

A lightweight adapter that enables bidirectional conversion between Gemini AI schemas and Zod schemas, allowing developers to use Zod's runtime validation with Google's Gemini AI. Version 0.1.2 is current; the library supports common data types (string, number, boolean, array, object) and handles optional fields and nullable types. It is designed for TypeScript environments and ships with type definitions. The package is newer with infrequent releases, differentiating by providing a straightforward mapping without additional dependencies beyond Zod.

npm install gemini-zod
INSTALL
IMPORT
SIG · GEMINI-ZOD
G
gemini-zod
ai-mljavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toGeminiSchema
import { toGeminiSchema } from 'gemini-zod'
import toGeminiSchema from 'gemini-zod'
Named export, not default. Only available in ESM.
toZodSchema
import { toZodSchema } from 'gemini-zod'
const { toZodSchema } = require('gemini-zod')
ESM-only; require will fail. Use dynamic import if needed.
GeminiSchema
import type { GeminiSchema } from 'gemini-zod'
TypeScript type export for defining Gemini AI schema shapes.

Demonstrates bidirectional conversion between Zod and Gemini AI schemas using toGeminiSchema and toZodSchema.

import { toGeminiSchema, toZodSchema } from 'gemini-zod'; import { z } from 'zod'; // Convert Zod to Gemini const userZod = z.object({ name: z.string(), age: z.number() }); const gemini = toGeminiSchema(userZod); // Convert Gemini to Zod const geminiInput = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'number' } }, required: ['name', 'age'] }; const zodAgain = toZodSchema(geminiInput); console.log(gemini, zodAgain);
Debug
Known issues
deprecatedThe package is at version 0.1.2 and API may change before 1.0.0.
fix
Pin exact version and test after upgrades.
affects: >=0.0.0 <1.0.0
gotchaNullable and optional handling may differ from Zod expectations: Gemini's nullable corresponds to Zod's optional, not nullable.
fix
Verify schema output; use z.optional() when converting from Gemini nullable.
affects: >=0.0.0
gotchaOnly supports common types (string, number, boolean, array, object). Union, intersection, and custom types may not convert correctly.
fix
Check return type or manually handle unsupported schemas.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package.
fix
Convert to import or use dynamic import: const { toGeminiSchema } = await import('gemini-zod');
TypeError: toGeminiSchema is not a function
Incorrect import (default instead of named).
fix
Use proper named import: import { toGeminiSchema } from 'gemini-zod';
Unhandled schema type: 'enum'
Gemini schema type not supported by toZodSchema.
fix
Convert manually or avoid using enum in input Gemini schemas.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies
zodrequiredrequired peer dependency for schema definitions and runtime validation
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
gemini-zod — npm install gemini-zod · libregistry