Usage with JSON Schema
Hi all,
I'm in the process of migrating my project from Zod to ArkType, but I'm running into issues while converting my AI SDK tool input schemas.
The AI SDK requires non-Zod schemas to first be converted to JSON schema and be parsed with their
jsonSchema
helper, but when I do jsonSchema(arktypeSchema.toJsonSchema())
, I get the error:
This happens even when arktypeSchema is type({})
. Any insights?2 Replies
Another piece of context:
While
jsonSchema(type({}).toJsonSchema())
gives the error, if I paste the runtime output of type({}).toJsonSchema()
into the adapter as jsonSchema({ $schema: "https://json-schema.org/draft/2020-12/schema", type: "object" });
, then it works fine.Welcome! This is just a quirk of interop between two libraries with different definition of the shape of a JsonSchema object, which is not trivial to represnt in TypeScript.
Unless something is failing at runtime, your best bet would be to simply cast the result of ArkType's
toJsonSchema
method so that it is compatible with the library you're trying to use it with.
If you're using this in many places, instead you may want to create a wrapper function like: