Skip to content

Conversation

ro0sterjam
Copy link

In interopZodTransformInputSchema, need to make a shallow copy of the schema before replacing the properties rather than replacing in place to prevent mutation of underlying schema.

Doing so however breaks the OpenAI integration because it takes advantage of the underlying schema being mutated.

Thus I created a new interopZodSanitizeSchema to be called by the OpenAI integration to allow for independent sanitization separate from toJsonSchema.

Note: I was unable to determine how best to write a unit/integration test for OpenAI to ensure that it works with transform on schemas. But I was able to validate live.

Fixes #9100

Copy link

changeset-bot bot commented Oct 5, 2025

⚠️ No Changeset found

Latest commit: 047002c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Oct 5, 2025

@ro0sterjam is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Oct 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Updated (UTC)
langchainjs-docs Ignored Ignored Oct 5, 2025 8:40pm

@ro0sterjam ro0sterjam force-pushed the fix-transform-input-schema-mutate branch from a6b992c to 047002c Compare October 5, 2025 20:40
) as ZodObjectV4;
return toJSONSchema(strictSchema);
} else {
return toJSONSchema(schema);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I correct to assume that toJSONSchema(schema) was a typo and that it should have been toJSONSchema(inputSchema)?

If not, please let me know, as this PR effectively makes that change.

Comment on lines +753 to +755
const outputShape: Mutable<z4.$ZodShape> = {
...outputSchema._zod.def.shape,
};
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primary fix here.

* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
* @returns The sanitized Zod schema.
*/
export function interopZodSanitizeSchema(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted so that it can be called independently here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calling withStructuredOutput with schema modifies schema and removes transform() configurations
1 participant