Effect CommunityEC
Effect Community2mo ago
9 replies
danielo515

Type Error with JSON Schema Conversion in Vercel AI SDK Integration

Hello, I'm trying to use Schema with the Vercel AI SDK (shame on me) and I tried to convert it to JSON Schema, but the signatures doesn't seem to match. I get the following type error:
Argument of type 'JsonSchema7Root' is not assignable to JSONSchema7 

It seems to be close based on the name, but it is not there. Any idea on how can I make use of Schema with generateObject from ai package?
Here is the code snippet:

import { generateObject, jsonSchema } from "ai"
import { Array, Data, Effect, JSONSchema, Schema, Stream } from "effect"

export class AiPlanningError extends Data.TaggedError("@app/AiPlanningError")<{
  cause: unknown
}> {}

const AiResponseSchema = Schema.Struct({
  startDate: Schema.String.pipe(
    Schema.annotations({
      description: "The new start date of the event, in ISO format",
      examples: ["2025-11-17T12:00:00+01:00"]
    })
  ),
  endDate: Schema.String.pipe(
    Schema.annotations({
      description: "The new end date of the event, in ISO format",
      examples: ["2025-12-01T12:00:00+01:00"]
    })
  )
})

const program = Effect.gen(function*() {
  const AiResponseJsonSchema = JSONSchema.make(AiResponseSchema)
  const result = yield* Effect.tryPromise({
    try: (signal) =>
      generateObject({
        abortSignal: signal,
        model: "openai/gpt-4o",
        output: "object",
        schema: jsonSchema(AiResponseJsonSchema),
        messages: [
          {
            role: "system",
            content:
              "Bla bla bla"
          },
          {
            role: "user",
            content: `Bitte analysiere die historischen Daten für das Seminar.`
          }
        ]
      }),
    catch: (error) => new AiPlanningError({ cause: error })
  })

})
Was this page helpful?