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-10-20.
2 breaking1 new APIs and options1 performance2 behavior and defaults36 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli init@mastra/schema-compat 142 changes
Breaking changes 2
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.
New APIs and options 1
Set this option to
trueto keep strict mode for structured output schemas with free-form keys.
Performance 1
Reduced TypeScript memory usage for applications that define many tools with Zod schemas.
Behavior and default changes 2
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.
Fixes and other changes 36
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.