langchainjs: Type instantiation is excessively deep and possibly infinite.

When I use any of the new openai-function functionality in langchain, I get many kinds of errors on typescript and eslint also takes over 30 seconds to run. Specifically, when using the DynamicStructuredTool with this zod schema:

    z.object({
      query: z
        .string()
        .describe("The actual text or keywords to search for on the database."),
      search_type: z
        .number()
        .describe(
          "This parameter determines the type of search that will be performed.",
        ),
    }),

This seems like a simple schema but somehow I get the error `Type instantiation is excessively deep and possibly infinite.

Additionally, it is also giving me this error Types have separate declarations of a private property  _cached

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Reactions: 5
  • Comments: 17 (1 by maintainers)

Most upvoted comments

🤖

Hello,

The error “Type instantiation is excessively deep and possibly infinite” is a TypeScript error that occurs when TypeScript’s type checker gets into a state where it might end up in an infinite loop. This can happen when you have recursive type definitions or complex type manipulations. In your case, it’s likely that the zod schema you’re using with the DynamicStructuredTool is causing this issue.

The error “Types have separate declarations of a private property _cached” is a TypeScript error that occurs when two classes share the same base class and declare a private property with the same name. In your case, it’s likely that the DynamicStructuredTool and another class both have a private property named _cached.

As for the eslint taking over 30 seconds to run, it could be due to a number of reasons. It could be that your project is large and eslint is taking a long time to lint all the files. It could also be that you have complex rules or plugins that are taking a long time to run. In your case, it’s possible that the complexity of the code in the file “langchain/src/chains/query_constructor/index.ts” is contributing to the long eslint run time.

Unfortunately, without more information about the specific zod schema you’re using and the other classes in your project, it’s hard to provide a more specific solution. You might need to simplify your zod schema or refactor your classes to avoid these errors.

As for the implementation of the DynamicStructuredTool in the LangChain codebase, it is a class that extends the StructuredTool class. It is a tool that can be created dynamically from a function, name, description, and a schema. You can find more details about its implementation in the langchain/src/tools/dynamic.ts file.

I hope this helps! If you have any more questions or if you can provide more information about your zod schema and the other classes in your project, I would be happy to assist you further.

Best, Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

what i found was that the versions of zod that langchain used was different to the version of zod i installed, so you get conflicts with comparison checking it is doing …

I was having the same issues as mentioned here, i simply removed zod from the root of my project and it just started working… (i know, this isn’t a proper fix, but it allowed me to get work done!)

Hi, @fer112233,

I’m helping the langchainjs team manage their backlog and am marking this issue as stale. From what I understand, the issue involves encountering errors related to type instantiation and private property declarations when using the DynamicStructuredTool with a specific zod schema in the langchain project. The errors are causing issues with TypeScript and eslint, leading to slow performance and potential infinite type instantiation. It seems that updating the zod version to match the one required in LangChain has solved the problem for some users.

Could you please confirm if this issue is still relevant to the latest version of the langchainjs repository? If it is, please let the langchainjs team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you for your understanding and cooperation.

Just here to say, same exact issue, same fix. When i started playing with the langchain samples i just “added zod” via pnpm and for it installed a 3.21 version… possibly because i was using that in a different project in my monorepo 🤔.

Fixing to 3.22.4 which is the version referenced all over the place for use by langchain in my lock file immediately resolved the issue.