Intermittent failures: Supabase Postgres + QuickChart workflow unstable

Describe the problem/error/question

I have a workflow in n8n that connects:
Webhook → Postgres (Supabase) → Aggregate → Orchestrator Agent → (store in Postgres / respond to webhook).

The problem is that the workflow works intermittently:

  • Sometimes it runs completely fine and returns the expected visualization.

  • Other times it fails (even with the exact same input) and either:

    • hangs without response, or

    • throws an error at Set response: toJsonString can't be used on undefined value.

This makes the workflow unreliable for production.

What is the error message (if any)?

  1. Problem in node 'Set response': toJsonString can't be used on undefined value
  2. Or no output at all (workflow seems stuck).

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

{
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "37512e1a-8376-4ba0-bdcd-34bb9329ae4b",
              "name": "response",
              "type": "string",
              "value": "={{\"https://quickchart.io/chart?width=400&c=\"+ encodeURIComponent($json.output.toJsonString()) }}\n\n"
            }
          ]
        },
        "options": {}
      },
      "id": "b82b6f15-b357-46c5-8283-53fa52470984",
      "name": "Set response",
      "type": "n8n-nodes-base.set",
      "position": [
        80,
        704
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"type\": {\n      \"type\": \"string\",\n      \"enum\": [\"bar\", \"line\", \"radar\", \"pie\", \"doughnut\", \"polarArea\", \"bubble\", \"scatter\", \"area\"]\n    },\n    \"data\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"labels\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"string\"\n          }\n        },\n        \"datasets\": {\n          \"type\": \"array\",\n          \"items\": {\n            \"type\": \"object\",\n            \"properties\": {\n              \"label\": {\n                \"type\": \"string\"\n              },\n              \"data\": {\n                \"type\": \"array\",\n                \"items\": {\n                  \"type\": \"number\"\n                }\n              },\n              \"backgroundColor\": {\n                \"type\": [\"string\", \"array\"],\n                \"items\": {\n                  \"type\": \"string\"\n                }\n              },\n              \"borderColor\": {\n                \"type\": [\"string\", \"array\"],\n                \"items\": {\n                  \"type\": \"string\"\n                }\n              },\n              \"borderWidth\": {\n                \"type\": \"number\"\n              }\n            },\n            \"required\": [\"data\", \"label\"],\n            \"additionalProperties\": true\n          }\n        }\n      },\n      \"required\": [\"labels\", \"datasets\"]\n    },\n    \"options\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"responsive\": {\n          \"type\": \"boolean\"\n        },\n        \"scales\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"x\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"title\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"display\": {\n                      \"type\": \"boolean\"\n                    },\n                    \"text\": {\n                      \"type\": \"string\"\n                    }\n                  }\n                },\n                \"beginAtZero\": {\n                  \"type\": \"boolean\"\n                }\n              }\n            },\n            \"y\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"title\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"display\": {\n                      \"type\": \"boolean\"\n                    },\n                    \"text\": {\n                      \"type\": \"string\"\n                    }\n                  }\n                },\n                \"beginAtZero\": {\n                  \"type\": \"boolean\"\n                },\n                \"ticks\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"callback\": {\n                      \"type\": \"string\"\n                    }\n                  }\n                }\n              }\n            }\n          }\n        },\n        \"plugins\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"title\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"display\": {\n                  \"type\": \"boolean\"\n                },\n                \"text\": {\n                  \"type\": \"string\"\n                }\n              }\n            },\n            \"legend\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"position\": {\n                  \"type\": \"string\",\n                  \"enum\": [\"top\", \"left\", \"bottom\", \"right\"]\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  },\n  \"required\": [\"type\", \"data\"]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.2,
      "position": [
        -160,
        880
      ],
      "id": "37cc1476-8d92-438b-a38e-0d635947bc98",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "model": "anthropic/claude-3.5-haiku",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        -416,
        880
      ],
      "id": "da70d5e8-566f-419f-81b6-affc711e05e0",
      "name": "OpenRouter Chat Model2",
      "credentials": {
        "openRouterApi": {
          "id": "kDjBZO625HxQHa05",
          "name": "Open Servicios Conversa"
        }
      }
    },
    {
      "parameters": {
        "operation": "upsert",
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "table": {
          "__rl": true,
          "value": "dashboard_plantillas",
          "mode": "list",
          "cachedResultName": "dashboard_plantillas"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "id": "={{ $('Webhook').item.json.body.id }}",
            "updated_at": "={{  $now  }}",
            "resultado_texto": "={{ $json.output }}"
          },
          "matchingColumns": [
            "id"
          ],
          "schema": [
            {
              "id": "id",
              "displayName": "id",
              "required": true,
              "defaultMatch": true,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "created_at",
              "displayName": "created_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "updated_at",
              "displayName": "updated_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": false
            },
            {
              "id": "tipo_visualizacion",
              "displayName": "tipo_visualizacion",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "tipo_resultado",
              "displayName": "tipo_resultado",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "resultado_numero",
              "displayName": "resultado_numero",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "resultado_texto",
              "displayName": "resultado_texto",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": false
            },
            {
              "id": "resultado_json",
              "displayName": "resultado_json",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "object",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "resultado_fecha",
              "displayName": "resultado_fecha",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "titulo_plantilla",
              "displayName": "titulo_plantilla",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "titulo_visualizacion",
              "displayName": "titulo_visualizacion",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "query_sql",
              "displayName": "query_sql",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "grafica_solicitud_ia",
              "displayName": "grafica_solicitud_ia",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "visualizar_en_dashboard",
              "displayName": "visualizar_en_dashboard",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "boolean",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "categoria",
              "displayName": "categoria",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            },
            {
              "id": "orden_visualizacion",
              "displayName": "orden_visualizacion",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": false,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        0,
        0
      ],
      "id": "f1472302-d974-4462-8797-10894e29dfeb",
      "name": "Postgres1",
      "credentials": {
        "postgres": {
          "id": "dLaj9Cymg7YxbaD5",
          "name": "Postgres Supabase PRODUCCION"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Input data:{{ $json.query.query }}",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=I want you to act as a Chart.js visualization expert. Your primary goal is to generate valid and clearly labeled Chart.js configuration objects based on user requests.  These configurations should be directly usable within a Chart.js environment.\n\nInput: You will receive user requests describing the desired visualization. These requests may include:\n\nChart Type: (e.g., bar, line, pie, scatter, radar, bubble, etc.)\nData: The data to be visualized. This can be provided in various formats (CSV, JSON, lists). Clarify ambiguous data formats with the user. Handle data extraction as needed.\nLabels: Labels for data points, axes, and other elements. Specifically, the user must provide clear axis titles and units (if applicable). Ask clarifying questions if this information is missing.\nStyling: Customization options (colors, fonts, gridlines, titles, legends, tooltips, axis scales). Use Chart.js defaults if no specific styling is requested.\nSpecific Chart.js options: Users might request specific Chart.js features (logarithmic scales, animations, plugins).\nNatural language descriptions: Interpret less structured descriptions and translate them into valid Chart.js configurations.\nAxis information: Request and expect clear details on axis labels, including:\nAxis Titles: Concise titles for x and y axes. (e.g., \"Month\", \"Sales (USD)\")\nUnits: Units of measurement, if relevant. (e.g., \"(USD)\", \"kg\")\nData Type: The type of data on each axis (categorical, numerical, time series).\nSpecific Formatting: Requirements for date/number formats, currency symbols, etc.\nOutput:  A valid, well-formatted, and easily readable JSON object representing a Chart.js configuration, ready to be used in a new Chart() constructor.  The output must include properly configured axis labels based on the provided input. This includes adding titles and units to both axes within the options.scales section of the JSON.\n\nExample Input (Improved):\n\n\"Create a bar chart showing the monthly sales for the first quarter of 2024.  January had $10,000 in sales, February had $12,000, and March had $15,000.  Use blue for the bars. The chart title should be 'Q1 2024 Sales'. The x-axis represents the 'Month' and the y-axis represents 'Sales (USD)'.\"\n\nExample Output (Improved):  (See previous response for the updated JSON with axis labels)\n\nImportant Considerations:\n\nData Validation: Perform basic validation and ask for clarification if data is inconsistent or incomplete.\nError Handling: Handle errors gracefully and inform the user if their request cannot be fulfilled.\nChart.js Version: Assume the latest stable version unless specified otherwise.\nBest Practices: Adhere to Chart.js best practices for effective visualizations.\nClear Axis Labels: Prioritize clear and informative axis labels in all generated Chart.js configurations.\n\nFurther instructions:\n- Never generate function callbacks"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        -400,
        704
      ],
      "id": "157cef56-8f38-410c-953c-6e018e13702d",
      "name": "Agente de Visualización de Gráficas",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Webhook').item.json.body.id }}",
        "contextWindowLength": 1
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        -400,
        384
      ],
      "id": "3d64e330-d595-4105-8fc9-4426f197dd4c",
      "name": "Window Buffer Memory"
    },
    {
      "parameters": {
        "name": "generate_a_chart",
        "description": "Call this tool whenever you need to generate a chart. All string values must be properly escaped, especially for multi-line strings. ",
        "workflowId": "={{ $workflow.id }}",
        "specifyInputSchema": true,
        "schemaType": "manual",
        "inputSchema": "{\n\"type\": \"object\",\n\"properties\": {\n\t\"query\": {\n\t\t\"type\": \"string\",\n\t\t\"description\": \"a query describing the chart to generate in json format\"\n\t\t},\n    \"event\": {\n         \"type\": \"string\",\n          \"description\": \"the type of event.  this should always be set to Generate\"\n\t},\n     \"workflow_execution_id\": {\n         \"type\": \"string\",\n          \"description\": \"the workflow execution id\"\n\t}\n}\n}"
      },
      "id": "108128e3-52d9-4548-bf75-635e30a87a2c",
      "name": "Generate chart",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        -288,
        448
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "model": "anthropic/claude-3.5-sonnet",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        -576,
        400
      ],
      "id": "9ae33ab5-ecfb-4424-b781-3fadd2d9b8a7",
      "name": "OpenRouter Chat Model",
      "credentials": {
        "openRouterApi": {
          "id": "kDjBZO625HxQHa05",
          "name": "Open Servicios Conversa"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $('Webhook').item.json.body.grafica_solicitud_ia }}\n\nDatos: {{ JSON.stringify($json) }}\n\n",
        "options": {
          "systemMessage": "=You are a helpful Data Visualization Orchestrator Agent \n\nGuidelines:\n- Use the json data provided by the user, convert it plain text and use the chart tool when the user asks to do so.\n- Cuando te soliciten una gráfica unicamente contesta con el URL sin agregar ningun tipo de comentario. \n\nThe workflow execution id is {{ $execution.id }}\n\nSiempre contesta en lenguaje español. \n\n\n"
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        -448,
        224
      ],
      "id": "867d27c7-1406-4769-a10e-a45fcd13f70d",
      "name": "Agente Orquestador",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -624,
        720
      ],
      "id": "bc890855-1738-4019-be66-ac47c8d2a5b3",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "generacion-de-graficas",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -1424,
        224
      ],
      "id": "4c7b9782-3bb4-467e-ad2d-264127b9375e",
      "name": "Webhook",
      "webhookId": "a07b2fb2-9f60-4ec7-b721-f3501449b9a6"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {
          "responseCode": 200
        }
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -1216,
        224
      ],
      "id": "8e927908-c841-4af8-924c-fd381b6ef60d",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "{{ $json.body.sql_query }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        -1008,
        224
      ],
      "id": "794c85fe-c920-4ecb-894b-53c7e9110b65",
      "name": "Postgres",
      "credentials": {
        "postgres": {
          "id": "dLaj9Cymg7YxbaD5",
          "name": "Postgres Supabase PRODUCCION"
        }
      }
    },
    {
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        -784,
        224
      ],
      "id": "11cbdedf-6c93-49aa-a440-ac4f9150a2d0",
      "name": "Aggregate"
    }
  ],
  "connections": {
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Agente de Visualización de Gráficas",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Agente de Visualización de Gráficas",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agente de Visualización de Gráficas": {
      "main": [
        [
          {
            "node": "Set response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "Agente Orquestador",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Generate chart": {
      "ai_tool": [
        [
          {
            "node": "Agente Orquestador",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Agente Orquestador",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Agente Orquestador": {
      "main": [
        [
          {
            "node": "Postgres1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Agente de Visualización de Gráficas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Respond to Webhook": {
      "main": [
        [
          {
            "node": "Postgres",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Agente Orquestador",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "a77361b54cbf97cd72794f55cde992afbb6fcc5e6f142790a5f41611c8ccda37"
  }
}

Share the output returned by the last node

When it fails, the output from Set response is empty.
When it works, the response contains the proper QuickChart URL with the JSON-encoded chart configuration.

Information on your n8n setup

  • n8n version: 1.108.2
  • Database (default: SQLite): supabase
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own (default)
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):**n8n cloud
  • Operating system: n8n cloud

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.