@mastra/schema-compat 1.3.7-alpha.0 → 1.3.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md DELETED
@@ -1,1007 +0,0 @@
1
- # @mastra/schema-compat
2
-
3
- ## 1.3.7-alpha.0
4
-
5
- ### Patch Changes
6
-
7
- - Optional nested JSON Schema properties with multiple types no longer produce exponentially large OpenAI tool payloads. Payload growth now remains linear as these schemas become more deeply nested. ([#21190](https://github.com/mastra-ai/mastra/pull/21190))
8
-
9
- ## 1.3.6
10
-
11
- ### Patch Changes
12
-
13
- - Fixed OpenAI structured output requests failing when a schema uses `z.record()`. The OpenAI compatibility layer now removes the `propertyNames` keyword, which OpenAI strict mode does not permit. Requests that used to fail with "Invalid schema ... 'propertyNames' is not permitted" are now accepted. ([#20977](https://github.com/mastra-ai/mastra/pull/20977))
14
-
15
- **Known limitation.** OpenAI strict mode cannot express an open-ended map. A `z.record()` field is still sent as a plain object with no value schema, so the model is not told what keys or values to produce. Use an explicit `z.object({ ... })` shape when you need the model to fill a map. See [#19273](https://github.com/mastra-ai/mastra/issues/19273).
16
-
17
- - Fix supervisor agent tool schemas for Gemini via OpenRouter. Properties with no Gemini-compatible type — most commonly `z.any()`, which serializes to an empty schema — are now rewritten into a permissive `anyOf` instead of being dropped. This resolves the misleading `required[N]: property is not defined` error when using Gemini models through OpenRouter as a supervisor agent (fixes #17325), while keeping fields the model is expected to fill (such as `resumeData` for tool suspend/resume) present in the tool contract. ([#17386](https://github.com/mastra-ai/mastra/pull/17386))
18
-
19
- - Fixed Zod v3 schema conversion for CommonJS consumers. ([#21147](https://github.com/mastra-ai/mastra/pull/21147))
20
-
21
- - Fixed tool execute-time input validation for Zod tools on Anthropic Claude 3.5 Haiku. The compat layer now skips string min/max checks that were removed from the model-facing JSON Schema, while preserving refinements, defaults, and other validation semantics. ([#19701](https://github.com/mastra-ai/mastra/pull/19701))
22
-
23
- ## 1.3.6-alpha.3
24
-
25
- ### Patch Changes
26
-
27
- - Fixed Zod v3 schema conversion for CommonJS consumers. ([#21147](https://github.com/mastra-ai/mastra/pull/21147))
28
-
29
- ## 1.3.6-alpha.2
30
-
31
- ### Patch Changes
32
-
33
- - Fixed OpenAI structured output requests failing when a schema uses `z.record()`. The OpenAI compatibility layer now removes the `propertyNames` keyword, which OpenAI strict mode does not permit. Requests that used to fail with "Invalid schema ... 'propertyNames' is not permitted" are now accepted. ([#20977](https://github.com/mastra-ai/mastra/pull/20977))
34
-
35
- **Known limitation.** OpenAI strict mode cannot express an open-ended map. A `z.record()` field is still sent as a plain object with no value schema, so the model is not told what keys or values to produce. Use an explicit `z.object({ ... })` shape when you need the model to fill a map. See [#19273](https://github.com/mastra-ai/mastra/issues/19273).
36
-
37
- ## 1.3.6-alpha.1
38
-
39
- ### Patch Changes
40
-
41
- - Fixed tool execute-time input validation for Zod tools on Anthropic Claude 3.5 Haiku. The compat layer now skips string min/max checks that were removed from the model-facing JSON Schema, while preserving refinements, defaults, and other validation semantics. ([#19701](https://github.com/mastra-ai/mastra/pull/19701))
42
-
43
- ## 1.3.6-alpha.0
44
-
45
- ### Patch Changes
46
-
47
- - Fix supervisor agent tool schemas for Gemini via OpenRouter. Properties with no Gemini-compatible type — most commonly `z.any()`, which serializes to an empty schema — are now rewritten into a permissive `anyOf` instead of being dropped. This resolves the misleading `required[N]: property is not defined` error when using Gemini models through OpenRouter as a supervisor agent (fixes #17325), while keeping fields the model is expected to fill (such as `resumeData` for tool suspend/resume) present in the tool contract. ([#17386](https://github.com/mastra-ai/mastra/pull/17386))
48
-
49
- ## 1.3.5
50
-
51
- ### Patch Changes
52
-
53
- - Fixed Claude requests failing when tool inputs use a top-level union of object schemas. ([#20724](https://github.com/mastra-ai/mastra/pull/20724))
54
-
55
- ## 1.3.5-alpha.0
56
-
57
- ### Patch Changes
58
-
59
- - Fixed Claude requests failing when tool inputs use a top-level union of object schemas. ([#20724](https://github.com/mastra-ai/mastra/pull/20724))
60
-
61
- ## 1.3.4
62
-
63
- ### Patch Changes
64
-
65
- - test(schema-compat): fix 'successful' typo in provider e2e test descriptions ([#19167](https://github.com/mastra-ai/mastra/pull/19167))
66
-
67
- - Fixed a crash when converting Zod v4 schemas containing `z.record(...)` through `applyCompatLayer` with any provider compat layer attached (e.g. `GoogleSchemaCompatLayer`, `OpenAISchemaCompatLayer`). ([#17052](https://github.com/mastra-ai/mastra/pull/17052))
68
-
69
- The record patch is now applied in `toStandardSchema` before the `StandardSchemaWithJSON` short-circuit, so it covers Zod >= 4.2 (which natively exposes `~standard.jsonSchema` and bypasses the Zod v4 adapter) as well as older Zod v4 versions that go through the adapter. Affects Zod 4.0.0–4.3.x; the underlying `z.record()` bug is fixed upstream in Zod 4.4.0.
70
-
71
- Fixes [#17051](https://github.com/mastra-ai/mastra/issues/17051).
72
-
73
- - Fixed Meta (Llama) and DeepSeek schemas leaking raw number bounds to the model. A field like `z.number().int()` was sent to the model with bogus `minimum: -9007199254740991` / `maximum: 9007199254740991` values, and `z.number().min(1).max(50)` leaked `minimum`/`maximum` keywords, even though OpenAI, Google, and Anthropic already strip these. Numeric constraints are now moved into the field description for Meta and DeepSeek too, matching the other providers. ([#19073](https://github.com/mastra-ai/mastra/pull/19073))
74
-
75
- **Before** (Meta/DeepSeek, `z.object({ age: z.number().min(0).max(120) })`):
76
-
77
- ```json
78
- { "age": { "type": "number", "minimum": 0, "maximum": 120 } }
79
- ```
80
-
81
- **After**:
82
-
83
- ```json
84
- { "age": { "type": "number", "description": "constraints: greater than or equal to 0, lower than or equal to 120" } }
85
- ```
86
-
87
- Closes #19072.
88
-
89
- ## 1.3.4-alpha.2
90
-
91
- ### Patch Changes
92
-
93
- - Fixed a crash when converting Zod v4 schemas containing `z.record(...)` through `applyCompatLayer` with any provider compat layer attached (e.g. `GoogleSchemaCompatLayer`, `OpenAISchemaCompatLayer`). ([#17052](https://github.com/mastra-ai/mastra/pull/17052))
94
-
95
- The record patch is now applied in `toStandardSchema` before the `StandardSchemaWithJSON` short-circuit, so it covers Zod >= 4.2 (which natively exposes `~standard.jsonSchema` and bypasses the Zod v4 adapter) as well as older Zod v4 versions that go through the adapter. Affects Zod 4.0.0–4.3.x; the underlying `z.record()` bug is fixed upstream in Zod 4.4.0.
96
-
97
- Fixes [#17051](https://github.com/mastra-ai/mastra/issues/17051).
98
-
99
- ## 1.3.4-alpha.1
100
-
101
- ### Patch Changes
102
-
103
- - test(schema-compat): fix 'successful' typo in provider e2e test descriptions ([#19167](https://github.com/mastra-ai/mastra/pull/19167))
104
-
105
- ## 1.3.4-alpha.0
106
-
107
- ### Patch Changes
108
-
109
- - Fixed Meta (Llama) and DeepSeek schemas leaking raw number bounds to the model. A field like `z.number().int()` was sent to the model with bogus `minimum: -9007199254740991` / `maximum: 9007199254740991` values, and `z.number().min(1).max(50)` leaked `minimum`/`maximum` keywords, even though OpenAI, Google, and Anthropic already strip these. Numeric constraints are now moved into the field description for Meta and DeepSeek too, matching the other providers. ([#19073](https://github.com/mastra-ai/mastra/pull/19073))
110
-
111
- **Before** (Meta/DeepSeek, `z.object({ age: z.number().min(0).max(120) })`):
112
-
113
- ```json
114
- { "age": { "type": "number", "minimum": 0, "maximum": 120 } }
115
- ```
116
-
117
- **After**:
118
-
119
- ```json
120
- { "age": { "type": "number", "description": "constraints: greater than or equal to 0, lower than or equal to 120" } }
121
- ```
122
-
123
- Closes #19072.
124
-
125
- ## 1.3.3
126
-
127
- ### Patch Changes
128
-
129
- - Fix the Zod v4 nullable and optional handlers gating on the wrapper type instead of the wrapped inner type. They checked `value.constructor.name` (always `"ZodNullable"`/`"ZodOptional"`), so the inner type was always processed. A nullable/optional wrapping an unsupported inner type (such as a tuple) is now passed through unchanged, matching the v3 handler, instead of being processed and rejected. Closes #18687. ([#18688](https://github.com/mastra-ai/mastra/pull/18688))
130
-
131
- ## 1.3.3-alpha.0
132
-
133
- ### Patch Changes
134
-
135
- - Fix the Zod v4 nullable and optional handlers gating on the wrapper type instead of the wrapped inner type. They checked `value.constructor.name` (always `"ZodNullable"`/`"ZodOptional"`), so the inner type was always processed. A nullable/optional wrapping an unsupported inner type (such as a tuple) is now passed through unchanged, matching the v3 handler, instead of being processed and rejected. Closes #18687. ([#18688](https://github.com/mastra-ai/mastra/pull/18688))
136
-
137
- ## 1.3.2
138
-
139
- ### Patch Changes
140
-
141
- - Fix the Zod v4 string handler silently dropping unrecognized `string_format` checks. Formats without a textual description (such as `ipv4`, `ipv6`, `datetime`, `date`, `time`, `base64`, `cuid2`, `ulid`, `nanoid`, `jwt`) are now preserved as validation instead of being removed, so schemas using them keep rejecting invalid input. Closes #18634. ([#18673](https://github.com/mastra-ai/mastra/pull/18673))
142
-
143
- - Fix inverted date constraint descriptions in the Zod v4 schema handler. `z.date().min()` and `z.date().max()` were described with their bounds swapped (a lower bound was labelled "older than" and an upper bound "newer than"), so the schema sent to the model stated the opposite and impossible constraint. The handler now matches Zod semantics and the existing v3 handler. Closes #18581. ([#18582](https://github.com/mastra-ai/mastra/pull/18582))
144
-
145
- - Fixed 'Type instantiation is excessively deep' (TS2589) errors that occurred when defining workflows with Zod schemas. Workflow and step type inference is now significantly faster and no longer causes TypeScript to crash or report depth errors. ([#18608](https://github.com/mastra-ai/mastra/pull/18608))
146
-
147
- ## 1.3.2-alpha.1
148
-
149
- ### Patch Changes
150
-
151
- - Fix the Zod v4 string handler silently dropping unrecognized `string_format` checks. Formats without a textual description (such as `ipv4`, `ipv6`, `datetime`, `date`, `time`, `base64`, `cuid2`, `ulid`, `nanoid`, `jwt`) are now preserved as validation instead of being removed, so schemas using them keep rejecting invalid input. Closes #18634. ([#18673](https://github.com/mastra-ai/mastra/pull/18673))
152
-
153
- ## 1.3.2-alpha.0
154
-
155
- ### Patch Changes
156
-
157
- - Fix inverted date constraint descriptions in the Zod v4 schema handler. `z.date().min()` and `z.date().max()` were described with their bounds swapped (a lower bound was labelled "older than" and an upper bound "newer than"), so the schema sent to the model stated the opposite and impossible constraint. The handler now matches Zod semantics and the existing v3 handler. Closes #18581. ([#18582](https://github.com/mastra-ai/mastra/pull/18582))
158
-
159
- - Fixed 'Type instantiation is excessively deep' (TS2589) errors that occurred when defining workflows with Zod schemas. Workflow and step type inference is now significantly faster and no longer causes TypeScript to crash or report depth errors. ([#18608](https://github.com/mastra-ai/mastra/pull/18608))
160
-
161
- ## 1.3.1
162
-
163
- ### Patch Changes
164
-
165
- - Fixed createTool type error when passing jsonSchema() or a Schema object from @ai-sdk/provider-utils as inputSchema — no more cast needed ([#17435](https://github.com/mastra-ai/mastra/pull/17435))
166
-
167
- ## 1.3.1-alpha.0
168
-
169
- ### Patch Changes
170
-
171
- - Fixed createTool type error when passing jsonSchema() or a Schema object from @ai-sdk/provider-utils as inputSchema — no more cast needed ([#17435](https://github.com/mastra-ai/mastra/pull/17435))
172
-
173
- ## 1.3.0
174
-
175
- ### Minor Changes
176
-
177
- - Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
178
-
179
- ## 1.3.0-alpha.0
180
-
181
- ### Minor Changes
182
-
183
- - Random bump ([#18178](https://github.com/mastra-ai/mastra/pull/18178))
184
-
185
- ## 1.2.14
186
-
187
- ### Patch Changes
188
-
189
- - Security remediation for the 2026-06-17 "easy-day-js" supply-chain incident. Patch bump to publish clean versions and move the `latest` dist-tag forward, superseding the compromised versions that declared the malicious `easy-day-js` dependency. ([#18056](https://github.com/mastra-ai/mastra/pull/18056))
190
-
191
- ## 1.2.14-alpha.0
192
-
193
- ### Patch Changes
194
-
195
- - Security remediation for the 2026-06-17 "easy-day-js" supply-chain incident. Patch bump to publish clean versions and move the `latest` dist-tag forward, superseding the compromised versions that declared the malicious `easy-day-js` dependency. ([#18056](https://github.com/mastra-ai/mastra/pull/18056))
196
-
197
- ## 1.2.12
198
-
199
- ### Patch Changes
200
-
201
- - Fixed schema compatibility type declarations so JSON Schema types are bundled correctly. ([#17877](https://github.com/mastra-ai/mastra/pull/17877))
202
-
203
- ## 1.2.11
204
-
205
- ### Patch Changes
206
-
207
- - Fixed Gemini REST tool calls failing for `z.discriminatedUnion`, `z.lazy`, and `z.tuple` inputs. `GoogleSchemaCompatLayer` now rewrites JSON Schema 2020-12 keywords into the OpenAPI 3.0 Schema Object subset that Gemini expects: `oneOf` → `anyOf`, `const` → `enum`, tuple `items: [array]` → `items: { anyOf: [...] }`, nullable `anyOf` collapse, `$ref` inlining with recursive schema support, and stripping of `$schema`/`additionalProperties`/`propertyNames`. Fixes #17057. ([#17179](https://github.com/mastra-ai/mastra/pull/17179))
208
-
209
- - Fixed Zod 4 schemas with `.transform()` producing the wrong JSON Schema for structured output and tool calling. The generated schema now describes the pre-transform input the model must produce instead of the post-transform output, so a field like `z.string().transform(JSON.parse)` is advertised as a `string` rather than `string | number | boolean | null`. ([#17357](https://github.com/mastra-ai/mastra/pull/17357))
210
-
211
- ## 1.2.11-alpha.0
212
-
213
- ### Patch Changes
214
-
215
- - Fixed Gemini REST tool calls failing for `z.discriminatedUnion`, `z.lazy`, and `z.tuple` inputs. `GoogleSchemaCompatLayer` now rewrites JSON Schema 2020-12 keywords into the OpenAPI 3.0 Schema Object subset that Gemini expects: `oneOf` → `anyOf`, `const` → `enum`, tuple `items: [array]` → `items: { anyOf: [...] }`, nullable `anyOf` collapse, `$ref` inlining with recursive schema support, and stripping of `$schema`/`additionalProperties`/`propertyNames`. Fixes #17057. ([#17179](https://github.com/mastra-ai/mastra/pull/17179))
216
-
217
- - Fixed Zod 4 schemas with `.transform()` producing the wrong JSON Schema for structured output and tool calling. The generated schema now describes the pre-transform input the model must produce instead of the post-transform output, so a field like `z.string().transform(JSON.parse)` is advertised as a `string` rather than `string | number | boolean | null`. ([#17357](https://github.com/mastra-ai/mastra/pull/17357))
218
-
219
- ## 1.2.10
220
-
221
- ### Patch Changes
222
-
223
- - Fixed Google-compatible schema conversion so Gemini accepts broad nullable tool parameters. ([#16129](https://github.com/mastra-ai/mastra/pull/16129))
224
-
225
- ## 1.2.10-alpha.0
226
-
227
- ### Patch Changes
228
-
229
- - Fixed Google-compatible schema conversion so Gemini accepts broad nullable tool parameters. ([#16129](https://github.com/mastra-ai/mastra/pull/16129))
230
-
231
- ## 1.2.9
232
-
233
- ### Patch Changes
234
-
235
- - Fixed MCP tool validation failures when tools use JSON Schema draft 2020-12. Tools from providers like Firecrawl that declare `$schema: "https://json-schema.org/draft/2020-12/schema"` now validate correctly instead of throwing "no schema with key or ref" errors. ([#14530](https://github.com/mastra-ai/mastra/pull/14530))
236
-
237
- - Fixed MCP tools with recursive JSON Schema refs so they stay serializable when loaded. ([#15400](https://github.com/mastra-ai/mastra/pull/15400))
238
-
239
- ## 1.2.9-alpha.1
240
-
241
- ### Patch Changes
242
-
243
- - Fixed MCP tool validation failures when tools use JSON Schema draft 2020-12. Tools from providers like Firecrawl that declare `$schema: "https://json-schema.org/draft/2020-12/schema"` now validate correctly instead of throwing "no schema with key or ref" errors. ([#14530](https://github.com/mastra-ai/mastra/pull/14530))
244
-
245
- ## 1.2.9-alpha.0
246
-
247
- ### Patch Changes
248
-
249
- - Fixed MCP tools with recursive JSON Schema refs so they stay serializable when loaded. ([#15400](https://github.com/mastra-ai/mastra/pull/15400))
250
-
251
- ## 1.2.8
252
-
253
- ### Patch Changes
254
-
255
- - --- ([#14624](https://github.com/mastra-ai/mastra/pull/14624))
256
- `@mastra/schema-compat`: patch
257
-
258
- ***
259
-
260
- Improved provider schema compatibility for structured outputs and tool calls.
261
- Fixed validation for optional, nullable, and defaulted fields, and for ISO date strings returned for date fields.
262
-
263
- ## 1.2.8-alpha.0
264
-
265
- ### Patch Changes
266
-
267
- - --- ([#14624](https://github.com/mastra-ai/mastra/pull/14624))
268
- `@mastra/schema-compat`: patch
269
-
270
- ***
271
-
272
- Improved provider schema compatibility for structured outputs and tool calls.
273
- Fixed validation for optional, nullable, and defaulted fields, and for ISO date strings returned for date fields.
274
-
275
- ## 1.2.7
276
-
277
- ### Patch Changes
278
-
279
- - Fixed schema-compat ESM imports for Zod JSON Schema helpers. ([#14617](https://github.com/mastra-ai/mastra/pull/14617))
280
-
281
- @mastra/schema-compat no longer uses createRequire in its Zod v4 adapter or runtime eval tests, which avoids createRequire-related ESM issues while preserving support for zod/v3 and zod/v4.
282
-
283
- - Fix Zod v3 and Zod v4 compatibility across public structured-output APIs. ([#14464](https://github.com/mastra-ai/mastra/pull/14464))
284
-
285
- Mastra agent and client APIs accept schemas from either `zod/v3` or `zod/v4`, matching the documented peer dependency range and preserving TypeScript compatibility for both Zod versions.
286
-
287
- ## 1.2.7-alpha.1
288
-
289
- ### Patch Changes
290
-
291
- - Fixed schema-compat ESM imports for Zod JSON Schema helpers. ([#14617](https://github.com/mastra-ai/mastra/pull/14617))
292
-
293
- @mastra/schema-compat no longer uses createRequire in its Zod v4 adapter or runtime eval tests, which avoids createRequire-related ESM issues while preserving support for zod/v3 and zod/v4.
294
-
295
- ## 1.2.7-alpha.0
296
-
297
- ### Patch Changes
298
-
299
- - Fix Zod v3 and Zod v4 compatibility across public structured-output APIs. ([#14464](https://github.com/mastra-ai/mastra/pull/14464))
300
-
301
- Mastra agent and client APIs accept schemas from either `zod/v3` or `zod/v4`, matching the documented peer dependency range and preserving TypeScript compatibility for both Zod versions.
302
-
303
- ## 1.2.6
304
-
305
- ### Patch Changes
306
-
307
- - fix(schema-compat): map Mastra draft target names to Zod v4 format ([#14401](https://github.com/mastra-ai/mastra/pull/14401))
308
-
309
- Zod v4's `z.toJSONSchema()` expects `"draft-7"` / `"draft-4"` while
310
- Mastra uses `"draft-07"` / `"draft-04"`. The mismatch caused repeated
311
- `Invalid target: draft-07` console warnings and suppressed the `$schema`
312
- field in generated JSON Schemas.
313
-
314
- Adds `ZOD_V4_TARGET_MAP` in the zod-v4 adapter to translate target names
315
- before calling `z.toJSONSchema()`. `"draft-2020-12"` is unchanged as both
316
- sides already agree on that name.
317
-
318
- Fixes `#14399`
319
-
320
- - Add support for `draft-2020-12` and `draft-04` JSON Schema targets in the Zod v3 adapter, and fix the `toJSONSchema` target mapping to properly translate all `zod-to-json-schema` target names (like `openApi3`) to standard-schema target names. Fixes "Unsupported JSON Schema target" errors when serializing tool schemas. ([#14471](https://github.com/mastra-ai/mastra/pull/14471))
321
-
322
- ## 1.2.6-alpha.1
323
-
324
- ### Patch Changes
325
-
326
- - Add support for `draft-2020-12` and `draft-04` JSON Schema targets in the Zod v3 adapter, and fix the `toJSONSchema` target mapping to properly translate all `zod-to-json-schema` target names (like `openApi3`) to standard-schema target names. Fixes "Unsupported JSON Schema target" errors when serializing tool schemas. ([#14471](https://github.com/mastra-ai/mastra/pull/14471))
327
-
328
- ## 1.2.6-alpha.0
329
-
330
- ### Patch Changes
331
-
332
- - fix(schema-compat): map Mastra draft target names to Zod v4 format ([#14401](https://github.com/mastra-ai/mastra/pull/14401))
333
-
334
- Zod v4's `z.toJSONSchema()` expects `"draft-7"` / `"draft-4"` while
335
- Mastra uses `"draft-07"` / `"draft-04"`. The mismatch caused repeated
336
- `Invalid target: draft-07` console warnings and suppressed the `$schema`
337
- field in generated JSON Schemas.
338
-
339
- Adds `ZOD_V4_TARGET_MAP` in the zod-v4 adapter to translate target names
340
- before calling `z.toJSONSchema()`. `"draft-2020-12"` is unchanged as both
341
- sides already agree on that name.
342
-
343
- Fixes `#14399`
344
-
345
- ## 1.2.5
346
-
347
- ### Patch Changes
348
-
349
- - Added ZodIntersection support so that MCP tools using allOf in their JSON Schema no longer throw 'does not support zod type: ZodIntersection'. Intersection types are flattened and merged into a single object schema across all provider compatibility layers (Anthropic, Google, OpenAI, OpenAI Reasoning, DeepSeek, Meta). ([#14255](https://github.com/mastra-ai/mastra/pull/14255))
350
-
351
- ## 1.2.5-alpha.0
352
-
353
- ### Patch Changes
354
-
355
- - Added ZodIntersection support so that MCP tools using allOf in their JSON Schema no longer throw 'does not support zod type: ZodIntersection'. Intersection types are flattened and merged into a single object schema across all provider compatibility layers (Anthropic, Google, OpenAI, OpenAI Reasoning, DeepSeek, Meta). ([#14255](https://github.com/mastra-ai/mastra/pull/14255))
356
-
357
- ## 1.2.4
358
-
359
- ### Patch Changes
360
-
361
- - Lazily load createRequire to fix 'Uncaught (in promise) TypeError: lzt.createRequire is not a function' error ([#14275](https://github.com/mastra-ai/mastra/pull/14275))
362
-
363
- ## 1.2.4-alpha.0
364
-
365
- ### Patch Changes
366
-
367
- - Lazily load createRequire to fix 'Uncaught (in promise) TypeError: lzt.createRequire is not a function' error ([#14275](https://github.com/mastra-ai/mastra/pull/14275))
368
-
369
- ## 1.2.3
370
-
371
- ### Patch Changes
372
-
373
- - Fixed "Dynamic require of zod/v4 is not supported" error when schema-compat is consumed by ESM bundles (e.g. via npx mastracode). The dynamic require fallback was incorrectly selecting esbuild's require shim instead of Node.js createRequire. ([#14268](https://github.com/mastra-ai/mastra/pull/14268))
374
-
375
- ## 1.2.2
376
-
377
- ### Patch Changes
378
-
379
- - `@mastra/schema-compat`: patch ([#14195](https://github.com/mastra-ai/mastra/pull/14195))
380
-
381
- Fixed published `@mastra/schema-compat` types so AI SDK v5 schemas resolve correctly for consumers
382
-
383
- - Fixed false `z.toJSONSchema is not available` errors for compatible Zod versions. ([#14264](https://github.com/mastra-ai/mastra/pull/14264))
384
-
385
- **What changed**
386
- - Improved Zod schema conversion detection so JSON Schema generation works more reliably across different runtime setups.
387
-
388
- ## 1.2.2-alpha.0
389
-
390
- ### Patch Changes
391
-
392
- - `@mastra/schema-compat`: patch ([#14195](https://github.com/mastra-ai/mastra/pull/14195))
393
-
394
- Fixed published `@mastra/schema-compat` types so AI SDK v5 schemas resolve correctly for consumers
395
-
396
- - Fixed false `z.toJSONSchema is not available` errors for compatible Zod versions. ([#14264](https://github.com/mastra-ai/mastra/pull/14264))
397
-
398
- **What changed**
399
- - Improved Zod schema conversion detection so JSON Schema generation works more reliably across different runtime setups.
400
-
401
- ## 1.2.1
402
-
403
- ### Patch Changes
404
-
405
- - dependencies updates: ([#14119](https://github.com/mastra-ai/mastra/pull/14119))
406
- - Updated dependency [`zod-from-json-schema@^0.5.2` ↗︎](https://www.npmjs.com/package/zod-from-json-schema/v/0.5.2) (from `^0.5.0`, in `dependencies`)
407
-
408
- - Fixed Zod v4 schema conversion when `zod/v4` compat layer from Zod 3.25.x is used. Schemas like `ask_user` and other harness tools were not being properly converted to JSON Schema when `~standard.jsonSchema` was absent, causing `type: "None"` errors from the Anthropic API. ([#14157](https://github.com/mastra-ai/mastra/pull/14157))
409
-
410
- ## 1.2.1-alpha.1
411
-
412
- ### Patch Changes
413
-
414
- - dependencies updates: ([#14119](https://github.com/mastra-ai/mastra/pull/14119))
415
- - Updated dependency [`zod-from-json-schema@^0.5.2` ↗︎](https://www.npmjs.com/package/zod-from-json-schema/v/0.5.2) (from `^0.5.0`, in `dependencies`)
416
-
417
- ## 1.2.1-alpha.0
418
-
419
- ### Patch Changes
420
-
421
- - Fixed Zod v4 schema conversion when `zod/v4` compat layer from Zod 3.25.x is used. Schemas like `ask_user` and other harness tools were not being properly converted to JSON Schema when `~standard.jsonSchema` was absent, causing `type: "None"` errors from the Anthropic API. ([#14157](https://github.com/mastra-ai/mastra/pull/14157))
422
-
423
- ## 1.2.0
424
-
425
- ### Minor Changes
426
-
427
- - Add Zod v4 and Standard Schema support ([#12238](https://github.com/mastra-ai/mastra/pull/12238))
428
-
429
- ## Zod v4 Breaking Changes
430
- - Fix all `z.record()` calls to use 2-argument form (key + value schema) as required by Zod v4
431
- - Update `ZodError.errors` to `ZodError.issues` (Zod v4 API change)
432
- - Update `@ai-sdk/provider` versions for Zod v4 compatibility
433
-
434
- ## Standard Schema Integration
435
- - Add `packages/core/src/schema/` module that re-exports from `@mastra/schema-compat`
436
- - Migrate codebase to use `PublicSchema` type for schema parameters
437
- - Use `toStandardSchema()` for normalizing schemas across Zod v3, Zod v4, AI SDK Schema, and JSON Schema
438
- - Use `standardSchemaToJSONSchema()` for JSON Schema conversion
439
-
440
- ## Schema Compatibility (@mastra/schema-compat)
441
- - Add new adapter exports: `@mastra/schema-compat/adapters/ai-sdk`, `@mastra/schema-compat/adapters/zod-v3`, `@mastra/schema-compat/adapters/json-schema`
442
- - Enhance test coverage with separate v3 and v4 test suites
443
- - Improve zod-to-json conversion with `unrepresentable: 'any'` support
444
-
445
- ## TypeScript Fixes
446
- - Resolve deep instantiation errors in client-js and model.ts
447
- - Add proper type assertions where Zod v4 inference differs
448
-
449
- **BREAKING CHANGE**: Minimum Zod version is now `^3.25.0` for v3 compatibility or `^4.0.0` for v4
450
-
451
- ### Patch Changes
452
-
453
- - Fixed Gemini supervisor agent tool calls failing with `INVALID_ARGUMENT` when delegated tool schemas include nullable fields. Fixes `#13988`. ([#14012](https://github.com/mastra-ai/mastra/pull/14012))
454
-
455
- - Fixed OpenAI and OpenAI Reasoning compat layers to ensure all properties appear in the JSON Schema required array when using processToJSONSchema. This prevents OpenAI strict mode rejections for schemas with optional, default, or nullish fields. (Fixes #12284) ([#13695](https://github.com/mastra-ai/mastra/pull/13695))
456
-
457
- ## 1.2.0-alpha.0
458
-
459
- ### Minor Changes
460
-
461
- - Add Zod v4 and Standard Schema support ([#12238](https://github.com/mastra-ai/mastra/pull/12238))
462
-
463
- ## Zod v4 Breaking Changes
464
- - Fix all `z.record()` calls to use 2-argument form (key + value schema) as required by Zod v4
465
- - Update `ZodError.errors` to `ZodError.issues` (Zod v4 API change)
466
- - Update `@ai-sdk/provider` versions for Zod v4 compatibility
467
-
468
- ## Standard Schema Integration
469
- - Add `packages/core/src/schema/` module that re-exports from `@mastra/schema-compat`
470
- - Migrate codebase to use `PublicSchema` type for schema parameters
471
- - Use `toStandardSchema()` for normalizing schemas across Zod v3, Zod v4, AI SDK Schema, and JSON Schema
472
- - Use `standardSchemaToJSONSchema()` for JSON Schema conversion
473
-
474
- ## Schema Compatibility (@mastra/schema-compat)
475
- - Add new adapter exports: `@mastra/schema-compat/adapters/ai-sdk`, `@mastra/schema-compat/adapters/zod-v3`, `@mastra/schema-compat/adapters/json-schema`
476
- - Enhance test coverage with separate v3 and v4 test suites
477
- - Improve zod-to-json conversion with `unrepresentable: 'any'` support
478
-
479
- ## TypeScript Fixes
480
- - Resolve deep instantiation errors in client-js and model.ts
481
- - Add proper type assertions where Zod v4 inference differs
482
-
483
- **BREAKING CHANGE**: Minimum Zod version is now `^3.25.0` for v3 compatibility or `^4.0.0` for v4
484
-
485
- ### Patch Changes
486
-
487
- - Fixed Gemini supervisor agent tool calls failing with `INVALID_ARGUMENT` when delegated tool schemas include nullable fields. Fixes `#13988`. ([#14012](https://github.com/mastra-ai/mastra/pull/14012))
488
-
489
- - Fixed OpenAI and OpenAI Reasoning compat layers to ensure all properties appear in the JSON Schema required array when using processToJSONSchema. This prevents OpenAI strict mode rejections for schemas with optional, default, or nullish fields. (Fixes #12284) ([#13695](https://github.com/mastra-ai/mastra/pull/13695))
490
-
491
- ## 1.1.3
492
-
493
- ### Patch Changes
494
-
495
- - Fix `ZodNull` throwing "does not support zod type: ZodNull" for Anthropic and OpenAI reasoning models. MCP tools with nullable properties in their JSON Schema produce `z.null()` which was unhandled by these provider compat layers. ([#13496](https://github.com/mastra-ai/mastra/pull/13496))
496
-
497
- ## 1.1.3-alpha.0
498
-
499
- ### Patch Changes
500
-
501
- - Fix `ZodNull` throwing "does not support zod type: ZodNull" for Anthropic and OpenAI reasoning models. MCP tools with nullable properties in their JSON Schema produce `z.null()` which was unhandled by these provider compat layers. ([#13496](https://github.com/mastra-ai/mastra/pull/13496))
502
-
503
- ## 1.1.2
504
-
505
- ### Patch Changes
506
-
507
- - Fixed Groq provider not receiving schema compatibility transformations, which caused HTTP 400 errors when AI models omitted optional parameters from workspace tool calls (e.g. list_files). Groq now correctly gets the same optional-to-nullable schema handling as OpenAI. ([#13303](https://github.com/mastra-ai/mastra/pull/13303))
508
-
509
- ## 1.1.2-alpha.0
510
-
511
- ### Patch Changes
512
-
513
- - Fixed Groq provider not receiving schema compatibility transformations, which caused HTTP 400 errors when AI models omitted optional parameters from workspace tool calls (e.g. list_files). Groq now correctly gets the same optional-to-nullable schema handling as OpenAI. ([#13303](https://github.com/mastra-ai/mastra/pull/13303))
514
-
515
- ## 1.1.1
516
-
517
- ### Patch Changes
518
-
519
- - fix(schema-compat): fix zodToJsonSchema routing for v3/v4 Zod schemas ([#13253](https://github.com/mastra-ai/mastra/pull/13253))
520
-
521
- The `zodToJsonSchema` function now reliably detects and routes Zod v3 vs v4 schemas regardless of which version the ambient `zod` import resolves to. Previously, the detection relied on checking `'toJSONSchema' in z` against the ambient `z` import, which could resolve to either v3 or v4 depending on the environment (monorepo vs global install). This caused v3 schemas to be passed to v4's `toJSONSchema()` (crashing with "Cannot read properties of undefined (reading 'def')") or v4 schemas to be passed to the v3 converter (producing schemas missing the `type` field).
522
-
523
- The fix explicitly imports `z as zV4` from `zod/v4` and routes based on the schema's own `_zod` property, making the behavior environment-independent.
524
-
525
- Also migrates all mastracode tool files from `zod/v3` to `zod` imports now that the schema-compat fix supports both versions correctly.
526
-
527
- ## 1.1.1-alpha.0
528
-
529
- ### Patch Changes
530
-
531
- - fix(schema-compat): fix zodToJsonSchema routing for v3/v4 Zod schemas ([#13253](https://github.com/mastra-ai/mastra/pull/13253))
532
-
533
- The `zodToJsonSchema` function now reliably detects and routes Zod v3 vs v4 schemas regardless of which version the ambient `zod` import resolves to. Previously, the detection relied on checking `'toJSONSchema' in z` against the ambient `z` import, which could resolve to either v3 or v4 depending on the environment (monorepo vs global install). This caused v3 schemas to be passed to v4's `toJSONSchema()` (crashing with "Cannot read properties of undefined (reading 'def')") or v4 schemas to be passed to the v3 converter (producing schemas missing the `type` field).
534
-
535
- The fix explicitly imports `z as zV4` from `zod/v4` and routes based on the schema's own `_zod` property, making the behavior environment-independent.
536
-
537
- Also migrates all mastracode tool files from `zod/v3` to `zod` imports now that the schema-compat fix supports both versions correctly.
538
-
539
- ## 1.1.0
540
-
541
- ### Minor Changes
542
-
543
- - Added [Standard Schema](https://github.com/standard-schema/standard-schema) support to `@mastra/schema-compat`. This enables interoperability with any schema library that implements the Standard Schema specification. ([#12527](https://github.com/mastra-ai/mastra/pull/12527))
544
-
545
- **New exports:**
546
- - `toStandardSchema()` - Convert Zod, JSON Schema, or AI SDK schemas to Standard Schema format
547
- - `StandardSchemaWithJSON` - Type for schemas implementing both validation and JSON Schema conversion
548
- - `InferInput`, `InferOutput` - Utility types for type inference
549
-
550
- **Example usage:**
551
-
552
- ```typescript
553
- import { toStandardSchema } from '@mastra/schema-compat/schema';
554
- import { z } from 'zod';
555
-
556
- // Convert a Zod schema to Standard Schema
557
- const zodSchema = z.object({ name: z.string(), age: z.number() });
558
- const standardSchema = toStandardSchema(zodSchema);
559
-
560
- // Use validation
561
- const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
562
-
563
- // Get JSON Schema
564
- const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
565
- ```
566
-
567
- ## 1.1.0-alpha.0
568
-
569
- ### Minor Changes
570
-
571
- - Added [Standard Schema](https://github.com/standard-schema/standard-schema) support to `@mastra/schema-compat`. This enables interoperability with any schema library that implements the Standard Schema specification. ([#12527](https://github.com/mastra-ai/mastra/pull/12527))
572
-
573
- **New exports:**
574
- - `toStandardSchema()` - Convert Zod, JSON Schema, or AI SDK schemas to Standard Schema format
575
- - `StandardSchemaWithJSON` - Type for schemas implementing both validation and JSON Schema conversion
576
- - `InferInput`, `InferOutput` - Utility types for type inference
577
-
578
- **Example usage:**
579
-
580
- ```typescript
581
- import { toStandardSchema } from '@mastra/schema-compat/schema';
582
- import { z } from 'zod';
583
-
584
- // Convert a Zod schema to Standard Schema
585
- const zodSchema = z.object({ name: z.string(), age: z.number() });
586
- const standardSchema = toStandardSchema(zodSchema);
587
-
588
- // Use validation
589
- const result = standardSchema['~standard'].validate({ name: 'John', age: 30 });
590
-
591
- // Get JSON Schema
592
- const jsonSchema = standardSchema['~standard'].jsonSchema.output({ target: 'draft-07' });
593
- ```
594
-
595
- ## 1.0.0
596
-
597
- ### Major Changes
598
-
599
- - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
600
-
601
- - Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
602
-
603
- ### Patch Changes
604
-
605
- - Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#9265](https://github.com/mastra-ai/mastra/pull/9265))
606
-
607
- Zod v4 has a bug in the single-argument form of `z.record(valueSchema)` where it incorrectly assigns the value schema to `keyType` instead of `valueType`, leaving `valueType` undefined. This causes `toJSONSchema()` to throw "Cannot read properties of undefined (reading '\_zod')" when processing schemas containing `z.record()` fields.
608
-
609
- This fix patches affected schemas before conversion by detecting records with missing `valueType` and correctly assigning the schema to `valueType` while setting `keyType` to `z.string()` (the default). The patch recursively handles nested schemas including those wrapped in `.optional()`, `.nullable()`, arrays, unions, and objects.
610
-
611
- - Embed AI types to fix peerdeps mismatches ([`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808))
612
-
613
- - Fixed agent network mode failing with "Cannot read properties of undefined" error when tools or workflows don't have an `inputSchema` defined. ([#12063](https://github.com/mastra-ai/mastra/pull/12063))
614
- - **@mastra/core:** Fixed `getRoutingAgent()` to handle tools and workflows without `inputSchema` by providing a default empty schema fallback.
615
- - **@mastra/schema-compat:** Fixed Zod v4 optional/nullable fields producing invalid JSON schema for OpenAI structured outputs. OpenAI now correctly receives `type: ["string", "null"]` instead of `anyOf` patterns that were rejected with "must have a 'type' key" error.
616
-
617
- - Fixed OpenAI schema validation error when using passthrough schemas with tools like `vectorQueryTool`. ([#11846](https://github.com/mastra-ai/mastra/pull/11846))
618
-
619
- **What was happening:** Tools using `.passthrough()` or `z.looseObject()` schemas (like the RAG `vectorQueryTool`) would fail with OpenAI models, returning the error: "Invalid schema for function: In context=('additionalProperties',), schema must have a 'type' key."
620
-
621
- **What changed:** The OpenAI schema compatibility layer now converts passthrough schemas to strict object schemas, producing valid `additionalProperties: false` instead of the invalid empty object `{}` that Zod v4 generates.
622
-
623
- Fixes #11823
624
-
625
- - Fixed "Transforms cannot be represented in JSON Schema" error when using Zod v4 with structuredOutput ([#11466](https://github.com/mastra-ai/mastra/pull/11466))
626
-
627
- When using schemas with `.optional()`, `.nullable()`, `.default()`, or `.nullish().default("")` patterns with `structuredOutput` and Zod v4, users would encounter an error because OpenAI schema compatibility layer adds transforms that Zod v4's native `toJSONSchema()` cannot handle.
628
-
629
- The fix uses Mastra's transform-safe `zodToJsonSchema` function which gracefully handles transforms by using the `unrepresentable: 'any'` option.
630
-
631
- Also exported `isZodType` utility from `@mastra/schema-compat` and updated it to detect both Zod v3 (`_def`) and Zod v4 (`_zod`) schemas.
632
-
633
- - Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
634
-
635
- - Fix OpenAI structured output compatibility for fields with `.default()` values ([#11434](https://github.com/mastra-ai/mastra/pull/11434))
636
-
637
- When using Zod schemas with `.default()` fields (e.g., `z.number().default(1)`), OpenAI's structured output API was failing with errors like `Missing '<field>' in required`. This happened because `zod-to-json-schema` doesn't include fields with defaults in the `required` array, but OpenAI requires all properties to be required.
638
-
639
- This fix converts `.default()` fields to `.nullable()` with a transform that returns the default value when `null` is received, ensuring compatibility with OpenAI's strict mode while preserving the original default value semantics.
640
-
641
- - fix(schema-compat): handle undefined values in optional fields for OpenAI compat layers ([#11469](https://github.com/mastra-ai/mastra/pull/11469))
642
-
643
- When a Zod schema has nested objects with `.partial()`, the optional fields would fail validation with "expected string, received undefined" errors. This occurred because the OpenAI schema compat layer converted `.optional()` to `.nullable()`, which only accepts `null` values, not `undefined`.
644
-
645
- Changed `.nullable()` to `.nullish()` so that optional fields now accept both `null` (when explicitly provided by the LLM) and `undefined` (when fields are omitted entirely).
646
-
647
- Fixes #11457
648
-
649
- - Fix discriminatedUnion schema information lost when json schema is converted to zod ([#10500](https://github.com/mastra-ai/mastra/pull/10500))
650
-
651
- - Fix oneOf schema conversion generating invalid JavaScript ([#11626](https://github.com/mastra-ai/mastra/pull/11626))
652
-
653
- The upstream json-schema-to-zod library generates TypeScript syntax (`reduce<z.ZodError[]>`) when converting oneOf schemas. This TypeScript generic annotation fails when evaluated at runtime with Function(), causing schema resolution to fail.
654
-
655
- The fix removes TypeScript generic syntax from the generated output, producing valid JavaScript that can be evaluated at runtime. This resolves issues where MCP tools with oneOf in their output schemas would fail validation.
656
-
657
- - Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
658
-
659
- **Changes**
660
- - **Automatic transformation**: Zod schemas are now automatically transformed for OpenAI strict mode compatibility when using OpenAI models (including reasoning models like o1, o3, o4)
661
- - **Optional field handling**: `.optional()` fields are converted to `.nullable()` with a transform that converts `null` → `undefined`, preserving optional semantics while satisfying OpenAI's strict mode requirements
662
- - **Preserves nullable fields**: Intentionally `.nullable()` fields remain unchanged
663
- - **Deep transformation**: Handles `.optional()` fields at any nesting level (objects, arrays, unions, etc.)
664
- - **JSON Schema objects**: Not transformed, only Zod schemas
665
-
666
- **Example**
667
-
668
- ```typescript
669
- const agent = new Agent({
670
- name: 'data-extractor',
671
- model: { provider: 'openai', modelId: 'gpt-4o' },
672
- instructions: 'Extract user information',
673
- });
674
-
675
- const schema = z.object({
676
- name: z.string(),
677
- age: z.number().optional(),
678
- deletedAt: z.date().nullable(),
679
- });
680
-
681
- // Schema is automatically transformed for OpenAI compatibility
682
- const result = await agent.generate('Extract: John, deleted yesterday', {
683
- structuredOutput: { schema },
684
- });
685
-
686
- // Result: { name: 'John', age: undefined, deletedAt: null }
687
- ```
688
-
689
- ## 1.0.0-beta.8
690
-
691
- ### Patch Changes
692
-
693
- - Fixed agent network mode failing with "Cannot read properties of undefined" error when tools or workflows don't have an `inputSchema` defined. ([#12063](https://github.com/mastra-ai/mastra/pull/12063))
694
- - **@mastra/core:** Fixed `getRoutingAgent()` to handle tools and workflows without `inputSchema` by providing a default empty schema fallback.
695
- - **@mastra/schema-compat:** Fixed Zod v4 optional/nullable fields producing invalid JSON schema for OpenAI structured outputs. OpenAI now correctly receives `type: ["string", "null"]` instead of `anyOf` patterns that were rejected with "must have a 'type' key" error.
696
-
697
- ## 1.0.0-beta.7
698
-
699
- ### Patch Changes
700
-
701
- - Fixed OpenAI schema validation error when using passthrough schemas with tools like `vectorQueryTool`. ([#11846](https://github.com/mastra-ai/mastra/pull/11846))
702
-
703
- **What was happening:** Tools using `.passthrough()` or `z.looseObject()` schemas (like the RAG `vectorQueryTool`) would fail with OpenAI models, returning the error: "Invalid schema for function: In context=('additionalProperties',), schema must have a 'type' key."
704
-
705
- **What changed:** The OpenAI schema compatibility layer now converts passthrough schemas to strict object schemas, producing valid `additionalProperties: false` instead of the invalid empty object `{}` that Zod v4 generates.
706
-
707
- Fixes #11823
708
-
709
- ## 1.0.0-beta.6
710
-
711
- ### Patch Changes
712
-
713
- - Fix oneOf schema conversion generating invalid JavaScript ([#11626](https://github.com/mastra-ai/mastra/pull/11626))
714
-
715
- The upstream json-schema-to-zod library generates TypeScript syntax (`reduce<z.ZodError[]>`) when converting oneOf schemas. This TypeScript generic annotation fails when evaluated at runtime with Function(), causing schema resolution to fail.
716
-
717
- The fix removes TypeScript generic syntax from the generated output, producing valid JavaScript that can be evaluated at runtime. This resolves issues where MCP tools with oneOf in their output schemas would fail validation.
718
-
719
- ## 1.0.0-beta.5
720
-
721
- ### Patch Changes
722
-
723
- - Fixed "Transforms cannot be represented in JSON Schema" error when using Zod v4 with structuredOutput ([#11466](https://github.com/mastra-ai/mastra/pull/11466))
724
-
725
- When using schemas with `.optional()`, `.nullable()`, `.default()`, or `.nullish().default("")` patterns with `structuredOutput` and Zod v4, users would encounter an error because OpenAI schema compatibility layer adds transforms that Zod v4's native `toJSONSchema()` cannot handle.
726
-
727
- The fix uses Mastra's transform-safe `zodToJsonSchema` function which gracefully handles transforms by using the `unrepresentable: 'any'` option.
728
-
729
- Also exported `isZodType` utility from `@mastra/schema-compat` and updated it to detect both Zod v3 (`_def`) and Zod v4 (`_zod`) schemas.
730
-
731
- - fix(schema-compat): handle undefined values in optional fields for OpenAI compat layers ([#11469](https://github.com/mastra-ai/mastra/pull/11469))
732
-
733
- When a Zod schema has nested objects with `.partial()`, the optional fields would fail validation with "expected string, received undefined" errors. This occurred because the OpenAI schema compat layer converted `.optional()` to `.nullable()`, which only accepts `null` values, not `undefined`.
734
-
735
- Changed `.nullable()` to `.nullish()` so that optional fields now accept both `null` (when explicitly provided by the LLM) and `undefined` (when fields are omitted entirely).
736
-
737
- Fixes #11457
738
-
739
- ## 1.0.0-beta.4
740
-
741
- ### Patch Changes
742
-
743
- - Fix OpenAI structured output compatibility for fields with `.default()` values ([#11434](https://github.com/mastra-ai/mastra/pull/11434))
744
-
745
- When using Zod schemas with `.default()` fields (e.g., `z.number().default(1)`), OpenAI's structured output API was failing with errors like `Missing '<field>' in required`. This happened because `zod-to-json-schema` doesn't include fields with defaults in the `required` array, but OpenAI requires all properties to be required.
746
-
747
- This fix converts `.default()` fields to `.nullable()` with a transform that returns the default value when `null` is received, ensuring compatibility with OpenAI's strict mode while preserving the original default value semantics.
748
-
749
- ## 1.0.0-beta.3
750
-
751
- ### Patch Changes
752
-
753
- - Embed AI types to fix peerdeps mismatches ([`9650cce`](https://github.com/mastra-ai/mastra/commit/9650cce52a1d917ff9114653398e2a0f5c3ba808))
754
-
755
- ## 1.0.0-beta.2
756
-
757
- ### Patch Changes
758
-
759
- - Fix discriminatedUnion schema information lost when json schema is converted to zod ([#10500](https://github.com/mastra-ai/mastra/pull/10500))
760
-
761
- ## 1.0.0-beta.1
762
-
763
- ### Patch Changes
764
-
765
- - Fixed OpenAI schema compatibility when using `agent.generate()` or `agent.stream()` with `structuredOutput`. ([#10366](https://github.com/mastra-ai/mastra/pull/10366))
766
-
767
- ## Changes
768
- - **Automatic transformation**: Zod schemas are now automatically transformed for OpenAI strict mode compatibility when using OpenAI models (including reasoning models like o1, o3, o4)
769
- - **Optional field handling**: `.optional()` fields are converted to `.nullable()` with a transform that converts `null` → `undefined`, preserving optional semantics while satisfying OpenAI's strict mode requirements
770
- - **Preserves nullable fields**: Intentionally `.nullable()` fields remain unchanged
771
- - **Deep transformation**: Handles `.optional()` fields at any nesting level (objects, arrays, unions, etc.)
772
- - **JSON Schema objects**: Not transformed, only Zod schemas
773
-
774
- ## Example
775
-
776
- ```typescript
777
- const agent = new Agent({
778
- name: 'data-extractor',
779
- model: { provider: 'openai', modelId: 'gpt-4o' },
780
- instructions: 'Extract user information',
781
- });
782
-
783
- const schema = z.object({
784
- name: z.string(),
785
- age: z.number().optional(),
786
- deletedAt: z.date().nullable(),
787
- });
788
-
789
- // Schema is automatically transformed for OpenAI compatibility
790
- const result = await agent.generate('Extract: John, deleted yesterday', {
791
- structuredOutput: { schema },
792
- });
793
-
794
- // Result: { name: 'John', age: undefined, deletedAt: null }
795
- ```
796
-
797
- ## 1.0.0-beta.0
798
-
799
- ### Major Changes
800
-
801
- - Bump minimum required Node.js version to 22.13.0 ([#9706](https://github.com/mastra-ai/mastra/pull/9706))
802
-
803
- - Mark as stable ([`83d5942`](https://github.com/mastra-ai/mastra/commit/83d5942669ce7bba4a6ca4fd4da697a10eb5ebdc))
804
-
805
- ### Patch Changes
806
-
807
- - Fix Zod v4 toJSONSchema bug with z.record() single-argument form ([#9265](https://github.com/mastra-ai/mastra/pull/9265))
808
-
809
- Zod v4 has a bug in the single-argument form of `z.record(valueSchema)` where it incorrectly assigns the value schema to `keyType` instead of `valueType`, leaving `valueType` undefined. This causes `toJSONSchema()` to throw "Cannot read properties of undefined (reading '\_zod')" when processing schemas containing `z.record()` fields.
810
-
811
- This fix patches affected schemas before conversion by detecting records with missing `valueType` and correctly assigning the schema to `valueType` while setting `keyType` to `z.string()` (the default). The patch recursively handles nested schemas including those wrapped in `.optional()`, `.nullable()`, arrays, unions, and objects.
812
-
813
- - Improved reliability of string field types in tool schema compatibility ([#9266](https://github.com/mastra-ai/mastra/pull/9266))
814
-
815
- ## 0.11.4
816
-
817
- ### Patch Changes
818
-
819
- - Fixes an issue when the OpenAI reasoning schema compatibility layer was calling defaultValue() as a function, which works in Zod v3 but fails in Zod v4 where defaultValue is stored directly as a value. ([#8090](https://github.com/mastra-ai/mastra/pull/8090))
820
-
821
- ## 0.11.4-alpha.0
822
-
823
- ### Patch Changes
824
-
825
- - Fixes an issue when the OpenAI reasoning schema compatibility layer was calling defaultValue() as a function, which works in Zod v3 but fails in Zod v4 where defaultValue is stored directly as a value. ([#8090](https://github.com/mastra-ai/mastra/pull/8090))
826
-
827
- ## 0.11.3
828
-
829
- ### Patch Changes
830
-
831
- - Change SchemaCompat zodToJsonSchema ref strategy from none to relative, leading to less schema warnings and smaller converted schema sizes ([#7697](https://github.com/mastra-ai/mastra/pull/7697))
832
-
833
- ## 0.11.3-alpha.0
834
-
835
- ### Patch Changes
836
-
837
- - Change SchemaCompat zodToJsonSchema ref strategy from none to relative, leading to less schema warnings and smaller converted schema sizes ([#7697](https://github.com/mastra-ai/mastra/pull/7697))
838
-
839
- ## 0.11.2
840
-
841
- ### Patch Changes
842
-
843
- - ab48c97: dependencies updates:
844
- - Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
845
- - 637f323: Fix issue with some compilers and calling zod v4's toJSONSchema function
846
- - de3cbc6: Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
847
- - 45e4d39: Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
848
-
849
- ## 0.11.2-alpha.3
850
-
851
- ### Patch Changes
852
-
853
- - [#7350](https://github.com/mastra-ai/mastra/pull/7350) [`45e4d39`](https://github.com/mastra-ai/mastra/commit/45e4d391a2a09fc70c48e4d60f505586ada1ba0e) Thanks [@LekoArts](https://github.com/LekoArts)! - Try fixing the `Attempted import error: 'z'.'toJSONSchema' is not exported from 'zod'` error by tricking the compiler
854
-
855
- ## 0.11.2-alpha.2
856
-
857
- ### Patch Changes
858
-
859
- - [#7343](https://github.com/mastra-ai/mastra/pull/7343) [`de3cbc6`](https://github.com/mastra-ai/mastra/commit/de3cbc61079211431bd30487982ea3653517278e) Thanks [@LekoArts](https://github.com/LekoArts)! - Update the `package.json` file to include additional fields like `repository`, `homepage` or `files`.
860
-
861
- ## 0.11.2-alpha.1
862
-
863
- ### Patch Changes
864
-
865
- - [#5816](https://github.com/mastra-ai/mastra/pull/5816) [`ab48c97`](https://github.com/mastra-ai/mastra/commit/ab48c979098ea571faf998a55d3a00e7acd7a715) Thanks [@dane-ai-mastra](https://github.com/apps/dane-ai-mastra)! - dependencies updates:
866
- - Updated dependency [`zod-to-json-schema@^3.24.6` ↗︎](https://www.npmjs.com/package/zod-to-json-schema/v/3.24.6) (from `^3.24.5`, in `dependencies`)
867
-
868
- ## 0.11.2-alpha.0
869
-
870
- ### Patch Changes
871
-
872
- - [#7121](https://github.com/mastra-ai/mastra/pull/7121) [`637f323`](https://github.com/mastra-ai/mastra/commit/637f32371d79a8f78c52c0d53411af0915fcec67) Thanks [@DanielSLew](https://github.com/DanielSLew)! - Fix issue with some compilers and calling zod v4's toJSONSchema function
873
-
874
- ## 0.11.1
875
-
876
- ### Patch Changes
877
-
878
- - [`c6113ed`](https://github.com/mastra-ai/mastra/commit/c6113ed7f9df297e130d94436ceee310273d6430) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix peerdpes for @mastra/core
879
-
880
- ## 0.11.0
881
-
882
- ### Minor Changes
883
-
884
- - [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
885
-
886
- ### Patch Changes
887
-
888
- - [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
889
-
890
- - [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
891
-
892
- - [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
893
-
894
- ## 0.11.0-alpha.2
895
-
896
- ### Minor Changes
897
-
898
- - [#7032](https://github.com/mastra-ai/mastra/pull/7032) [`1191ce9`](https://github.com/mastra-ai/mastra/commit/1191ce946b40ed291e7877a349f8388e3cff7e5c) Thanks [@wardpeet](https://github.com/wardpeet)! - Bump zod peerdep to 3.25.0 to support both v3/v4
899
-
900
- ## 0.10.6-alpha.1
901
-
902
- ### Patch Changes
903
-
904
- - [#7028](https://github.com/mastra-ai/mastra/pull/7028) [`da58ccc`](https://github.com/mastra-ai/mastra/commit/da58ccc1f2ac33da0cb97b00443fc6208b45bdec) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix exportsmap
905
-
906
- ## 0.10.6-alpha.0
907
-
908
- ### Patch Changes
909
-
910
- - [#6982](https://github.com/mastra-ai/mastra/pull/6982) [`94e9f54`](https://github.com/mastra-ai/mastra/commit/94e9f547d66ef7cd01d9075ab53b5ca9a1cae100) Thanks [@wardpeet](https://github.com/wardpeet)! - Fix AI peerdeps for NPM install
911
-
912
- - [#6944](https://github.com/mastra-ai/mastra/pull/6944) [`a93f3ba`](https://github.com/mastra-ai/mastra/commit/a93f3ba05eef4cf17f876d61d29cf0841a9e70b7) Thanks [@wardpeet](https://github.com/wardpeet)! - Add support for zod v4
913
-
914
- ## 0.10.7
915
-
916
- ### Patch Changes
917
-
918
- - dd94a26: Dont rely on the full language model for schema compat
919
- - 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
920
- - ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
921
-
922
- ## 0.10.7-alpha.1
923
-
924
- ### Patch Changes
925
-
926
- - ae2eb63: Handle regex checks better, return description as a string rather than an object with pattern and flags.
927
-
928
- ## 0.10.7-alpha.0
929
-
930
- ### Patch Changes
931
-
932
- - dd94a26: Dont rely on the full language model for schema compat
933
- - 2fff911: Fix vnext working memory tool schema when model is incompatible with schema
934
-
935
- ## 0.10.6
936
-
937
- ### Patch Changes
938
-
939
- - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
940
-
941
- ## 0.10.6-alpha.0
942
-
943
- ### Patch Changes
944
-
945
- - 4a406ec: fixes TypeScript declaration file imports to ensure proper ESM compatibility
946
-
947
- ## 0.10.5
948
-
949
- ### Patch Changes
950
-
951
- - 4da943f: Fix Cannot read properties of undefined (reading 'typeName') in schema compat check
952
-
953
- ## 0.10.5-alpha.0
954
-
955
- ### Patch Changes
956
-
957
- - 4da943f: Fix Cannot read properties of undefined (reading 'typeName') in schema compat check
958
-
959
- ## 0.10.4
960
-
961
- ### Patch Changes
962
-
963
- - 0c85311: Fix Google models ZodNull tool schema handling
964
-
965
- ## 0.10.4-alpha.0
966
-
967
- ### Patch Changes
968
-
969
- - 0c85311: Fix Google models ZodNull tool schema handling
970
-
971
- ## 0.10.3
972
-
973
- ### Patch Changes
974
-
975
- - 98bbe5a: Claude cannot handle tuple schemas now.
976
- - a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
977
-
978
- ## 0.10.3-alpha.1
979
-
980
- ### Patch Changes
981
-
982
- - a853c43: Allow for object.passthrough in schema compat (aka MCP tool support).
983
-
984
- ## 0.10.3-alpha.0
985
-
986
- ### Patch Changes
987
-
988
- - 98bbe5a: Claude cannot handle tuple schemas now.
989
-
990
- ## 0.10.2
991
-
992
- ### Patch Changes
993
-
994
- - f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
995
- - f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra
996
-
997
- ## 0.10.2-alpha.3
998
-
999
- ### Patch Changes
1000
-
1001
- - f6fd25f: Updates @mastra/schema-compat to allow all zod schemas. Uses @mastra/schema-compat to apply schema transformations to agent output schema.
1002
-
1003
- ## 0.10.2-alpha.2
1004
-
1005
- ### Patch Changes
1006
-
1007
- - f9816ae: Create @mastra/schema-compat package to extract the schema compatibility layer to be used outside of mastra