#11740·langchainjs

bug(core): JsonOutputParser rejects streamed content blocks that work with invoke

Author: To3akaRinCreated Sep 27, 2026Updated Sep 27, 2026

Description

JsonOutputParser.invoke() extracts JSON from text content blocks, but transform() rejects the same message format with Cannot handle non-string output. This prevents parsing streamed JSON from models that return AIMessageChunk.content as an array of text/reasoning blocks.

BaseCumulativeTransformOutputParser._transform() checks that content is a string before calling the parser. It never reaches the existing JsonOutputParser._baseMessageToString() override that extracts message.text.

Example Code

typescript
import { AIMessage, AIMessageChunk } from "@langchain/core/messages";
import { JsonOutputParser } from "@langchain/core/output_parsers";

const parser = new JsonOutputParser();
console.log(await parser.invoke(new AIMessage({
  content: [{ type: "text", text: '{"answer":42}' }],
}))); // { answer: 42 }

async function* chunks() {
  yield new AIMessageChunk({
    content: [{ type: "text", text: '{"answer":' }],
  });
  yield new AIMessageChunk({
    content: [{ type: "text", text: "42}" }],
  });
}

for await (const value of parser.transform(chunks(), {})) {
  console.log(value);
}

Expected: the stream emits {} and then { answer: 42 }, as it does for equivalent string chunks.

Actual: the first content-block chunk throws Error: Cannot handle non-string output.

System Info

  • Reproduced on main at 5d509ad4b8a5ed9dd4b83020b4c103ac8a69859c (@langchain/core package version 1.2.13).
  • macOS / Apple Silicon, Node.js v24.18.0, pnpm 10.14.0.
  • No model service, credentials, or network request is needed for the reproduction.

Related work

PR #9789 fixed text extraction for non-streaming JsonOutputParser.invoke(). This report concerns the separate cumulative streaming path. I checked the open PR list and GitHub issue/PR searches for this streaming failure and did not find an existing fix.

Source: langchain-ai/langchainjs