Skip to content

[JS] date/time formats in schema cause error #227

@sqrrrl

Description

@sqrrrl

Describe the bug
Using z.date() or z.string().datetime() in an input schema results in an error when calling a tool or flow.

TRPCClientError: unknown format "date-time" ignored in schema at path "#/properties/start"
at n.from (http://localhost:4000/main-ZXY5OYEA.js:17:517771)
at http://localhost:4000/main-ZXY5OYEA.js:17:521774
at u.invoke (http://localhost:4000/polyfills-QXL6O4PO.js:16:6385)
at Object.onInvoke (http://localhost:4000/chunk-XINN327K.js:22:79627)
at u.invoke (http://localhost:4000/polyfills-QXL6O4PO.js:16:6325)
at Y.run (http://localhost:4000/polyfills-QXL6O4PO.js:16:1715)
at http://localhost:4000/polyfills-QXL6O4PO.js:17:554
at u.invokeTask (http://localhost:4000/polyfills-QXL6O4PO.js:16:7010)
at Object.onInvokeTask (http://localhost:4000/chunk-XINN327K.js:22:79443)
at u.invokeTask (http://localhost:4000/polyfills-QXL6O4PO.js:16:6931)

To Reproduce

import { defineTool, generate } from '@genkit-ai/ai';
import { action, configureGenkit } from '@genkit-ai/core';
import { defineFlow, startFlowsServer } from '@genkit-ai/flow';
import { gemini15ProPreview } from '@genkit-ai/vertexai';
import * as z from 'zod';
import { vertexAI } from '@genkit-ai/vertexai';
import 'dotenv/config'

configureGenkit({
  plugins: [
    vertexAI({ location: 'us-central1' }),
  ],
  logLevel: 'debug',
  enableTracingAndMetrics: true,
});


const getSchedule = defineTool(
  {
    name: 'calendar',
    description: 'Retrieves a users schedule for a time range',
    inputSchema: z.object({
      start: z.string().datetime(),
      end: z.string().datetime(),
    }),
    outputSchema: z.array(z.object({
      startTime: z.string(),
      endTime: z.string(),
      summary: z.string()
    }))
  },
  async({start, end}) => {
    console.log("Fetching calendar for", start, end);

    return [
    {
      "startTime": "2024-05-20T08:00:00",
      "endTime": "2024-05-20T09:30:00",
      "summary": "Team Meeting - Q2 Goals Review"
    },
    {
      "startTime": "2024-05-20T10:00:00",
      "endTime": "2024-05-20T11:00:00",
      "summary": "Client Call - Project X Kickoff"
    },
    {
      "startTime": "2024-05-20T14:00:00",
      "endTime": "2024-05-20T15:30:00",
      "summary": "Budget Planning Session"
    },
    {
      "startTime": "2024-05-21T09:00:00",
      "endTime": "2024-05-21T10:00:00",
      "summary": "1:1 with Sarah - Performance Review"
    },
    {
      "startTime": "2024-05-21T11:00:00",
      "endTime": "2024-05-21T12:30:00",
      "summary": "Webinar - Marketing Trends in 2024"
    },
    {
      "startTime": "2024-05-21T15:00:00",
      "endTime": "2024-05-21T16:00:00",
      "summary": "Doctor's Appointment"
    },
    {
      "startTime": "2024-05-22T10:30:00",
      "endTime": "2024-05-22T12:00:00",
      "summary": "Product Demo - Client Z"
    },
    {
      "startTime": "2024-05-22T14:30:00",
      "endTime": "2024-05-22T15:30:00",
      "summary": "Interview - Potential New Hire"
    },
    {
      "startTime": "2024-05-23T13:00:00",
      "endTime": "2024-05-23T14:30:00",
      "summary": "Lunch with Board Members"
    }
  ]
}
);

export const testToolFlow = defineFlow(
  {
    name: 'toolTest',
    inputSchema: z.string(),
    outputSchema: z.string(),
  },
  async (input) => {
    const llmResponse = await generate(  {
      prompt: `How much free time do I have on 5/22/2024 between 9am and 5pm`,
      model: gemini15ProPreview,
      config: {
        temperature: 1,
      },
      tools: [getSchedule],
    });
    return llmResponse.text()
  }
);

startFlowsServer();

Expected behavior

Genkit understands all common zod types.

Screenshots
If applicable, add screenshots to help explain your problem.

Runtime (please complete the following information):

  • OS: [e.g. Linux, MacOS]
  • Version [e.g. 22]

** Node version

  • run node --version at paste here

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjs

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions