Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip conditions from a schema #3816

Open
t18n opened this issue Oct 24, 2024 · 0 comments
Open

Strip conditions from a schema #3816

t18n opened this issue Oct 24, 2024 · 0 comments

Comments

@t18n
Copy link

t18n commented Oct 24, 2024

I would like to be able to achieve this

const myZodSchema = z.object({
  property: z.integer().min(5).max(10)
  property2: z.integer().min(5).max(10)
})

const myZodSchemaOnlyCheckType = z.stripKeywords(myZodSchema, ['min', 'max'])

// Should return 
z.object({
  property: z.integer()
   property2: z.integer()
})

Is there any way to do that?

Some context

I am building an app which uses Drizzle, Zod and Open AI.

On my app, I defined a Drizzle schema and generate a zod schema from it.

import { createInsertSchema } from 'drizzle-zod';

export const profiles = pgTable(
  'profiles',
  {
    headline: varchar('headline', { length: 255 }).notNull(),
  },
);

export const insertProfileSchema = createInsertSchema(profiles);

then send the schema over to Open AI to get Structured output.

The generated Zod schema would include the length check. However, OpenAI doesn't support some keyword at the moment, including maxLength. So that's why I am trying to work around this.

I've tried with createSelectSchema from drizzle-zod without luck.

Any other more elegant solutions are welcomed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant