diff --git a/langchain/src/output_parsers/json.ts b/langchain/src/output_parsers/json.ts index da1bdd735e07..41c25c1a1476 100644 --- a/langchain/src/output_parsers/json.ts +++ b/langchain/src/output_parsers/json.ts @@ -2,6 +2,11 @@ // MIT License export function parsePartialJson(s: string) { + // If the input is undefined, return null to indicate failure. + if (typeof s === "undefined") { + return null; + } + // Attempt to parse the string as-is. try { return JSON.parse(s);