unstale

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

@unstale/cli on npm

@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.

    1.4.0release notes

  • 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.

    1.4.0release notes

  • Tool execute functions now receive the transformed output type for Standard Schemas instead of a union of input and output types.

    1.3.14release notes

  • Optional fields inside nullable or nullish objects or arrays returned as null are now dropped, matching behavior for non-nullable parents.

    1.3.12release notes

  • The minimum required Node.js version is now 22.13.0.

    1.0.0release notes

New APIs and options 7

  • Set this option to true to keep strict mode for structured output schemas with free-form keys.

    1.3.15release notes

  • Adds support for Standard Schema.

    1.2.0release notes

  • Adds support for Zod v4 schemas.

    1.2.0release notes

  • Adds a utility type for type inference.

    1.1.0release notes

  • Adds a type for schemas implementing both validation and JSON Schema conversion.

    1.1.0release notes

  • Converts Zod, JSON Schema, or AI SDK schemas to Standard Schema format, enabling interoperability with Standard Schema implementations.

    1.1.0release notes

  • The utility is exported and detects both Zod v3 (_def) and Zod v4 (_zod) schemas.

    1.0.0release notes

Performance 1

  • Reduced TypeScript memory usage for applications that define many tools with Zod schemas.

    1.3.10release notes

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.

    1.4.0release notes

  • Tool requestContextSchema accepts Standard Schemas that transform their input, and tool request context is typed with the transformed output.

    1.3.14release notes

  • 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.

    1.3.4release notes

  • The package is marked as stable.

    1.0.0release notes

  • Zod schemas used with agent.generate() or agent.stream() are automatically transformed for OpenAI strict mode; optional fields are converted while intentionally nullable fields remain unchanged. JSON Schema objects are not transformed.

    1.0.0release notes

Fixes and other changes 55

  • formatMinimum and formatMaximum constraints on date and date-time values now take effect.

    1.4.0release notes

  • 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.

    1.4.0release notes

  • Optional tool inputs are left empty instead of being filled with made-up values when the Azure deployment name contains an OpenAI model name.

    1.3.15release notes

  • OpenAI models can leave optional tool inputs empty when those inputs accept more than one type, rather than filling them with made-up values.

    1.3.15release notes

  • 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.

    1.3.15release notes

  • OpenAI strict-mode schema preparation no longer rejects allOf object schemas with properties named constructor, toString, or __proto__.

    1.3.13release notes

  • Tools with optional number parameters that have a format now return responses as expected instead of failing silently.

    1.3.12release notes

  • 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.

    1.3.12release notes

  • Claude on Vertex now uses the Anthropic compatibility layer, preserving nullable parameters as JSON Schema type: ['string', 'null']; Gemini on Vertex is unchanged.

    1.3.11release notes

  • JSON Schema adapter declarations use bundled Ajv types, so consumers no longer need a separate Ajv installation.

    1.3.11release notes

  • Fixed loading from CommonJS, which previously failed with “jsonSchemaToZod is not a function.”

    1.3.11release notes

  • Generated schemas use z.record(z.string(), value) so schemas with additionalProperties or patternProperties validate correctly on the noted Zod versions.

    1.3.11release notes

  • Recursively removes validation keywords rejected by OpenAI strict mode, including in referenced schemas, and folds their intent into descriptions.

    1.3.10release notes

  • Avoids duplicating nested optional object and array definitions, preventing compatible MCP tools from being rejected.

    1.3.9release notes

  • Optional nested properties with multiple types no longer produce exponentially large OpenAI tool payloads; payload growth remains linear as schemas become more deeply nested.

    1.3.7release notes

  • 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.

    1.3.6release notes

  • The OpenAI compatibility layer removes the unsupported propertyNames keyword from structured output schemas, allowing requests using z.record() to be accepted.

    1.3.6release notes

  • 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.

    1.3.6release notes

  • Schema conversion for Zod v3 is fixed for CommonJS consumers.

    1.3.6release notes

  • Fixed Claude requests failing when tool inputs use a top-level union of object schemas.

    1.3.5release notes

  • 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.

    1.3.4release notes

  • In Zod v4, nullable or optional schemas wrapping unsupported inner types, such as tuples, are passed through unchanged instead of being processed and rejected.

    1.3.3release notes

  • The Zod v4 string handler now preserves formats without textual descriptions as validation, so schemas using them keep rejecting invalid input.

    1.3.2release notes

  • Workflow and step type inference with Zod schemas is significantly faster and no longer causes TypeScript crashes or depth errors.

    1.3.2release notes

  • 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.

    1.3.2release notes

  • Fixed a type error when passing jsonSchema() or a Schema object from @ai-sdk/provider-utils as inputSchema, so no cast is needed.

    1.3.1release notes

  • Fixed schema compatibility type declarations so JSON Schema types are bundled correctly.

    1.2.12release notes

  • 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.

    1.2.11release notes

  • Generated schemas for Zod 4 transforms now describe the pre-transform input the model must produce, fixing structured output and tool calling.

    1.2.11release notes

  • Fixed schema conversion so Gemini accepts broad nullable tool parameters.

    1.2.10release notes

  • MCP tools using JSON Schema draft 2020-12 now validate correctly instead of throwing “no schema with key or ref” errors.

    1.2.9release notes

  • MCP tools with recursive JSON Schema refs stay serializable when loaded.

    1.2.9release notes

  • Improved compatibility for structured outputs and tool calls, fixing validation for optional, nullable, and defaulted fields and ISO date strings returned for date fields.

    1.2.8release notes

  • Fixed ESM imports for Zod JSON Schema helpers, avoiding createRequire-related issues while preserving support for zod/v3 and zod/v4.

    1.2.7release notes

  • Mastra agent and client structured-output APIs accept schemas from either zod/v3 or zod/v4, with TypeScript compatibility for both.

    1.2.7release notes

  • The Zod v4 adapter translates Mastra draft target names to Zod v4 names, preventing invalid-target warnings and restoring the generated $schema field.

    1.2.6release notes

  • The Zod v3 adapter supports draft-2020-12 and draft-04 targets and translates zod-to-json-schema target names to standard-schema target names, fixing unsupported-target errors when serializing tool schemas.

    1.2.6release notes

  • 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.

    1.2.5release notes

  • Lazily loads createRequire to fix an “Uncaught (in promise) TypeError: lzt.createRequire is not a function” error.

    1.2.4release notes

  • 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.

    1.2.3release notes

  • Published types now allow AI SDK v5 schemas to resolve correctly for consumers.

    1.2.2release notes

  • Improved schema conversion detection so JSON Schema generation works more reliably across runtime setups and avoids false z.toJSONSchema is not available errors for compatible Zod versions.

    1.2.2release notes

  • 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.

    1.2.1release notes

  • Anthropic and OpenAI reasoning model compatibility layers now handle ZodNull, avoiding errors when MCP tools have nullable JSON Schema properties.

    1.1.3release notes

  • Groq now receives optional-to-nullable schema handling like OpenAI, preventing HTTP 400 errors when models omit optional parameters from workspace tool calls.

    1.1.2release notes

  • Routes Zod v3 and v4 schemas based on the schema's own _zod property, avoiding environment-dependent converter selection.

    1.1.1release notes

  • 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.

    1.0.0release notes

  • JSON Schema conversion to Zod no longer loses discriminatedUnion schema information.

    1.0.0release notes

  • Conversion of oneOf schemas removes TypeScript generic syntax from generated output so it can be evaluated as JavaScript at runtime.

    1.0.0release notes

  • Zod v4 optional and nullable fields now produce valid OpenAI structured-output JSON schema, using a type array instead of rejected anyOf patterns.

    1.0.0release notes

  • Optional fields in nested partial objects now use nullish handling so they accept both null and undefined.

    1.0.0release notes

  • The OpenAI compatibility layer converts passthrough schemas to strict object schemas with additionalProperties: false.

    1.0.0release notes

  • Reliability of string field types in tool schema compatibility is improved.

    1.0.0release notes

  • Structured-output conversion uses Mastra's transform-safe zodToJsonSchema function with unrepresentable: 'any' to handle Zod v4 transforms.

    1.0.0release notes

  • 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.

    1.0.0release notes