Skip to content

Conversation

@ro0sterjam
Copy link

@ro0sterjam ro0sterjam commented Oct 5, 2025

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 as part of the first call to toJsonSchema. Thus when it reaches toJSONSchemaV4 from zod, it already assumes that the transforms have been stripped.

Since this PR fixes the underlying mutation, this assumption no longer holds, so I have to manually make sure that the downstream schema passed to zod's toJSONSchemaV4 runs through the transform stripping logic.

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 5, 2025

⚠️ No Changeset found

Latest commit: 15cd573

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

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

@vercel
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
@christian-bromann
Copy link
Member

christian-bromann commented Oct 8, 2025

Really appreciate you taking the time to open this PR, @ro0sterjam 🙏
The team is currently focused on shipping our v1 release, so we’re pausing detailed reviews for a bit. We’ll follow up within the next 2–4 weeks once things settle — thanks so much for your patience!

@ro0sterjam ro0sterjam force-pushed the fix-transform-input-schema-mutate branch 3 times, most recently from 2313a71 to 669dc5e Compare November 3, 2025 07:24
// Handle nested object schemas
if (isZodObjectV4(outputSchema)) {
const outputShape: Mutable<z4.$ZodShape> = outputSchema._zod.def.shape;
const outputShape: Mutable<z4.$ZodShape> = {};
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

@ro0sterjam ro0sterjam force-pushed the fix-transform-input-schema-mutate branch from 669dc5e to 15cd573 Compare November 3, 2025 07:25
name,
strict: true,
schema: toJSONSchemaV4(zodSchema, {
schema: toJsonSchema(zodSchema, {
Copy link
Author

Choose a reason for hiding this comment

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

Call the version of toJsonSchema that also strips off transforms, since we can no longer assume that that has already been done for us by this point.

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

2 participants