{"record":{"id":"24a49d4cc63cdc51","repo":"Zie619/n8n-workflows","slug":"research-query-must-be-at-least-3-characters-long","errorCode":null,"errorMessage":"Research query must be at least 3 characters long","messagePattern":"Research query must be at least 3 characters long","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"workflows/Telegram/1341_Telegram_Splitout_Automate_Webhook.json","lineNumber":291,"sourceCode":"        -320\n      ],\n      \"parameters\": {\n        \"options\": {},\n        \"fieldToSplitOut\": \" introduction, summary, key_findings, news_highlights, scholarly_insights, wikipedia_summary, sources\"\n      },\n      \"typeVersion\": 1,\n      \"notes\": \"This splitOut node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"b89d5c35-64c4-4e8c-b432-c2219aba8acc\",\n      \"name\": \"Input Validation\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        180,\n        -320\n      ],\n      \"parameters\": {\n        \"jsCode\": \"// Validate input and prepare for processing\\nconst query = $input.all()[0].json.query;\\n\\nif (!query || query.trim().length < 3) {\\n  throw new Error('Research query must be at least 3 characters long');\\n}\\n\\nreturn {\\n  json: {\\n    originalQuery: query,\\n    cleanedQuery: query.trim().toLowerCase(),\\n    timestamp: new Date().toISOString()\\n  }\\n};\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },\n    {\n      \"id\": \"e34f9b0e-a9ca-4011-bfee-c7845c68942b\",\n      \"name\": \"Parse Research Output\",\n      \"type\": \"n8n-nodes-base.code\",\n      \"position\": [\n        1300,\n        -320\n      ],\n      \"parameters\": {\n        \"jsCode\": \"// Get the output string from the Research AI Agent\\nconst outputString = $input.first().json.output;\\n\\n// Parse the string into a JSON object\\nconst parsedOutput = JSON.parse(outputString);\\n\\n// Return the parsed JSON as a single item\\nreturn [{\\n  json: parsedOutput\\n}];\"\n      },\n      \"typeVersion\": 2,\n      \"notes\": \"This code node performs automated tasks as part of the workflow.\"\n    },","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Telegram/1341_Telegram_Splitout_Automate_Webhook.json#L273-L309","documentation":"Thrown by the 'Input Validation' Code node in a Telegram-driven research workflow when the incoming json.query is missing, null, or shorter than 3 non-whitespace characters. It reads $input.all()[0].json.query, enforces a minimum length, then returns the original and cleaned (trimmed, lowercased) query.","triggerScenarios":"A Telegram message/webhook payload without a query field, a message containing only 1-2 characters or whitespace, a command like '/go' with the argument stripped, or wrong field name (q, text, message) so query is undefined.","commonSituations":"Users sending emoji/sticker-only messages, bot command parsing that removes the command but leaves an empty remainder, or a webhook producer changing the payload key. Also note $input.all()[0] throws a raw TypeError (not this message) when zero items arrive — the guard only covers present-but-short values.","solutions":["Log the raw trigger payload (Object.keys($input.all()[0].json)) to confirm which field actually carries the user text.","Map the correct field to query upstream (webhook/Set node), or read the fallback: const q = $json.query || $json.q || $json.message;","Reply to the user with a usage hint instead of throwing (return an item that routes to a Telegram 'please send a longer query' branch).","Guard the empty-items case too: const first = $input.all()[0]; if (!first?.json?.query) ..."],"exampleFix":"// before\nconst query = $input.all()[0].json.query;\nif (!query || query.trim().length < 3) {\n  throw new Error('Research query must be at least 3 characters long');\n}\n\n// after - friendly branch instead of hard failure\nconst first = $input.all()[0];\nconst query = first?.json?.query ?? first?.json?.text ?? '';\nif (query.trim().length < 3) {\n  return { json: { invalid: true, reason: 'Research query must be at least 3 characters long', originalQuery: query } };\n}","handlingStrategy":"validation","validationCode":"const first = $input.all()[0];\nconst query = first?.json?.query ?? first?.json?.text ?? first?.json?.message ?? '';\nif (query.trim().length < 3) {\n  return { json: { invalid: true, reason: 'Query too short', reply: 'Please send a research query of at least 3 characters.' } };\n}","typeGuard":"const isResearchableQuery = (q) => typeof q === 'string' && q.trim().length >= 3;","tryCatchPattern":null,"preventionTips":["Validate user-supplied text at the trigger and reply with usage help instead of throwing — a thrown error in a chat bot is invisible to the user.","Handle both missing-field and empty-items cases (the current code would TypeError on zero items).","Normalize field names once at the webhook node so downstream code sees one canonical 'query' key."],"tags":["n8n","code-node","validation","telegram","user-input","input-validation"],"backgroundTag":null,"analyzedSha":"94007c1445d9258a7da116646b79473e7c7c3282","analyzedAt":"2026-08-15T04:10:37.591Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}