-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Checked other resources
- This is a bug, not a usage question. For questions, please use the LangChain Forum (https://forum.langchain.com/).
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
import { type InteropZodType, interopZodTransformInputSchema } from "@langchain/core/utils/types";
import { z } from "zod/v4";
const schemaWithOptional = z.object({
messages: z.array(z.string().transform((x) => x.toUpperCase())).optional(),
});
const schemaWithoutOptional = z.object({
messages: z.array(z.string().transform((x) => x.toUpperCase())),
});
interopZodTransformInputSchema(schemaWithOptional as unknown as InteropZodType, true);
interopZodTransformInputSchema(schemaWithoutOptional as unknown as InteropZodType, true);
const message = { messages: ["hello"] };
console.log(schemaWithOptional.parse(message)); // Logs { message: [ 'HELLO' ] }
console.log(schemaWithoutOptional.parse(message)); // Logs { message: [ 'hello' ] }
Error Message and Stack Trace (if applicable)
No response
Description
interopZodTransformInputSchema
is suppose to strip the transform functions from a schema, but when an object
or array
is wrapped with an optional
, the current logic seems to skip over this element and thus does not strip any nested transforms under it.
I believe it should be a relatively trivial fix by adding the addition check for optional
here.
Something like:
// Handle nested optional schemas
else if (isZodOptionalV4(outputSchema)) {
const innerType = interopZodTransformInputSchema(
outputSchema._zod.def.innerType,
recursive
) as z4.$ZodType;
outputSchema = clone<z4.$ZodOptional>(outputSchema, {
...outputSchema._zod.def,
innerType,
});
}
System Info
Langchain 0.3.35
Node v24.5.0
OSX 15.6.1 (24G90)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working