Skip to content

Commit 6bf9c57

Browse files
committed
Add OpenAI example
1 parent 2db3e92 commit 6bf9c57

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@ const contact = anyOf([
101101
])
102102
```
103103

104+
## 🤖 OpenAI Structured Outputs
105+
106+
JSON Schema Kit is perfectly suited for OpenAI's Structured Outputs.
107+
Here's how to use it with the Vercel AI SDK:
108+
109+
```ts
110+
const schema = object({
111+
summary: string(),
112+
sentiment: string({ enum: ['positive', 'neutral', 'negative'] }),
113+
})
114+
115+
await generateObject({
116+
model: openai('...'),
117+
schema: jsonSchema(schema),
118+
prompt: 'Analyze this review: "Great product, works perfectly!"',
119+
})
120+
```
121+
104122
## 🤔 "But what about Zod?"
105123

106124
Great question! Zod is a versatile and comprehensive library, spanning thousands of lines of code. However, it's not specifically built for generating JSON Schemas, which can lead to unexpected results during conversion. In contrast, JSON Schema Kit provides full control — all in under 100 lines of code.

0 commit comments

Comments
 (0)