#38908·n8n

[BUG] Mistral Cloud Chat Model crashes on citation (reference) chunks — @mistralai/mistralai pinned to broken 1.x schema

Author: SighteCreated Sep 17, 2026Updated Sep 17, 2026
Labelsteam:aistatus:in-linearstatus:team-assigned

Bug Description

The Mistral Cloud Chat Model sub-node kills an Agent run with NodeOperationError: invalid_union whenever the model emits a citation block.

Mistral models can return message content as an array of chunks, one variant being {"type": "reference", "reference_ids": [...]} — see Citations & References. The API sends those ids as strings; the bundled @mistralai/mistralai 1.x requires integers, so Zod rejects the chunk and the stream dies mid-answer.

The deciding line is buried deep in the union tree (all other branches are noise):

data.choices[0].delta.content[0].reference_ids[0]   expected number, received string

This is not #19856 (Magistral thinking chunks, fixed by #20853 in 1.117.0). That fix is in place — thinking shows up as a valid union member in the error below. The reference variant is the one that fails, and it has no issue and no fix yet.

There is no way to switch it off: the node exposes only maxTokens, temperature, maxRetries, topP, safeMode, randomSeed, and the Mistral API has no citation parameter — citations are model behaviour when grounding on documents.

Root cause: @mistralai/mistralai is pinned to the 1.x line

On master (@n8n/nodes-langchain 2.40.0):

  • packages/@n8n/nodes-langchain/package.json"@langchain/mistralai": "1.0.1" and "@mistralai/mistralai": "^1.10.0"
  • pnpm-workspace.yaml (overrides) → '@mistralai/mistralai': ^1.10.0
  • pnpm-lock.yaml resolves @mistralai/[email protected]

@mistralai/[email protected]src/models/components/referencechunk.ts:

reference_ids: z.array(z.number().int()),

This is unchanged through the whole 1.x line, including the latest v1.15.1.

Upstream fixed it in @mistralai/[email protected]:

reference_ids: z.array(smartUnion([z.string(), z.int()])),

And @langchain/mistralai ships that SDK from 1.1.0 onwards ("@mistralai/mistralai": "2.2.1"). n8n is on @langchain/mistralai 1.0.1, which depends on @mistralai/mistralai ^1.3.1 — so no released n8n version contains the fix, master included.

Suggested fix

Bump @langchain/mistralai to >= 1.1.0 and raise (or drop) the @mistralai/mistralai entries in pnpm-workspace.yaml and packages/@n8n/nodes-langchain/package.json — the ^1.10.0 override alone would otherwise force the tree straight back onto the broken 1.x schema.

To Reproduce

  1. AI Agent + Mistral Cloud Chat Model, model mistral-medium-3.5 (also reproduced with mistral-large-2512), streaming enabled.
  2. Inject retrieved document snippets into the user message in a way that invites the model to cite them (in our case an explicit source marker next to each snippet).
  3. Ask a question whose answer enumerates content from several documents.

It is non-deterministic: the same prompt in the same chat session succeeds on one run and dies on the next — it depends purely on whether the model decides to emit a citation chunk. Measured on one production workflow: 4 of 11 runs on a single enumerating prompt, and 3 of 76 runs over a day of mixed prompts.

Expected behavior

Reference/citation chunks are parsed instead of aborting the run.

Actual behavior

The Agent node throws mid-stream:

NodeOperationError: [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "array",
            "path": [ "data", "choices", 0, "delta", "content" ],
            "message": "Expected string, received array"
          }
        ],
        "name": "ZodError"
      },
      ...
      // the branch that matters:
      // path: [ "data", "choices", 0, "delta", "content", 0, "reference_ids", 0 ]
      // expected number, received string
    ]
  }
]
    at wrapAsNodeOperationError (.../utils/output_parsers/langchainParserError.ts:95:9)
    at wrapLangChainParserError (.../utils/output_parsers/langchainParserError.ts:117:10)
    at .../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:110:42
    at executeBatch (.../nodes/agents/Agent/agents/ToolsAgent/V3/helpers/executeBatch.ts:107:15)
    at ExecuteContext.toolsAgentExecute (.../nodes/agents/Agent/agents/ToolsAgent/V3/execute.ts:98:8)
    at ExecuteContext.execute (.../nodes/agents/Agent/V3/AgentV3.node.ts:155:10)

Description: Original error: ZodError — failing node: the Agent, failing sub-node: Mistral Cloud Chat Model.

Workaround

Replace the Mistral node with the OpenAI Chat Model node pointed at https://api.mistral.ai/v1 (options.baseURL, responsesApiEnabled: false). @langchain/openai does not Zod-validate stream chunks, so the run completes — at the price of whatever the reference chunks carried.

Environment

  • Self-hosted (Docker). The pins quoted above are read from master, so current releases are affected as well.
  • Models: mistral-medium-3.5, mistral-large-2512
  • Nodes: @n8n/n8n-nodes-langchain.agent (v3.1) + @n8n/n8n-nodes-langchain.lmChatMistralCloud (v1)