on type safety in LangChain TS
Blog post from Octomind
The use of Large Language Models (LLMs) in LangChain TS at Octomind presents challenges in ensuring type safety due to the unpredictable nature of LLM outputs, which complicates the task of parsing and handling errors within the type system. Despite the advantages of using TypeScript, such as integration with existing projects and alleged type safety, the TypeScript implementation of LangChain lags behind Python, both in code and documentation. LangChain's tool implementation relies on developers understanding input formats, but inconsistencies arise in parsing outputs as JSON, leading to potential runtime type errors. The StructuredTool class is employed to manage input data, but its type-checking occurs only at runtime, posing issues for developers who expect compile-time assurance. To address these problems, Octomind developed an auto-fixer for common input format errors in LLM outputs, although this process revealed gaps in LangChain's type system. The experience highlights the need for improved solutions, prompting discussions on GitHub to explore potential fixes for these issues in LangChain's JavaScript and TypeScript implementations.