-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(langchain): Fix toJsonSchema mutating underlying zod schema #9125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(langchain): Fix toJsonSchema mutating underlying zod schema #9125
Conversation
|
@ro0sterjam is attempting to deploy a commit to the LangChain Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
a6b992c
to
047002c
Compare
) as ZodObjectV4; | ||
return toJSONSchema(strictSchema); | ||
} else { | ||
return toJSONSchema(schema); |
There was a problem hiding this comment.
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.
const outputShape: Mutable<z4.$ZodShape> = { | ||
...outputSchema._zod.def.shape, | ||
}; |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
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 fromtoJsonSchema
.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