Zie619/n8n-workflows · warning · Error
Research query must be at least 3 characters long
Error message
Research query must be at least 3 characters long
What it means
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.
Source
Thrown at workflows/Telegram/1341_Telegram_Splitout_Automate_Webhook.json:291
-320
],
"parameters": {
"options": {},
"fieldToSplitOut": " introduction, summary, key_findings, news_highlights, scholarly_insights, wikipedia_summary, sources"
},
"typeVersion": 1,
"notes": "This splitOut node performs automated tasks as part of the workflow."
},
{
"id": "b89d5c35-64c4-4e8c-b432-c2219aba8acc",
"name": "Input Validation",
"type": "n8n-nodes-base.code",
"position": [
180,
-320
],
"parameters": {
"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};"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},
{
"id": "e34f9b0e-a9ca-4011-bfee-c7845c68942b",
"name": "Parse Research Output",
"type": "n8n-nodes-base.code",
"position": [
1300,
-320
],
"parameters": {
"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}];"
},
"typeVersion": 2,
"notes": "This code node performs automated tasks as part of the workflow."
},View on GitHub (pinned to 94007c1445)
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) ...
Example fix
// before
const query = $input.all()[0].json.query;
if (!query || query.trim().length < 3) {
throw new Error('Research query must be at least 3 characters long');
}
// after - friendly branch instead of hard failure
const first = $input.all()[0];
const query = first?.json?.query ?? first?.json?.text ?? '';
if (query.trim().length < 3) {
return { json: { invalid: true, reason: 'Research query must be at least 3 characters long', originalQuery: query } };
} Defensive patterns
Strategy: validation
Validate before calling
const first = $input.all()[0];
const query = first?.json?.query ?? first?.json?.text ?? first?.json?.message ?? '';
if (query.trim().length < 3) {
return { json: { invalid: true, reason: 'Query too short', reply: 'Please send a research query of at least 3 characters.' } };
} Type guard
const isResearchableQuery = (q) => typeof q === 'string' && q.trim().length >= 3;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No input data received
- Approved quantity must be greater than 0
- The video ID parameter is empty.
- One or more input arrays are empty. Check your previous node
- Invalid data structure
AI-assisted analysis of Zie619/n8n-workflows@94007c1445 (2026-08-15).
Data as JSON: /api/errors/24a49d4cc63cdc51.
Report an issue: GitHub.