AI Agent output adding \n newline characters when using Mistral Large 4 model

Describe the problem/error/question

The AI Agent node outputs a \n newline character every couple tokens in the output, when using the Mistral Large 4 model. This causes the resulting markdown to not render properly. The AI Agent execution logs show a correct output by the LLM, but the AI Agent node output contains rogue newlines. So far, I have only found this issue with this specific Mistral model, other models work fine.

Please share your workflow

Share the output returned by the last node

[

{

“output”:
“Here\n’s what\n’s in your dataset\n:\n\n—\n\n\n## Dataset Overview\n\n\nDataset: \nCASUSER.CARS\n | Rows\n: 428 |\n Columns: \n15\n\nThis is\n a classic car\n-spec\nifications dataset\n — one row per\n car model (2\n004 model\n year\n),\n with who\n made it,\n what\n kind\n of car it is\n, and its\n mechanical\n/\nprice\n specs.\n\n### Variables\n\n\n| Variable |\n Type | Missing\n | Missing\n % | Status |\n\n|:\n--------\n-|:-----\n|\n--------:|----------\n:\n|:------\n|\n\n| Make | Text\n | 0 |\n 0\n% | :white_check_mark: (\n38 brands,\n e.g. Toyota\n \n28, Chevrolet\n 27,\n BMW 20\n) |\n| Model\n | Text | \n0 | 0\n% |\n :warning: \n425 distinct —\n essentially\n a unique ID\n per row |\n|\n Type | Text |\n 0 | \n0% | :white_check_mark:\n \n6 categories:\n Sedan 262\n (\n61%), SUV\n 60\n, Sports\n 49, W\nagon 30,\n Truck 24,\n Hybrid 3\n |\n| Origin |\n Text | 0\n | 0%\n | :white_check_mark: 3\n categories\n: Asia 158\n (\n37\n%), USA 147\n (34\n%), Europe 123\n (29\n%) |\n| Drive\nTrain | Text |\n 0 | \n0% | :white_check_mark:\n 3 categories:\n Front 226\n (53\n%), Rear 110\n (26\n%), All 92\n (21\n%) |\n| MS\nRP | \nText\n :warning: | 0\n | 0%\n | stored\n like\n \"$21,\n739\" — needs\n cleaning to use\n as a number |\n\n| Invoice | \nText :warning:\n | 0 |\n 0% |\n stored like \"$\n20\n,189\n\" — same issue\n |\n| EngineSize\n | Number | \n0 | 0\n% | :white_check_mark: litres\n,\n 1.3\n–\n8.3\n, mean\n 3\n.2 |\n|\n Cylinders |\n Number | \n2 | \n0.47%\n |\n :warning: only variable\n with missing values\n |\n| Horsepower\n | Number | \n0 | 0\n% | :white_check_mark: \n73–500\n hp, mean \n216 |\n| MP\nG_City |\n Number | 0\n | 0%\n | :white_check_mark: 10\n–60\n, mean 20\n.\n1 |\n| MP\nG_Highway\n | Number | \n0 | 0\n% | :white_check_mark: \n12–66,\n mean 26.\n8 |\n| Weight\n | Number | \n0 | 0\n% | :white_check_mark: lbs\n, 1,\n850–7\n,190, mean\n 3,578\n |\n| Wheelbase\n | Number | \n0 | 0\n% | :white_check_mark: inches\n, 89\n–144\n, mean 108\n |\n| Length |\n Number | 0\n | 0%\n | :white_check_mark: inches\n, 143\n–238\n, mean 186\n |\n\n### Things to\n watch out for\n\n\n- MS\nRP and Invoice are\n text\n, not numbers\n — they’re stored\n with\n $\n and commas\n (e.g.\n \"$36\n,945\").\n Any\n analysis using\n price\n must\n strip\n those first.\n Clean\ned,\n MS\nRP runs\n $10,280\n–\n$192,465\n (mean ≈\n $32,775\n) and Invoice\n $\n9,875–\n$173,560\n (mean ≈ $\n30,015).\n\n- Cyl\ninders has 2\n missing values (\n0.47%)\n — negligible, but\n worth knowing\n before\n any test\n.\n- Model\n has\n 425 distinct values\n out\n of 428 rows\n — it’s\n effectively\n a unique\n identifier, not\n a grouping\n variable.\n Don’t use\n it as\n a category in\n a test.\n-\n Cylinders\n (\n7 distinct\n values) is\n a numeric column\n that really\n behaves like a\n category —\n 3, \n4, 5\n, 6,\n 8, \n10, 12\n.\n Treat\n it as a group\n label\n if\n you compare\n across\n it, not as\n a continuous measurement\n.\n\n### Example\n rows\n\n| Make\n | Model | Type\n | Origin | Drive\nTrain | MSRP\n | Engine\nSize | Cyl\n |\n HP\n | MPG_C\n | MPG_H\n | Weight |\n|:\n—|:—|:\n—|:—|:\n—|:—|\n—:|—:|\n—:|—:|\n—:|—:\n|\n| Acura\n | MDX |\n SUV | Asia |\n All | $36\n,945 | \n3.5 |\n 6 | \n265 | 17\n | 23 |\n 4451 |\n\n| Acura |\n RSX Type S\n 2dr |\n Sedan | Asia\n | Front | $\n23,820 |\n 2.0\n | 4 |\n 200 | \n24 | 31\n | 2778\n |\n| Acura\n | TSX \n4dr | Sedan\n | Asia | Front\n | $26,\n990 | 2\n.4 | \n4 | 200\n | 22 |\n 29 | \n3230 |\n\n—\n\n\nIn\n short: \n428 car\n models with\n brand\n, vehicle\n type, origin,\n dr\nivetrain, price\n (as text\n), and eight\n numeric specs. The\n data is very\n clean — only \n2 missing cells\n in\n the whole table\n — and the main\n practical\n got\ncha is that the\n two price columns need\n their\n $/\ncommas stripped before\n you\n can compute\n with\n them.\n\nIf you\n want to go\n further\n — e\n.g. \ndoes\n horsepower differ by\n car type,\n or by\n origin?\n — that’s a\n hypothesis\n question, and you\n’d select\n the Test hypothesis\n block. Want\n me to set\n that up?”

}
]

Information on your n8n setup

  • n8n version:
    2.45.6
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

Hey @J_Bom, while you wait for a response, here are some things that might help:

Suggested resources

Automatically matched to your question.

Docs:

Forum:

@ihortom, @Akif, @GollyJer - you’ve helped with similar issues before, can you take a look?

Automatically suggested by n8n’s community bot. It’s a pilot - please share feedback here.

Hi @J_Bom, the pattern in your output is a good clue. The extra \n sits every few tokens and splits words (“Here\n’s”, “2\n004”, “MS\nRP”), so it looks like it’s being inserted at chunk boundaries when the pieces of the response get joined, not something the model writes. That would also explain why the execution log of the model looks clean while the Agent node output doesn’t, and why only this model is affected (newer Mistral models can return the message content as a list of parts instead of one string, and if those parts are joined with a newline you get exactly this).

Things worth trying:

  1. If your Agent node has the streaming option, turn it off and run it again. If the newlines disappear, that confirms it’s the chunk joining.
  2. Workaround that usually sidesteps it: Mistral’s API is OpenAI-compatible, so you can use the OpenAI Chat Model node with a new OpenAI credential whose Base URL is https://api.mistral.ai/v1 and your Mistral API key, then type the model name. Plug that into the same Agent and compare.
  3. Don’t try to clean it up with a replace afterwards. You can’t tell the bad \n from the real ones in your markdown table, so you’d break the formatting either way.

If 1 or 2 fixes it, it’s worth opening a GitHub issue with your n8n version, the exact model ID, and the before/after output, since the Mistral Cloud Chat Model node should handle that response shape.

I get the same result with Streaming on or Streaming off.

Option 2 worked, the workaround with a OpenAI Model node instead of a Mistral Model node.

Can you add the Github issue? All the information is in this post

Glad the OpenAI node route works. The fact that streaming is making no difference narrows it down: the model log is clean, and the same model behaves through the OpenAI-compatible endpoint, so it likely points at the Mistral Chat Model node’s response handling rather than the model or the Agent.

Best if you file the issue yourself, since you have the repro and can answer follow-ups. Search existing issues for “Mistral” first in case it’s already reported. Include: n8n 2.45.6 (Docker, Postgres), the exact model ID, that streaming on and off both fail, a minimal workflow (Mistral node to the Agent, no tools, short prompt), a small slice of the bad output, and that the OpenAI node with the Mistral base URL is fine.

If the logs look clean but the node output is broken, it’s likely streaming chunks being joined with newlines. Try turning streaming off in the agent options, or add a Code node after it that strips the stray \n between tokens. Also try the Mistral model node on a different API route to see if it’s the provider.

Streaming isn’t the cause. J_Bom already turned streaming off and got the same result, and the execution log is clean, so the newline gets added while the Mistral node assembles the response, not by the model. Instead of patching the prompt, normalise afterwards: a Code node that drops a newline when it sits between two non-space characters, keeping the markdown renderer downstream.

That’s the same boundary the decompiling argument is about this week: fine when a person reads the output, unreliable when something downstream needs it byte for byte.