Skip to content

Commit 344c0dd

Browse files
authored
chore: [JS] Add instructions to always use zod@v4 (#299)
1 parent a608ae8 commit 344c0dd

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

docs-js/foundation-models/openai/chat-completion.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,19 @@ const response = await client.run({
203203
console.log(response.getContent());
204204
```
205205

206-
You can also define JSON schema using [Zod](https://zod.dev/) schema as shown below:
206+
You can also define JSON schema using [Zod](https://zod.dev/) schema.
207+
We recommend using Zod v4 for full compatibility with this package.
208+
If you're upgrading from an earlier version, refer to the [Zod v4 migration guide](https://zod.dev/v4/changelog) and pay attention to breaking changes like the switch from `describe('...')` to `meta({ description: '...' })`.
207209

208210
```ts
209211
import * as z from 'zod';
210212
import { toJsonSchema } from '@langchain/core/utils/json_schema';
211213
import { AzureOpenAiResponseFormatJsonSchema } from '@sap-ai-sdk/foundation-models';
212214

213-
const countryCapitalSchema = z
214-
.object({
215-
population: z.number(),
216-
capital: z.string()
217-
})
218-
.strict();
215+
const countryCapitalSchema = z.strictObject({
216+
population: z.number(),
217+
capital: z.string()
218+
});
219219

220220
const response_format: AzureOpenAiResponseFormatJsonSchema = {
221221
type: 'json_schema',

docs-js/langchain/openai.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ For a usage example, refer to the [getting started with agents tutorial](../tuto
191191

192192
It is often useful to have a model return output that matches a specific schema.
193193
This schema can be defined using either a [Zod](https://zod.dev/) schema or an OpenAI-style JSON schema.
194+
We recommend using Zod v4 for full compatibility with this package.
195+
If you're upgrading from an earlier version, refer to the [Zod v4 migration guide](https://zod.dev/v4/changelog) and pay attention to breaking changes like the switch from `describe('...')` to `meta({ description: '...' })`.
194196
For more details on structured output, refer to the [official LangChain documentation on structured output](https://docs.langchain.com/oss/javascript/langchain/models#structured-outputs).
195197
Below is an example using `json_schema` response type and passing in a Zod schema.
196198

@@ -201,9 +203,11 @@ import { AzureOpenAiChatClient } from '@sap-ai-sdk/langchain';
201203
const llm = new AzureOpenAiChatClient({ modelName: 'gpt-4o' });
202204

203205
const joke = z.object({
204-
setup: z.string().describe('The setup of the joke'),
205-
punchline: z.string().describe('The punchline to the joke'),
206-
rating: z.number().describe('How funny the joke is, from 1 to 10')
206+
setup: z.string().meta({ description: 'The setup of the joke' }),
207+
punchline: z.string().meta({ description: 'The punchline to the joke' }),
208+
rating: z
209+
.number()
210+
.meta({ description: 'How funny the joke is, from 1 to 10' })
207211
});
208212

209213
const structuredLlm = llm.withStructuredOutput(joke, {

docs-js/orchestration/chat-completion.mdx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,24 @@ const templating: TemplatingModuleConfig = {
404404
};
405405
```
406406

407+
:::info
408+
409+
We recommend using Zod v4 for full compatibility with this package.
410+
If you're upgrading from an earlier version, refer to the [Zod v4 migration guide](https://zod.dev/v4/changelog) and pay attention to breaking changes like the switch from `describe('...')` to `meta({ description: '...' })`
411+
412+
:::
413+
407414
You can also define JSON schema using [Zod](https://zod.dev/) schema as shown below:
408415

409416
```ts
410-
import * as z from 'zod/v4';
417+
import * as z from 'zod';
411418
import { toJsonSchema } from '@langchain/core/utils/json_schema';
412419
import { ResponseFormatJsonSchema } from '@sap-ai-sdk/orchestration';
413420

414-
const countryCapitalSchema = z
415-
.object({
416-
country_name: z.string(),
417-
capital: z.string()
418-
})
419-
.strict();
421+
const countryCapitalSchema = z.strictObject({
422+
country_name: z.string(),
423+
capital: z.string()
424+
});
420425

421426
const response_format: ResponseFormatJsonSchema = {
422427
type: 'json_schema',

0 commit comments

Comments
 (0)