function convertZodToJsonSchema(schema): Record<string, any> | undefined;
function convertZodToJsonSchema(schema): Record<string, any> | undefined;
Defined in: tools/zod-converter.ts:57
Converts a schema (Zod or JSONSchema) to JSON Schema format compatible with LLM providers. If the input is already a JSONSchema object, it is returned as-is. If the input is a Zod schema, it is converted to JSON Schema.
Zod schema or JSONSchema object to convert
SchemaInput | undefined
Record<string, any> | undefined
JSON Schema object that can be sent to LLM providers
import { z } from 'zod';
// Using Zod schema
const zodSchema = z.object({
location: z.string().describe('City name'),
unit: z.enum(['celsius', 'fahrenheit']).optional()
});
const jsonSchema = convertZodToJsonSchema(zodSchema);
// Returns:
// {
// type: 'object',
// properties: {
// location: { type: 'string', description: 'City name' },
// unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
// },
// required: ['location']
// }
// Using JSONSchema directly (passes through unchanged)
const rawSchema = {
type: 'object',
properties: { location: { type: 'string' } },
required: ['location']
};
const result = convertZodToJsonSchema(rawSchema);
// Returns the same object
import { z } from 'zod';
// Using Zod schema
const zodSchema = z.object({
location: z.string().describe('City name'),
unit: z.enum(['celsius', 'fahrenheit']).optional()
});
const jsonSchema = convertZodToJsonSchema(zodSchema);
// Returns:
// {
// type: 'object',
// properties: {
// location: { type: 'string', description: 'City name' },
// unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
// },
// required: ['location']
// }
// Using JSONSchema directly (passes through unchanged)
const rawSchema = {
type: 'object',
properties: { location: { type: 'string' } },
required: ['location']
};
const result = convertZodToJsonSchema(rawSchema);
// Returns the same object
