#24773·mastra

[BUG] Strict schema preparation rejects allOf properties named constructor or toString

Author: zhangxinping666Created Sep 23, 2026Updated Sep 30, 2026
LabelsbugToolseffort:lowimpact:lowstatus: auto-triaged@mastra/core

Describe the Bug

prepareJsonSchemaForOpenAIStrictMode rejects otherwise mergeable allOf object schemas when a property is named constructor, toString, or hasOwnProperty. The field can appear in only one branch, yet the error says it is defined differently in multiple branches. Renaming the field to name succeeds.

In mergeAllOfSubschemas, mergedProps is an ordinary object and propName in mergedProps also matches inherited properties from Object.prototype. This incorrectly treats those inherited values as earlier schema definitions. An own __proto__ property also fails.

The helper is called when preparing OpenAI strict structured output, before the provider request. This also reproduces with Zod v3 object intersections converted through zodToJsonSchema; no API key or model call is needed.

Steps To Reproduce

At upstream commit 2a832580e3cf3efcdb4be3355eaa9a02929b3a2c, after installing the workspace dependencies, save this as repro-allof.ts in the repository root:

typescript
import { prepareJsonSchemaForOpenAIStrictMode } from "./packages/schema-compat/src/zod-to-json.ts";

console.log(prepareJsonSchemaForOpenAIStrictMode({
  allOf: [
    { type: "object", properties: { constructor: { type: "string" } } },
    { type: "object", properties: { age: { type: "number" } } },
  ],
}));

Run pnpm exec tsx repro-allof.ts.

Actual result:

Cannot flatten allOf for OpenAI strict mode: property "constructor" is defined differently in multiple branches

The linked regression tests fail on the unmodified implementation and pass with the proposed fix.

Link to Minimal Reproducible Example

https://github.com/zhangxinping666/mastra/blob/93022d977d74c10e59fec841000f5acf0bee8712/packages/schema-compat/src/zod-to-json.test.ts#L992-L1022

Expected Behavior

Merge the two distinct fields successfully, preserving constructor and age as own properties, with both fields required and additionalProperties: false. Identical duplicate definitions should still merge, while genuinely conflicting definitions should still throw.

Environment Information

bash
Mastra source commit: 2a832580e3cf3efcdb4be3355eaa9a02929b3a2c
Package: @mastra/schema-compat 1.3.11-alpha.1
OS: Windows
Node.js: 22.15.1 (reproduction and tests), 24.19.0 (lint and build)
pnpm: 11.21.0
Provider/browser: not required; deterministic schema conversion

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue