A production-ready n8n workflow that transforms a topic into a polished, professional document through a multi-stage LLM pipeline with automated quality control and conditional routing.
Chat Input (topic)
↓
┌─────────────────────────────────────┐
│ GENERATE OUTLINE │
│ Structured numbered sections │
│ with subsections and descriptions │
│ Output wrapped in <outline> tags │
└──────────────┬──────────────────────┘
↓
┌─────────────────────────────────────┐
│ CHECK OUTLINE CRITERIA │
│ Evaluates against 5 quality gates │
│ Returns PASS or FAIL + explanation │
└──────────────┬──────────────────────┘
↓
┌──────┴──────┐
│ │
PASS FAIL
│ │
↓ ↓
┌────────────┐ ┌───────────────┐
│ EXPAND │ │ EDIT FIELDS │
│ OUTLINE │ │ Return FAIL │
│ SECTIONS │ │ + output │
└─────┬──────┘ └───────────────┘
↓
┌─────────────────────────────────────┐
│ REFINE AND POLISH DOCUMENT │
│ Transitions, intro, conclusion │
│ Professional academic tone │
└──────────────┬──────────────────────┘
↓
Final Polished Document
The workflow evaluates every outline against these requirements before proceeding to document expansion:
- Must have at least 3 main sections
- Must include both benefits and challenges
- Must address ethical considerations
- Must include future perspectives
- Must have clear logical flow between sections
If the outline fails any criterion the workflow stops and returns a FAIL response with explanation — preventing low-quality outlines from being expanded.
- Multi-stage LLM pipeline — outline, evaluate, expand, polish
- Automated quality gate with PASS/FAIL routing
- XML-structured prompts for reliable LLM parsing
- Conditional branching — only expands approved outlines
- OpenRouter model routing — swap models without rebuilding
- Three specialized LLM chains with focused system prompts
- Failure handling — returns failed output with explanation
| Layer | Technology |
|---|---|
| Workflow Engine | n8n |
| Model Routing | OpenRouter |
| LLM | GPT-4.1 (openai/gpt-4.1) |
| Chain Type | LangChain LLM Chain |
| Trigger | n8n Chat Trigger |
Single responsibility per node Each LLM chain does one focused task — generate, evaluate, expand, or polish. This produces more consistent, higher quality output than asking one LLM call to do everything.
Quality gate before expansion Checking the outline before expanding prevents wasting tokens on a poor structure. It mirrors professional document review workflows where an outline is approved before writing begins.
Conditional routing The If node routes PASS outlines to expansion and FAIL outlines to a failure response — making the workflow self-aware and reliable.
XML tag delimiters Wrapping outline and criteria in XML tags gives the LLM clear boundaries for what to evaluate — improving parsing accuracy and evaluation consistency.
- Install and run n8n:
npm install -g n8n
n8n start-
Open n8n at
http://localhost:5678 -
Import the workflow:
- Click Workflows → Import from file
- Upload
workflows/document_generator_v2.json
-
Configure credentials:
- Click Credentials → Add Credential
- Select OpenRouter API
- Add your OpenRouter API key
- Get your key at openrouter.ai/keys
-
Activate the workflow and open the chat interface
- Open the n8n chat interface
- Enter a topic — example:
AI in Healthcare: Benefits, Challenges, and Future Directions
- The workflow will:
- Generate a structured outline
- Evaluate it against 5 criteria
- If PASS — expand and polish into a full document
- If FAIL — return the failure with explanation
Input: "AI in Healthcare"
Stage 1 — Generated Outline:
<outline>
1. Introduction to AI in Healthcare
a. Definition and scope
b. Current state of adoption
2. Benefits of AI in Clinical Practice
a. Diagnostic accuracy improvements
b. Operational efficiency gains
3. Challenges and Limitations
a. Data privacy concerns
b. Implementation barriers
4. Ethical Considerations
a. Bias in AI systems
b. Patient consent and transparency
5. Future Perspectives
a. Emerging technologies
b. Policy recommendations
</outline>
Stage 2 — Quality Check:
PASS — Outline meets all 5 criteria. Contains 5 main
sections, addresses benefits and challenges, includes
ethical considerations in section 4, covers future
perspectives in section 5, and maintains logical flow.
Stage 3 — Final Document: A fully expanded, polished professional document with introduction, detailed sections, smooth transitions, and conclusion.
Change the target audience Update the Style Guide in the Generate Outline node:
Target audience: [your audience here]
Change the quality criteria Update the criteria list in Check Outline Criteria node to match your document requirements.
Change the LLM model Update the OpenRouter Chat Model nodes to use any model available on OpenRouter — no other changes needed.
Add more quality criteria Add numbered items to the criteria section in the Check Outline Criteria node.
| File | Description |
|---|---|
| workflows/document_generator_v2.json | Fixed XML tags and typos |
| changelog.md | Full version history |
| Repo | Pattern | Framework |
|---|---|---|
| ai-agent-team-supervisor-pattern | Supervisor Pattern | Flowise AgentFlows V2/V3 |
| ai-multi-agent-content-pipeline | Sequential Agents | Flowise Sequential |
| data-analysis-agent-app | Interactive Agent | Next.js + FastAPI |
| deep-research-agent | Research App | Claude Code + Next.js |
| ai-food-chatbot-agent | Agentic RAG | Flowise + Postgres |
Paul Orlando Creative Technologist | AI Agent Developer | Data Analytics 🌐 paulforlando.com 💼 LinkedIn 🐙 GitHub
MIT License