Basic LLM Chain and prompts
The Basic LLM Chain is the entry point to AI in n8n: one root node with a Chat Model sub-node attached. Input arrives, the model is called, an answer comes out.
The four tasks that come up most in automation are solved by exactly this node:
- Classification — tickets, emails, reviews
- Field extraction — structured data from free text
- Summarisation — shortening long text (the Summarization Chain also exists for this)
- Rewriting — changing tone, translating, reformatting
When you need question-answering over documents, use the Question and Answer Chain — it connects to a vector store through a retriever, or to a workflow.
Writing prompts for automation is different. In a chat window you read the model's answer and correct it. In a workflow the answer goes straight to the next node — there is no human in between. That places three demands on the prompt:
1. The output format must be specified exactly. "Return JSON" is not enough; which fields, which types — all of it.
2. Behaviour for the unknown case must be defined. What should the model do when it cannot find the information? Leave it blank? Return null? Not invent it — that has to be written down.
3. The options must be constrained. For classification, give the list of permitted values, or the model will coin a new label each time.
n8n also has a Structured Output Parser sub-node, which helps enforce that the output matches an expected schema. That is more reliable than describing the format in the prompt.
| Problem | Cause | Fix |
|---|---|---|
| The answer is sometimes JSON, sometimes prose | The format is not specified precisely enough | Attach a Structured Output Parser; show an example in the prompt |
| The model writes a different category name each time | No list of permitted values was given | List them explicitly and say "return only one of these" |
| The model invents information it could not find | No behaviour was defined for the unknown case | Give an explicit instruction: "return `null` if you cannot find it" |
| The result varies for the same input | The model's randomness setting is high | Lower parameters such as temperature on the Chat Model sub-node |
| The answer is cut short on long inputs | The input or output limit was reached | Split the text, process in parts and combine the results |
AI output must always be validated. A model can produce a convincing but wrong result. If the next node writes to a database or messages a customer, an IF check belongs in between: are the required fields present, is the number really a number, is the category in the permitted list?
📚 Sources and documentation
- Basic LLM Chain nodeofficialdocs.n8n.io
- Summarization Chain nodeofficialdocs.n8n.io
- Question and Answer Chain nodeofficialdocs.n8n.io
- Test and improve AI workflowsofficialdocs.n8n.io
For measuring whether a prompt change actually improved the result.