Hi,
We’re using Zod to generate our schema. While Zod allows defining enums, it does not explicitly add “type”: “string” alongside “enum” in the generated JSON Schema.
This works fine with other providers, but Gemini throws the following error:
GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[action].enum: only allowed for STRING type
Hello,
Could you please share your code snippet so that we can analyse your issue better.
@Lalit_Kumar here is the simple code
const {z} = require('zod');
var inputSchema = z.object({
action: z.enum(["fill_form", "edit_form"]),
});
var schema = z.toJSONSchema(inputSchema);
Hi @Senthil_Kumar I’ve tested on my side and it’s working properly. I’ve shared the reference link and code — please check on your side
Reference Link
import { GoogleGenAI } from '@google/genai';
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
import 'dotenv/config';
const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
if (!GEMINI_API_KEY) throw new Error("Missing GEMINI_API_KEY");
const ai = new GoogleGenAI(GEMINI_API_KEY);
const zodSchema = z.object({
action: z.enum(["start", "stop", "pause"]),
});
const jsonSchema = zodToJsonSchema(zodSchema);
async function main() {
const result = await ai.models.generateContent({
model: 'gemini-2.5-flash',
config: {
tools: [{
functionDeclarations: [{
name: "controlDevice",
description: "Controls a device based on an action",
parameters: jsonSchema
}]
}],
},
contents: [{
role: "user",
parts: [{ text: "Start the machine" }]
}]
});
console.log(JSON.stringify(result.candidates[0].content.parts[0].functionCall, null, 2));
}
main().catch(console.error);
1 Like