Description:
The instructor library throws a TypeError when processing Zod validation errors. The error occurs in the fromZodErrorWithoutRuntimeCheck function when it tries to access zodError.errors, but this property is undefined.
Error Stack Trace:
TypeError: Cannot read properties of undefined (reading 'length')
at isNonEmptyArray (http://localhost:8080/node_modules/.vite/deps/@instructor-ai_instructor.js?v=8af0ca2e:10356:16)
at fromZodErrorWithoutRuntimeCheck (http://localhost:8080/node_modules/.vite/deps/@instructor-ai_instructor.js?v=8af0ca2e:10494:7)
at fromZodError (http://localhost:8080/node_modules/.vite/deps/@instructor-ai_instructor.js?v=8af0ca2e:10489:10)
at m (http://localhost:8080/node_modules/.vite/deps/@instructor-ai_instructor.js?v=8af0ca2e:10630:176)
at async LLMWrapper.generate
at async OpenAITalentService.extractResume
at async processFile
Environment:
@instructor-ai/instructor: 1.7.0
zod: 4.0.10
- Node.js: v22.17.1
- Browser: Chrome (development with Vite)
Root Cause:
The instructor library expects zodError.errors to exist, but in Zod 4.x, the property might be named differently or structured differently than what the instructor library expects.
Reproduction:
- Use
@instructor-ai/instructor@1.7.0 with zod@4.0.10
- Call the instructor client with a Zod schema that fails validation
- The error handling code fails when trying to process the ZodError
Expected Behavior:
The instructor library should properly handle Zod validation errors without throwing TypeError about undefined properties.
Suggested Fix:
The instructor library should check if zodError.errors exists before trying to access its length property, or adapt to the current Zod error structure.
Immediate Workaround
Description:
The instructor library throws a TypeError when processing Zod validation errors. The error occurs in the
fromZodErrorWithoutRuntimeCheckfunction when it tries to accesszodError.errors, but this property is undefined.Error Stack Trace:
Environment:
@instructor-ai/instructor: 1.7.0zod: 4.0.10Root Cause:
The instructor library expects
zodError.errorsto exist, but in Zod 4.x, the property might be named differently or structured differently than what the instructor library expects.Reproduction:
@instructor-ai/instructor@1.7.0withzod@4.0.10Expected Behavior:
The instructor library should properly handle Zod validation errors without throwing TypeError about undefined properties.
Suggested Fix:
The instructor library should check if
zodError.errorsexists before trying to access itslengthproperty, or adapt to the current Zod error structure.Immediate Workaround
npm install zod@<4.0.0