My output in Gmail as below:
Flow as below:
Currently, you have a Structured output parser attached, so it requires the AI to always return the specific JSON format you require.
Can you try passing it to an HTML Convert to HTML Table node?
Can you PIN the data on the AI Agent node, then upload your workflow.json to G Drive and share it? I will take a look to adjust it myself
it is as above and below:
| Executive Summary | 0:Total revenue across all regions: $97,700 | 1:Overall performance highlights: | 2:- Top 3 regions: | 3: 1. APAC — $47,000 | 4: 2. EMEA — $26,200 | 5: 3. Americas — $24,500 | 6:- Top 3 products: | 7: 1. Product A — $42,500 | 8: 2. Product B — $36,000 | 9: 3. Product C — $19,200 | Top 3 Region-Product Pairs | 0:Ranked Top 3 Region-Product Pairs: | 1:- 1. APAC | Product A — $25,000 | 2:- 2. APAC | Product B — $15,000 | 3:- 3. EMEA | Product B — $11,000 | Key Insights | 0:Regional performance observations: | 1:- APAC leads with $47,000 (≈48.11% of total), driven primarily by Product A ($25,000) and Product B ($15,000). | 2:- EMEA totals $26,200 (≈26.82% of total), with relatively balanced contributions from Product B ($11,000), Product A ($8,000), and Product C ($7,200). | 3:- Americas totals $24,500 (≈25.07% of total), where Product B ($10,000) and Product A ($9,500) are the main contributors. | 4:Product performance trends: | 5:- Product A is the top product at $42,500 (≈43.53% of total), led by APAC ($25,000) and solid contributions from Americas ($9,500) and EMEA ($8,000). | 6:- Product B is second at $36,000 (≈36.83% of total), with meaningful sales across APAC ($15,000), EMEA ($11,000), and Americas ($10,000). | 7:- Product C is the smallest at $19,200 (≈19.64% of total), with EMEA ($7,200) and APAC ($7,000) contributing most of its revenue. | 8:Notable patterns: | 9:- APAC is the dominant region, accounting for nearly half of total revenue, driven mainly by Product A. | 10:- Product A and Product B together represent the majority of revenue ($78,500 of $97,700). | 11:- EMEA and Americas have comparable total revenue (EMEA $26,200 vs Americas $24,500), while APAC is a clear outlier at $47,000. | |
|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|
I am requesting that you pin it because the structure of the data returned by the node matters too, right now your are simply taking one string with no data formatting around it, so I can’t reproduce the real issue and suggest a fix ![]()
your meaning of ‘Pin’ it means copy the whole flow here?
You can highlight all nodes you want to Pin (keep the data for), then you press P or right click > Pin. Then, you can export the workflow json and share it via Google Drive here, as it will be too large.
see if this helps:
{
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "SELECT Region, Product, SUM(Revenue) AS TotalRevenue\nFROM Sales\nWHERE SaleDate BETWEEN '2025-01-01' AND '2025-03-31'\nGROUP BY Region, Product\nORDER BY TotalRevenue DESC;\n"
},
"type": "n8n-nodes-base.microsoftSql",
"typeVersion": 1.1,
"position": [
-4048,
-624
],
"id": "617b2415-75df-44d0-ab2b-990de8a40510",
"name": "Microsoft SQL",
"credentials": {
"microsoftSql": {
"id": "qKbPOuea1IWxYcIz",
"name": "Microsoft SQL account"
}
}
},
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
-4240,
-624
],
"id": "4359e6df-4b6e-4aab-b10c-6ee772a1e3c2",
"name": "When clicking ‘Execute workflow’"
},
{
"parameters": {
"promptType": "define",
"text": "=Here is the complete sales revenue dataset:\n\n{{ $json.datasetText }}\n\nProvide a CLEAN, WELL-FORMATTED OUTPUT format analysis with these exact sections:\n\nTotal revenue across all regions: [exact number]\nOverall performance highlights: \nRank the top 3 regions with their revenue amount.\nRank the top 3 product with their revenue amount.\n\nRank the top 3 Region-Product Pairs\n\nRegional performance observations\nProduct performance trends\nNotable patterns\n\nUse only the provided numbers. Include dollar sign $ in front of the numerical values. Format with clear headings and bullet points. No version markers or special characters. DO NOT have '\\n' in the output format. If the sentence needs to start with a new line, do not add '\\n'.\n\n",
"hasOutputParser": true,
"options": {
"systemMessage": "=You are a precise data analyst and SQL expert. Analyze the COMPLETE dataset of sales revenue by region and product. Provide accurate insights based on ALL the data provided. Never invent or modify numbers.\n\nFor example,\nto extract the data for the Top 3 Region-Product Pairs, the SQL Query is below:\nSELECT Top(3) \n Region, \n Product,\n\tSUM(Revenue) AS TotalRevenue\nFROM [SalesDemo].[dbo].[Sales]\nGROUP BY Region, Product\nORDER BY TotalRevenue DESC;\n\nTo extract for the Overall performance, the SQL Query is as below:\nSELECT Top(3) \n Region, \n \tSUM(Revenue) AS TotalRevenue\nFROM [SalesDemo].[dbo].[Sales]\nGROUP BY Region\nORDER BY TotalRevenue DESC;\n\nAnd by Product:\nSELECT Top(3)\n Product, \n \tSUM(Revenue) AS TotalRevenue\nFROM [SalesDemo].[dbo].[Sales]\nGROUP BY Product\nORDER BY TotalRevenue DESC;"
}
},
"type": "@n8n/n8n-nodes-langchain.agent",
"typeVersion": 2.2,
"position": [
-3664,
-624
],
"id": "15e8e283-c512-4e18-8d17-352b9e716865",
"name": "AI Agent",
"executeOnce": false
},
{
"parameters": {
"model": {
"__rl": true,
"value": "gpt-5-mini",
"mode": "list",
"cachedResultName": "gpt-5-mini"
},
"options": {
"responseFormat": "text"
}
},
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"typeVersion": 1.2,
"position": [
-3696,
-432
],
"id": "480d589d-316c-44fc-ad4a-67d3560031ed",
"name": "OpenAI Chat Model",
"credentials": {
"openAiApi": {
"id": "PN2BdPgEnf15x1bU",
"name": "OpenAi account"
}
}
},
{
"parameters": {
"jsonSchemaExample": "{\n \"Executive Summary\": [\"Total revenue across all regions\",\"Overall performance highlights\"],\n \"Top 3 Region-Product Pairs\": [\"1. [Region] - [Product]: $[Amount]\",\n \"2. [Region] - [Product]: $[Amount]\",\n \"3. [Region] - [Product]: $[Amount]\"], \n \"Key Insights\": [\"Regional performance observations\",\n \"Product performance trends\",\n \"Notable patterns\"]\n}"
},
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"typeVersion": 1.3,
"position": [
-3440,
-432
],
"id": "49419f18-22e1-4dbc-8781-1abdd0d9d439",
"name": "Structured Output Parser"
},
{
"parameters": {
"jsCode": "// Aggregate all rows into one item for the AI\nconst allData = items.map(item => {\n return {\n Region: item.json.Region,\n Product: item.json.Product, \n TotalRevenue: item.json.TotalRevenue\n };\n});\n\nreturn [{\n json: {\n completeDataset: allData,\n totalRecords: allData.length,\n datasetText: allData.map(row => `${row.Region} | ${row.Product} | ${row.TotalRevenue}`).join('\\n')\n }\n}];"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-3856,
-624
],
"id": "9a0d960e-2317-4797-9555-0afc55437f67",
"name": "Aggregate"
},
{
"parameters": {
"sendTo": "[email protected]",
"subject": "Data Insights",
"message": "={{ $json.table }}",
"options": {}
},
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [
-3024,
-624
],
"id": "20a22c1c-1672-4b2f-9cdd-40d9789818e4",
"name": "Send a message",
"webhookId": "bb05d7e6-1dde-46a0-9c14-b3eec26877b6",
"credentials": {
"gmailOAuth2": {
"id": "XeRA7V62IbQLYqLe",
"name": "Gmail account"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "6fe527b2-090e-4f92-88d7-43f4f9c6bc55",
"name": "Subject",
"value": "Data Insights",
"type": "string"
},
{
"id": "a860b117-965b-4a20-a108-e0f4d6eaef7a",
"name": "Message",
"value": "={{ $json.output }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
-3360,
-624
],
"id": "7aa8a6ff-1b18-4928-a8aa-accd98327eca",
"name": "Edit Fields"
},
{
"parameters": {
"operation": "convertToHtmlTable",
"options": {
"capitalize": true,
"customStyling": true,
"tableAttributes": "style=\"padding:10px\"",
"headerAttributes": "style=\"padding:10px\""
}
},
"type": "n8n-nodes-base.html",
"typeVersion": 1.2,
"position": [
-3184,
-624
],
"id": "21a3941c-140e-4d47-8dd4-5176c76ae212",
"name": "HTML"
}
],
"connections": {
"Microsoft SQL": {
"main": [
[
{
"node": "Aggregate",
"type": "main",
"index": 0
}
]
]
},
"When clicking ‘Execute workflow’": {
"main": [
[
{
"node": "Microsoft SQL",
"type": "main",
"index": 0
}
]
]
},
"AI Agent": {
"main": [
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "AI Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Aggregate": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "HTML",
"type": "main",
"index": 0
}
]
]
},
"HTML": {
"main": [
[
{
"node": "Send a message",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "eecdc2ebf7b67c213c1ae11f85dd2efc90c44c7eaadcbfac1428826bf5b2ef9f"
}
}
I am not sure how to share it via Google Drive here.
I would say the problem is that you are saying do not use /n in your output but most languages use that as to skip a line, i would remove that from the system prompt and rather add a code node to format any excess symbols that needs to be removed. I can provide code if you need
You can also check the several strategies users reported in this thread to format output from the AI:
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.