npm / @mastra/schema-compat
@mastra/schema-compat
What changed in @mastra/schema-compat 1, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-25.
5 breaking7 new APIs and options1 performance5 behavior and defaults55 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli init@mastra/schema-compat 173 changes
Breaking changes 5
Plain JSON Schema formats are now enforced by toStandardSchema(), so invalid values are rejected; schemas from Zod or other Standard Schema libraries are unaffected.
Direct toStandardSchema() callers can set ajvOptions.validateFormats to false to retain the previous behavior; MCP tool inputs, core tool schemas, and structured output do not expose this opt-out.
Tool execute functions now receive the transformed output type for Standard Schemas instead of a union of input and output types.
Optional fields inside nullable or nullish objects or arrays returned as null are now dropped, matching behavior for non-nullable parents.
The minimum required Node.js version is now 22.13.0.
New APIs and options 7
Set this option to
trueto keep strict mode for structured output schemas with free-form keys.Adds support for Standard Schema.
Adds support for Zod v4 schemas.
Adds a utility type for type inference.
Adds a type for schemas implementing both validation and JSON Schema conversion.
Converts Zod, JSON Schema, or AI SDK schemas to Standard Schema format, enabling interoperability with Standard Schema implementations.
The utility is exported and detects both Zod v3 (
_def) and Zod v4 (_zod) schemas.
Performance 1
Reduced TypeScript memory usage for applications that define many tools with Zod schemas.
Behavior and default changes 5
Numeric, boolean, and empty-string literal fields are sent as their plain type with allowed values in the description; string enums from external JSON Schema that omit type now get type: "string". Tool arguments remain validated against the original schema.
Tool requestContextSchema accepts Standard Schemas that transform their input, and tool request context is typed with the transformed output.
Meta and DeepSeek schemas now move numeric constraints into the field description instead of sending raw number bounds or minimum/maximum keywords to the model.
The package is marked as stable.
Zod schemas used with
agent.generate()oragent.stream()are automatically transformed for OpenAI strict mode; optional fields are converted while intentionally nullable fields remain unchanged. JSON Schema objects are not transformed.
Fixes and other changes 55
formatMinimum and formatMaximum constraints on date and date-time values now take effect.
OpenAPI request parameter and body schemas are generated from accepted inputs, while response schemas remain based on emitted outputs; Zod v4 defaults and transformations now expose the correct representations.
Optional tool inputs are left empty instead of being filled with made-up values when the Azure deployment name contains an OpenAI model name.
OpenAI models can leave optional tool inputs empty when those inputs accept more than one type, rather than filling them with made-up values.
Structured output with free-form keys, such as
z.record(z.string(), z.string()), now works on OpenAI; these schemas are sent without strict mode.OpenAI strict-mode schema preparation no longer rejects allOf object schemas with properties named constructor, toString, or __proto__.
Tools with optional number parameters that have a format now return responses as expected instead of failing silently.
Nullable Zod v4 enums and literals now include null among exported allowed values, so tool parameters, OpenAPI schemas and dataset schemas match the Zod schema.
Claude on Vertex now uses the Anthropic compatibility layer, preserving nullable parameters as JSON Schema
type: ['string', 'null']; Gemini on Vertex is unchanged.JSON Schema adapter declarations use bundled Ajv types, so consumers no longer need a separate Ajv installation.
Fixed loading from CommonJS, which previously failed with “jsonSchemaToZod is not a function.”
Generated schemas use
z.record(z.string(), value)so schemas withadditionalPropertiesorpatternPropertiesvalidate correctly on the noted Zod versions.Recursively removes validation keywords rejected by OpenAI strict mode, including in referenced schemas, and folds their intent into descriptions.
Avoids duplicating nested optional object and array definitions, preventing compatible MCP tools from being rejected.
Optional nested properties with multiple types no longer produce exponentially large OpenAI tool payloads; payload growth remains linear as schemas become more deeply nested.
For Gemini via OpenRouter, properties without a Gemini-compatible type are rewritten into a permissive anyOf instead of being dropped, keeping expected tool fields in the contract.
The OpenAI compatibility layer removes the unsupported propertyNames keyword from structured output schemas, allowing requests using z.record() to be accepted.
Tool execute-time validation for Zod tools on Anthropic Claude 3.5 Haiku skips string min/max checks removed from the model-facing JSON Schema while preserving other validation semantics.
Schema conversion for Zod v3 is fixed for CommonJS consumers.
Fixed Claude requests failing when tool inputs use a top-level union of object schemas.
Fixes crashes when converting Zod v4 schemas containing z.record(...) with a provider compat layer attached, covering older Zod v4 versions and versions that expose ~standard.jsonSchema.
In Zod v4, nullable or optional schemas wrapping unsupported inner types, such as tuples, are passed through unchanged instead of being processed and rejected.
The Zod v4 string handler now preserves formats without textual descriptions as validation, so schemas using them keep rejecting invalid input.
Workflow and step type inference with Zod schemas is significantly faster and no longer causes TypeScript crashes or depth errors.
The Zod v4 schema handler now describes min and max date bounds according to Zod semantics, avoiding swapped or impossible constraints sent to the model.
Fixed a type error when passing jsonSchema() or a Schema object from @ai-sdk/provider-utils as inputSchema, so no cast is needed.
Fixed schema compatibility type declarations so JSON Schema types are bundled correctly.
Rewrites JSON Schema 2020-12 keywords into the OpenAPI 3.0 Schema Object subset Gemini expects, fixing REST tool calls for discriminated unions, lazy schemas, and tuples.
Generated schemas for Zod 4 transforms now describe the pre-transform input the model must produce, fixing structured output and tool calling.
Fixed schema conversion so Gemini accepts broad nullable tool parameters.
MCP tools using JSON Schema draft 2020-12 now validate correctly instead of throwing “no schema with key or ref” errors.
MCP tools with recursive JSON Schema refs stay serializable when loaded.
Improved compatibility for structured outputs and tool calls, fixing validation for optional, nullable, and defaulted fields and ISO date strings returned for date fields.
Fixed ESM imports for Zod JSON Schema helpers, avoiding createRequire-related issues while preserving support for zod/v3 and zod/v4.
Mastra agent and client structured-output APIs accept schemas from either zod/v3 or zod/v4, with TypeScript compatibility for both.
The Zod v4 adapter translates Mastra draft target names to Zod v4 names, preventing invalid-target warnings and restoring the generated $schema field.
The Zod v3 adapter supports
draft-2020-12anddraft-04targets and translateszod-to-json-schematarget names to standard-schema target names, fixing unsupported-target errors when serializing tool schemas.MCP tools using allOf in their JSON Schema no longer throw an unsupported ZodIntersection error; intersection types are flattened and merged into a single object schema across provider compatibility layers.
Lazily loads createRequire to fix an “Uncaught (in promise) TypeError: lzt.createRequire is not a function” error.
The fallback now uses Node.js createRequire instead of esbuild’s require shim, fixing the “Dynamic require of zod/v4 is not supported” error when consumed by ESM bundles.
Published types now allow AI SDK v5 schemas to resolve correctly for consumers.
Improved schema conversion detection so JSON Schema generation works more reliably across runtime setups and avoids false
z.toJSONSchema is not availableerrors for compatible Zod versions.Fixed conversion to JSON Schema when using the Zod 3.25.x zod/v4 compat layer without ~standard.jsonSchema, preventing type: "None" errors from the Anthropic API.
Anthropic and OpenAI reasoning model compatibility layers now handle ZodNull, avoiding errors when MCP tools have nullable JSON Schema properties.
Groq now receives optional-to-nullable schema handling like OpenAI, preventing HTTP 400 errors when models omit optional parameters from workspace tool calls.
Routes Zod v3 and v4 schemas based on the schema's own _zod property, avoiding environment-dependent converter selection.
Default fields are converted to nullable fields with a transform that restores the default when null is received, satisfying OpenAI strict mode while preserving default semantics.
JSON Schema conversion to Zod no longer loses discriminatedUnion schema information.
Conversion of oneOf schemas removes TypeScript generic syntax from generated output so it can be evaluated as JavaScript at runtime.
Zod v4 optional and nullable fields now produce valid OpenAI structured-output JSON schema, using a type array instead of rejected anyOf patterns.
Optional fields in nested partial objects now use nullish handling so they accept both null and undefined.
The OpenAI compatibility layer converts passthrough schemas to strict object schemas with
additionalProperties: false.Reliability of string field types in tool schema compatibility is improved.
Structured-output conversion uses Mastra's transform-safe
zodToJsonSchemafunction withunrepresentable: 'any'to handle Zod v4 transforms.Schema conversion now handles Zod v4's single-argument record form by assigning the value schema to valueType and the default string schema to keyType.