valibot-json-schema
valibot-json-schema copied to clipboard
Provide JSON schema translation as a core package
Hi Guillaume, I am toying with the idea of providing an official JSON schema translation package. It seems to me that this is more important than I initially thought due to the use of schema libraries with AI tools.
If the source code of the JSON schema translation lives next to the source code of the core library, it should be easier to keep it up to date. What do you think? Would you be interested in joining this effort?
Sure it sounds great! Would it be only conversion from valibot to JSON schema or also the inverse? Do you have any idea how you would want to do that in valibot? Having it modularized like all schemas/actions or just centralized conversion function like this lib? Also this lib has a CLI, I don't know if you'd want that in valibot (I could keep it in this repo)
For now, my idea is just to add a @valibot/to-json-schema package with a recursive and centralized function to convert Valibot schemas to JSON schemas. A CLI or inverse conversion is currently out of my scope.
Ok well if you want I can draft a PR to create a new to-json-schema package in the valibot repository
This is amazing, i was just looking through openAI's docs for structured output and found it only supported zod. https://github.com/openai/openai-node/blob/master/src/helpers/zod.ts
I'm trying to integrate it with valibot so I'd be happy to be the guinea pig for testing this in prod whenever y'all get the chance :D
@gcornut that would create! Feel free to add the package to /packages/to-json-schema. Please try to reuse the basic package setup from /library. Also, I recommend adding only the implementation and tests for object, string, and email so that we can discuss the optimal implementation before implementing everything. One idea I had in mind is to add a force: boolean parameter so that users can decide whether to throw or ignore if a part of a schema can't be converted to JSON schema.
@gcornut do you have an update for me? If you don't have time to implement it at the moment, I can do it or reach out to the community and ask for help.
I'm off this week but I already have some code ready. I should be able to open the PR in 2/3 days 👍
Ok, don't stress about it and enjoy your free time! Next week will be enough.