@n8n/workflow-sdk 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/build.tsbuildinfo +1 -1
  2. package/dist/generate-types/generate-types.js +1 -1
  3. package/dist/generate-types/generate-types.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +4 -2
  6. package/dist/index.js.map +1 -1
  7. package/dist/prompts/best-practices/guides/chatbot.d.ts +7 -0
  8. package/dist/prompts/best-practices/guides/chatbot.js +120 -0
  9. package/dist/prompts/best-practices/guides/chatbot.js.map +1 -0
  10. package/dist/prompts/best-practices/guides/content-generation.d.ts +7 -0
  11. package/dist/prompts/best-practices/guides/content-generation.js +117 -0
  12. package/dist/prompts/best-practices/guides/content-generation.js.map +1 -0
  13. package/dist/prompts/best-practices/guides/data-analysis.d.ts +7 -0
  14. package/dist/prompts/best-practices/guides/data-analysis.js +369 -0
  15. package/dist/prompts/best-practices/guides/data-analysis.js.map +1 -0
  16. package/dist/prompts/best-practices/guides/data-extraction.d.ts +7 -0
  17. package/dist/prompts/best-practices/guides/data-extraction.js +124 -0
  18. package/dist/prompts/best-practices/guides/data-extraction.js.map +1 -0
  19. package/dist/prompts/best-practices/guides/data-persistence.d.ts +7 -0
  20. package/dist/prompts/best-practices/guides/data-persistence.js +199 -0
  21. package/dist/prompts/best-practices/guides/data-persistence.js.map +1 -0
  22. package/dist/prompts/best-practices/guides/data-transformation.d.ts +7 -0
  23. package/dist/prompts/best-practices/guides/data-transformation.js +148 -0
  24. package/dist/prompts/best-practices/guides/data-transformation.js.map +1 -0
  25. package/dist/prompts/best-practices/guides/document-processing.d.ts +7 -0
  26. package/dist/prompts/best-practices/guides/document-processing.js +334 -0
  27. package/dist/prompts/best-practices/guides/document-processing.js.map +1 -0
  28. package/dist/prompts/best-practices/guides/enrichment.d.ts +7 -0
  29. package/dist/prompts/best-practices/guides/enrichment.js +273 -0
  30. package/dist/prompts/best-practices/guides/enrichment.js.map +1 -0
  31. package/dist/prompts/best-practices/guides/form-input.d.ts +7 -0
  32. package/dist/prompts/best-practices/guides/form-input.js +175 -0
  33. package/dist/prompts/best-practices/guides/form-input.js.map +1 -0
  34. package/dist/prompts/best-practices/guides/human-in-the-loop.d.ts +7 -0
  35. package/dist/prompts/best-practices/guides/human-in-the-loop.js +270 -0
  36. package/dist/prompts/best-practices/guides/human-in-the-loop.js.map +1 -0
  37. package/dist/prompts/best-practices/guides/knowledge-base.d.ts +7 -0
  38. package/dist/prompts/best-practices/guides/knowledge-base.js +270 -0
  39. package/dist/prompts/best-practices/guides/knowledge-base.js.map +1 -0
  40. package/dist/prompts/best-practices/guides/monitoring.d.ts +7 -0
  41. package/dist/prompts/best-practices/guides/monitoring.js +173 -0
  42. package/dist/prompts/best-practices/guides/monitoring.js.map +1 -0
  43. package/dist/prompts/best-practices/guides/notification.d.ts +7 -0
  44. package/dist/prompts/best-practices/guides/notification.js +137 -0
  45. package/dist/prompts/best-practices/guides/notification.js.map +1 -0
  46. package/dist/prompts/best-practices/guides/scheduling.d.ts +7 -0
  47. package/dist/prompts/best-practices/guides/scheduling.js +154 -0
  48. package/dist/prompts/best-practices/guides/scheduling.js.map +1 -0
  49. package/dist/prompts/best-practices/guides/scraping-and-research.d.ts +7 -0
  50. package/dist/prompts/best-practices/guides/scraping-and-research.js +160 -0
  51. package/dist/prompts/best-practices/guides/scraping-and-research.js.map +1 -0
  52. package/dist/prompts/best-practices/guides/triage.d.ts +7 -0
  53. package/dist/prompts/best-practices/guides/triage.js +151 -0
  54. package/dist/prompts/best-practices/guides/triage.js.map +1 -0
  55. package/dist/prompts/best-practices/index.d.ts +20 -0
  56. package/dist/prompts/best-practices/index.js +69 -0
  57. package/dist/prompts/best-practices/index.js.map +1 -0
  58. package/dist/prompts/best-practices/types.d.ts +25 -0
  59. package/dist/prompts/best-practices/types.js +40 -0
  60. package/dist/prompts/best-practices/types.js.map +1 -0
  61. package/dist/prompts/index.d.ts +3 -0
  62. package/dist/prompts/index.js +25 -0
  63. package/dist/prompts/index.js.map +1 -0
  64. package/dist/prompts/node-guidance/index.d.ts +3 -0
  65. package/dist/prompts/node-guidance/index.js +20 -0
  66. package/dist/prompts/node-guidance/index.js.map +1 -0
  67. package/dist/prompts/node-guidance/node-recommendations/audio-generation.d.ts +2 -0
  68. package/dist/prompts/node-guidance/node-recommendations/audio-generation.js +18 -0
  69. package/dist/prompts/node-guidance/node-recommendations/audio-generation.js.map +1 -0
  70. package/dist/prompts/node-guidance/node-recommendations/format-recommendation.d.ts +2 -0
  71. package/dist/prompts/node-guidance/node-recommendations/format-recommendation.js +27 -0
  72. package/dist/prompts/node-guidance/node-recommendations/format-recommendation.js.map +1 -0
  73. package/dist/prompts/node-guidance/node-recommendations/image-generation.d.ts +2 -0
  74. package/dist/prompts/node-guidance/node-recommendations/image-generation.js +18 -0
  75. package/dist/prompts/node-guidance/node-recommendations/image-generation.js.map +1 -0
  76. package/dist/prompts/node-guidance/node-recommendations/index.d.ts +6 -0
  77. package/dist/prompts/node-guidance/node-recommendations/index.js +17 -0
  78. package/dist/prompts/node-guidance/node-recommendations/index.js.map +1 -0
  79. package/dist/prompts/node-guidance/node-recommendations/text-manipulation.d.ts +2 -0
  80. package/dist/prompts/node-guidance/node-recommendations/text-manipulation.js +27 -0
  81. package/dist/prompts/node-guidance/node-recommendations/text-manipulation.js.map +1 -0
  82. package/dist/prompts/node-guidance/node-recommendations/types.d.ts +26 -0
  83. package/dist/prompts/node-guidance/node-recommendations/types.js +16 -0
  84. package/dist/prompts/node-guidance/node-recommendations/types.js.map +1 -0
  85. package/dist/prompts/node-guidance/node-recommendations/video-generation.d.ts +2 -0
  86. package/dist/prompts/node-guidance/node-recommendations/video-generation.js +15 -0
  87. package/dist/prompts/node-guidance/node-recommendations/video-generation.js.map +1 -0
  88. package/dist/prompts/node-guidance/node-tips/index.d.ts +3 -0
  89. package/dist/prompts/node-guidance/node-tips/index.js +8 -0
  90. package/dist/prompts/node-guidance/node-tips/index.js.map +1 -0
  91. package/dist/prompts/node-guidance/node-tips/structured-output-parser.d.ts +2 -0
  92. package/dist/prompts/node-guidance/node-tips/structured-output-parser.js +35 -0
  93. package/dist/prompts/node-guidance/node-tips/structured-output-parser.js.map +1 -0
  94. package/dist/prompts/node-guidance/node-tips/types.d.ts +7 -0
  95. package/dist/prompts/node-guidance/node-tips/types.js +3 -0
  96. package/dist/prompts/node-guidance/node-tips/types.js.map +1 -0
  97. package/dist/prompts/node-guidance/node-tips/webhook.d.ts +2 -0
  98. package/dist/prompts/node-guidance/node-tips/webhook.js +38 -0
  99. package/dist/prompts/node-guidance/node-tips/webhook.js.map +1 -0
  100. package/dist/prompts/node-guidance/parameter-guides/embedding-nodes.d.ts +2 -0
  101. package/dist/prompts/node-guidance/parameter-guides/embedding-nodes.js +70 -0
  102. package/dist/prompts/node-guidance/parameter-guides/embedding-nodes.js.map +1 -0
  103. package/dist/prompts/node-guidance/parameter-guides/gmail.d.ts +2 -0
  104. package/dist/prompts/node-guidance/parameter-guides/gmail.js +53 -0
  105. package/dist/prompts/node-guidance/parameter-guides/gmail.js.map +1 -0
  106. package/dist/prompts/node-guidance/parameter-guides/http-request.d.ts +2 -0
  107. package/dist/prompts/node-guidance/parameter-guides/http-request.js +139 -0
  108. package/dist/prompts/node-guidance/parameter-guides/http-request.js.map +1 -0
  109. package/dist/prompts/node-guidance/parameter-guides/if-node.d.ts +2 -0
  110. package/dist/prompts/node-guidance/parameter-guides/if-node.js +159 -0
  111. package/dist/prompts/node-guidance/parameter-guides/if-node.js.map +1 -0
  112. package/dist/prompts/node-guidance/parameter-guides/index.d.ts +12 -0
  113. package/dist/prompts/node-guidance/parameter-guides/index.js +26 -0
  114. package/dist/prompts/node-guidance/parameter-guides/index.js.map +1 -0
  115. package/dist/prompts/node-guidance/parameter-guides/predecessor-output.d.ts +2 -0
  116. package/dist/prompts/node-guidance/parameter-guides/predecessor-output.js +25 -0
  117. package/dist/prompts/node-guidance/parameter-guides/predecessor-output.js.map +1 -0
  118. package/dist/prompts/node-guidance/parameter-guides/resource-locator.d.ts +2 -0
  119. package/dist/prompts/node-guidance/parameter-guides/resource-locator.js +40 -0
  120. package/dist/prompts/node-guidance/parameter-guides/resource-locator.js.map +1 -0
  121. package/dist/prompts/node-guidance/parameter-guides/set-node.d.ts +2 -0
  122. package/dist/prompts/node-guidance/parameter-guides/set-node.js +94 -0
  123. package/dist/prompts/node-guidance/parameter-guides/set-node.js.map +1 -0
  124. package/dist/prompts/node-guidance/parameter-guides/switch-node.d.ts +2 -0
  125. package/dist/prompts/node-guidance/parameter-guides/switch-node.js +75 -0
  126. package/dist/prompts/node-guidance/parameter-guides/switch-node.js.map +1 -0
  127. package/dist/prompts/node-guidance/parameter-guides/system-message.d.ts +2 -0
  128. package/dist/prompts/node-guidance/parameter-guides/system-message.js +96 -0
  129. package/dist/prompts/node-guidance/parameter-guides/system-message.js.map +1 -0
  130. package/dist/prompts/node-guidance/parameter-guides/text-fields.d.ts +2 -0
  131. package/dist/prompts/node-guidance/parameter-guides/text-fields.js +31 -0
  132. package/dist/prompts/node-guidance/parameter-guides/text-fields.js.map +1 -0
  133. package/dist/prompts/node-guidance/parameter-guides/tool-nodes.d.ts +2 -0
  134. package/dist/prompts/node-guidance/parameter-guides/tool-nodes.js +76 -0
  135. package/dist/prompts/node-guidance/parameter-guides/tool-nodes.js.map +1 -0
  136. package/dist/prompts/node-guidance/parameter-guides/types.d.ts +18 -0
  137. package/dist/prompts/node-guidance/parameter-guides/types.js +3 -0
  138. package/dist/prompts/node-guidance/parameter-guides/types.js.map +1 -0
  139. package/dist/prompts/node-selection/ai-nodes.d.ts +2 -0
  140. package/dist/prompts/node-selection/ai-nodes.js +35 -0
  141. package/dist/prompts/node-selection/ai-nodes.js.map +1 -0
  142. package/dist/prompts/node-selection/connection-parameters.d.ts +1 -0
  143. package/dist/prompts/node-selection/connection-parameters.js +13 -0
  144. package/dist/prompts/node-selection/connection-parameters.js.map +1 -0
  145. package/dist/prompts/node-selection/index.d.ts +5 -0
  146. package/dist/prompts/node-selection/index.js +16 -0
  147. package/dist/prompts/node-selection/index.js.map +1 -0
  148. package/dist/prompts/node-selection/native-preference.d.ts +1 -0
  149. package/dist/prompts/node-selection/native-preference.js +18 -0
  150. package/dist/prompts/node-selection/native-preference.js.map +1 -0
  151. package/dist/prompts/node-selection/trigger-selection.d.ts +1 -0
  152. package/dist/prompts/node-selection/trigger-selection.js +23 -0
  153. package/dist/prompts/node-selection/trigger-selection.js.map +1 -0
  154. package/dist/prompts/node-selection/use-case-patterns.d.ts +2 -0
  155. package/dist/prompts/node-selection/use-case-patterns.js +58 -0
  156. package/dist/prompts/node-selection/use-case-patterns.js.map +1 -0
  157. package/dist/prompts/sdk-reference/additional-functions.d.ts +1 -0
  158. package/dist/prompts/sdk-reference/additional-functions.js +20 -0
  159. package/dist/prompts/sdk-reference/additional-functions.js.map +1 -0
  160. package/dist/prompts/sdk-reference/expressions.d.ts +1 -0
  161. package/dist/prompts/sdk-reference/expressions.js +34 -0
  162. package/dist/prompts/sdk-reference/expressions.js.map +1 -0
  163. package/dist/prompts/sdk-reference/index.d.ts +5 -0
  164. package/dist/prompts/sdk-reference/index.js +14 -0
  165. package/dist/prompts/sdk-reference/index.js.map +1 -0
  166. package/dist/prompts/sdk-reference/workflow-patterns-detailed.d.ts +1 -0
  167. package/dist/prompts/sdk-reference/workflow-patterns-detailed.js +398 -0
  168. package/dist/prompts/sdk-reference/workflow-patterns-detailed.js.map +1 -0
  169. package/dist/prompts/sdk-reference/workflow-patterns.d.ts +2 -0
  170. package/dist/prompts/sdk-reference/workflow-patterns.js +479 -0
  171. package/dist/prompts/sdk-reference/workflow-patterns.js.map +1 -0
  172. package/dist/prompts/sdk-reference/workflow-rules.d.ts +1 -0
  173. package/dist/prompts/sdk-reference/workflow-rules.js +23 -0
  174. package/dist/prompts/sdk-reference/workflow-rules.js.map +1 -0
  175. package/dist/workflow-builder/plugins/defaults.js +1 -0
  176. package/dist/workflow-builder/plugins/defaults.js.map +1 -1
  177. package/dist/workflow-builder/plugins/validators/filter-node-validator.d.ts +2 -0
  178. package/dist/workflow-builder/plugins/validators/filter-node-validator.js +90 -0
  179. package/dist/workflow-builder/plugins/validators/filter-node-validator.js.map +1 -0
  180. package/dist/workflow-builder/plugins/validators/index.d.ts +1 -0
  181. package/dist/workflow-builder/plugins/validators/index.js +3 -1
  182. package/dist/workflow-builder/plugins/validators/index.js.map +1 -1
  183. package/package.json +50 -4
@@ -0,0 +1,334 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentProcessingBestPractices = void 0;
4
+ const types_1 = require("../types");
5
+ class DocumentProcessingBestPractices {
6
+ constructor() {
7
+ this.technique = types_1.WorkflowTechnique.DOCUMENT_PROCESSING;
8
+ this.version = '1.0.0';
9
+ this.documentation = `# Best Practices: Document Processing Workflows
10
+
11
+ ## Workflow Design
12
+
13
+ Document processing workflows extract and act on content from files like PDFs, images, Word documents, and spreadsheets. Design your workflow following these core patterns:
14
+
15
+ ### Core Architecture Pattern
16
+ Trigger → Capture Binary → Extract Text → Parse/Transform → Route to Destination → Notify
17
+
18
+ ### Common Flow Patterns
19
+
20
+ **Simple Document Processing:**
21
+ - Gmail Trigger → Check file type → Extract from File → DataTable → Slack notification
22
+ - Best for: Basic text-based PDFs with straightforward data extraction
23
+
24
+ **Complex Document Processing with AI:**
25
+ - Webhook → File Type Check → OCR (if image) → AI Extract → Validate → CRM Update → Multiple notifications
26
+ - Best for: Varied document formats requiring intelligent parsing
27
+
28
+ **Batch Document Processing:**
29
+ - Main workflow: Schedule Trigger → Fetch Files → Split In Batches → Sub-workflow → Merge Results → Bulk Update
30
+ - Sub-workflow When Executed by Another Workflow -> Process result
31
+ - Best for: High-volume processing with API rate limits
32
+
33
+ **Multi-Source Document Aggregation:**
34
+ - Multiple Triggers (Email + Drive + Webhook) → Set common fields → Standardize → Process → Store
35
+ - Best for: Documents from various channels needing unified processing
36
+
37
+ ### Branching Strategy
38
+
39
+ Always branch early based on document characteristics:
40
+ - **File Type Branching**: Use IF/Switch nodes immediately after ingestion to route PDFs vs images vs spreadsheets
41
+ - **Provider Branching**: Route documents to provider-specific processing (e.g., different invoice formats)
42
+ - **Quality Branching**: Separate high-confidence extractions from those needing manual review
43
+
44
+ ## Binary Data Management
45
+ Documents in n8n are handled as binary data that must be carefully preserved throughout the workflow.
46
+
47
+ ### Referencing Binary Data from Other Nodes
48
+ When you need to reference binary data from a previous node, use this syntax:
49
+ - Expression: '{{ $('Node Name').item.binary.property_name }}' or {{ $binary.property_name }} if previous item
50
+ - Example for Gmail attachments: '{{ $('Gmail Trigger').item.binary.attachment_0 }}' or {{ $binary.attachment_0 }} if previous item
51
+ - Example for webhook data: '{{ $('Webhook').item.binary.data }}' or {{ $binary.data }} if previous item
52
+ - Important: The property name depends on how the previous node names the binary data
53
+
54
+ ### Preserving Binary Data
55
+ - Many nodes (Code, Edit Fields, AI nodes) output JSON and drop binary data by default
56
+ - Use parallel branches: one for processing, one to preserve the original file
57
+ - Rejoin branches with Merge node in pass-through mode
58
+ - Alternative: Configure nodes to keep binary (e.g., Edit field node's "Include Other Input Fields" option ON)
59
+
60
+ ### Memory Optimization
61
+ For high-volume processing:
62
+ - Process files sequentially or in small batches
63
+ - Drop unnecessary binary data after extraction to free memory
64
+
65
+ ### File Metadata
66
+ Documents uploaded via a form trigger will have various bits of metadata available - filename, mimetype and size.
67
+ These are accessible using an expression like {{ $json.documents[0].mimetype }} to access each of the document's details.
68
+ Multiple files can be uploaded to a form which is the reason for the documents array.
69
+
70
+ ## Text Extraction Strategy
71
+
72
+ Choose extraction method based on document type and content:
73
+
74
+ ### Critical: File Type Detection
75
+ **ALWAYS check the file type before using Extract from File node** (unless the file type is already known):
76
+ - Use IF node to check file extension or MIME type first
77
+ - The Extract from File node has multiple operations, each for a specific file type:
78
+ - "Extract from PDF" for PDF files
79
+ - "Extract from MS Excel" for Excel files (.xlsx, .xls)
80
+ - "Extract from MS Word" for Word documents (.docx, .doc)
81
+ - "Extract from CSV" for CSV files
82
+ - "Extract from HTML" for HTML files
83
+ - "Extract from RTF" for Rich Text Format files
84
+ - "Extract from Text File" for plain text files
85
+ - Using the wrong operation will result in errors or empty output
86
+
87
+ ### Decision Tree for Extraction
88
+ 1. **Check file type** → Route to appropriate extraction method
89
+ 2. **Scanned image/PDF?** → Use OCR service (OCR.space, AWS Textract, Google Vision)
90
+ 3. **Structured invoice/receipt?** → Use specialized parser (Mindee) or AI extraction
91
+ 4. **Text-based document?** → Use Extract from File with the correct operation for that file type
92
+
93
+ ### Fallback Strategy
94
+ Always implement fallback for extraction failures:
95
+ - Check if text extraction returns empty
96
+ - If empty, automatically route to OCR
97
+ - If OCR fails, send to manual review queue
98
+
99
+ ## Data Parsing & Classification
100
+
101
+ ### AI-Powered Extraction Pattern
102
+ For varied or complex documents:
103
+
104
+ Option 1 - Using Document Loader (Recommended for binary files):
105
+ 1. Pass binary data directly to Document Loader node (set Data Source to "Binary")
106
+ 2. Connect to AI Agent or LLM Chain for processing
107
+ 3. Validate extracted fields before processing
108
+
109
+ Option 2 - Using text extraction:
110
+ 1. Extract raw text using Extract from File or OCR
111
+ 2. Pass to AI Agent or LLM Chain with structured prompt
112
+ 3. Validate extracted fields before processing
113
+
114
+ Example system prompt structure:
115
+ "Extract the following fields from the document: [field list]. Return as JSON with this schema: [schema example]"
116
+
117
+ ### Document Classification Flow
118
+ Classify before processing for better accuracy:
119
+ 1. Initial AI classification (Invoice vs Receipt vs Contract)
120
+ 2. Route to specialized sub-workflow based on type
121
+ 3. Use type-specific prompts and validation rules
122
+ 4. This reduces errors and improves extraction quality
123
+
124
+ ## Error Handling Strategy
125
+
126
+ Build resilience at every step:
127
+
128
+ ### Validation Checkpoints
129
+ - After extraction: Verify text not empty
130
+ - After AI parsing: Validate JSON schema
131
+ - Before database insert: Check required fields
132
+ - After API calls: Verify success response
133
+
134
+ ## Performance Optimization
135
+
136
+ ### Batch Processing Strategy
137
+ - Use Split In Batches node: process 5-10 files at a time
138
+ - Implement delays between batches for rate-limited APIs
139
+ - Monitor memory usage and adjust batch size accordingly
140
+
141
+ ## Recommended Nodes
142
+
143
+ ### Triggers & Input
144
+
145
+ **Gmail Trigger (n8n-nodes-base.gmailTrigger)**
146
+ Purpose: Monitor Gmail for emails with attachments (Recommended over IMAP)
147
+ Advantages: Real-time processing, simpler authentication, better integration with Google Workspace
148
+ Critical Configuration for Attachments:
149
+ - **MUST set "Simplify" to FALSE** - otherwise attachments won't be available
150
+ - **MUST set "Download Attachments" to TRUE** to retrieve files
151
+ - Set appropriate label filters
152
+ - Set "Property Prefix Name" (e.g., "attachment_") - attachments will be named with this prefix plus index
153
+ - Important: When referencing its binary data, it will be referenced "attachment_0", "attachment_1", etc., NOT "data"
154
+
155
+ **Email Read (IMAP) (n8n-nodes-base.emailReadImap)**
156
+ Purpose: Alternative email fetching if there's no specialized node for email provider
157
+ Configuration:
158
+ - Enable "Download Attachments" to retrieve files
159
+ - Set "Property Prefix Name" (e.g., "attachment_") - attachments will be named with this prefix plus index
160
+ - Important: When referencing binary data, it will be referenced "attachment_0", "attachment_1", etc., NOT "data"
161
+
162
+ **HTTP Webhook (n8n-nodes-base.webhook)**
163
+ Purpose: Receive file uploads from web forms
164
+ Configuration: Enable "Raw Body" for binary data
165
+
166
+ **Google Drive Trigger (n8n-nodes-base.googleDriveTrigger)**
167
+ Purpose: Monitor folders for new documents
168
+ Configuration: Set appropriate folder and file type filters
169
+
170
+ ### Text Extraction
171
+
172
+ **Extract from File (n8n-nodes-base.extractFromFile)**
173
+ Purpose: Extract text from various file formats using format-specific operations
174
+ Critical: ALWAYS check file type first with an IF or Switch before and select the correct operation (Extract from PDF, Extract from MS Excel, etc.)
175
+ Critical: If the user requests handling of multiple file types (PDF, CSV, JSON, etc) then a Switch (n8n-nodes-base.switch) node should be used
176
+ to check the file type before text extraction. Multiple text extraction nodes should be used to handle each of the different file types. For example,
177
+ if the workflow contains a form trigger node which receives a file, then a Switch node MUST be used to split the different options out to different extraction nodes.
178
+ Output: Extracted text is returned under the "text" key in JSON (e.g., access with {{ $json.text }})
179
+ Pitfalls:
180
+ - Returns empty for scanned documents - always check and fallback to OCR; Using wrong operation causes errors
181
+ - If connecting to a document upload form (n8n-nodes-base.formTrigger) use a File field type and then connect it to the extract from file node using the field name.
182
+ For example if creating a form trigger with field "Upload Document" then set the extract from file input binary field to "Upload_Document"
183
+
184
+ **AWS Textract (n8n-nodes-base.awsTextract)**
185
+ Purpose: Advanced OCR with table and form detection
186
+ Best for: Structured documents like invoices and forms
187
+
188
+ **Mindee (n8n-nodes-base.mindee)**
189
+ Purpose: Specialized invoice and receipt parsing
190
+ Returns: Structured JSON with line items, totals, dates
191
+
192
+ ### Data Processing
193
+
194
+ **AI Agent (@n8n/n8n-nodes-langchain.agent)**
195
+ Purpose: Intelligent document parsing and decision making
196
+ Configuration: Include structured output tools for consistent results
197
+
198
+ **LLM Chain (@n8n/n8n-nodes-langchain.chainLlm)**
199
+ Purpose: Document classification and data extraction
200
+
201
+ **Document Loader (@n8n/n8n-nodes-langchain.documentLoader)**
202
+ Purpose: Load and process documents directly from binary data for AI processing
203
+ Critical: Use the "Binary" data source option to handle binary files directly - no need to convert to JSON first
204
+ Configuration: Select "Binary" as Data Source, specify the binary property name (by default data unless renamed in a previous node)
205
+ Best for: Direct document processing in AI workflows without intermediate extraction steps
206
+
207
+ **Structured Output Parser (@n8n/n8n-nodes-langchain.outputParserStructured)**
208
+ Purpose: Ensure AI outputs match expected JSON schema
209
+ Critical for: Database inserts and API calls
210
+
211
+ ### Vector Storage (for RAG/Semantic Search)
212
+ **Simple Vector Store (@n8n/n8n-nodes-langchain.vectorStore) - RECOMMENDED**
213
+ Purpose: Easy-to-setup vector storage for document embeddings
214
+ Advantages:
215
+ - No external dependencies or API keys required
216
+ - Works out of the box with local storage
217
+ - Perfect for prototyping and small to medium datasets
218
+ Configuration: Just connect and use - no complex setup needed
219
+ Best for: Most document processing workflows that need semantic search
220
+
221
+ ### Flow Control
222
+
223
+ **Split In Batches (n8n-nodes-base.splitInBatches)**
224
+ Purpose: Process multiple documents in controlled batches
225
+ Configuration: Set batch size based on API limits and memory
226
+ Outputs (in order):
227
+ - Output 0 "done": Executes after all batches are processed - use for final aggregation or notifications
228
+ - Output 1 "loop": Connect processing nodes here - executes for each batch
229
+ Important: Connect processing logic to the second output (loop), completion logic to the first output (done)
230
+
231
+ **Merge (n8n-nodes-base.merge)**
232
+ Purpose: Combine data from multiple branches that need to execute together
233
+ Critical: Merge node waits for ALL input branches to complete - do NOT use for independent/optional branches
234
+ Modes: Use "Pass Through" to preserve binary from one branch
235
+
236
+ **Edit Fields (Set) (n8n-nodes-base.set)**
237
+ Purpose: Better choice for combining data from separate/independent branches
238
+ Use for: Adding fields from different sources, preserving binary while adding processed data
239
+ Configuration: Set common fields and use "Include Other Input Fields" ON to preserve existing data including binary
240
+
241
+ **Execute Workflow Trigger (n8n-nodes-base.executeWorkflowTrigger)**
242
+ Purpose: Start point for sub-workflows that are called by other workflows
243
+ Configuration: Automatically receives data from the calling workflow including binary data
244
+ Best practice: Use for modular workflow design, heavy processing tasks, or reusable workflow components
245
+ Pairing: Must be used with Execute Workflow node in the parent workflow
246
+
247
+ **Execute Workflow (n8n-nodes-base.executeWorkflow)**
248
+ Purpose: Call and execute another workflow from within the current workflow
249
+ Critical configurations:
250
+ - Workflow ID: Use expression "{{ $workflow.id }}" to reference sub-workflows in the same workflow
251
+ - Choose execution mode: "Run Once for All Items" or "Run Once for Each Item"
252
+ - Binary data is automatically passed to the sub-workflow
253
+ Best practice: Use for delegating heavy processing, creating reusable modules, or managing memory in large batch operations
254
+
255
+ ### Data Destinations
256
+
257
+ **DataTable (n8n-nodes-base.dataTable)**
258
+ Purpose: Store extracted data in n8n's built-in data tables
259
+ Operations: Insert, Update, Select rows without external dependencies
260
+ Best for: Self-contained workflows that don't require external storage
261
+
262
+ **Google Sheets (n8n-nodes-base.googleSheets)**
263
+ Purpose: Log extracted data in external spreadsheet
264
+ Operations: Use "Append" for new rows, "Update" with key column for existing
265
+ Best for: Collaborative review and manual data validation
266
+
267
+ **Database Nodes**
268
+ - Postgres (n8n-nodes-base.postgres)
269
+ - MySQL (n8n-nodes-base.mySql)
270
+ - MongoDB (n8n-nodes-base.mongoDb)
271
+ Purpose: Store structured extraction results in production databases
272
+ Best Practice: Validate data schema before insert
273
+
274
+ ### Utilities
275
+
276
+ **IF/Switch (n8n-nodes-base.if, n8n-nodes-base.switch)**
277
+ Purpose: Route based on file type, extraction quality, or classification
278
+
279
+ **Function/Code (n8n-nodes-base.function, n8n-nodes-base.code)**
280
+ Purpose: Custom validation, data transformation, or regex extraction
281
+
282
+ **HTTP Request (n8n-nodes-base.httpRequest)**
283
+ Purpose: Call external OCR APIs (OCR.space, Google Vision, Mistral OCR)
284
+ Configuration: Set "Response Format: File" for downloads
285
+ Critical: NEVER set API keys directly in the request - user can set credentials from the UI for secure API key management
286
+
287
+ ## Common Pitfalls to Avoid
288
+
289
+ ### Binary Data Loss
290
+
291
+ **Problem**: Binary file "disappears" after processing nodes
292
+ **Solution**:
293
+ - Use Merge node to reattach binary after processing
294
+ - Or configure nodes to explicitly keep binary data
295
+ - In Code nodes: copy items[0].binary to output
296
+
297
+ ### Incorrect OCR Fallback
298
+
299
+ **Problem**: Not detecting when text extraction fails
300
+ **Solution**:
301
+ - Always check if extraction result is empty
302
+ - Implement automatic OCR fallback for scanned documents
303
+ - Don't assume all PDFs have extractable text
304
+
305
+ ### API Format Mismatches
306
+
307
+ **Problem**: Sending files in wrong format to APIs
308
+ **Solution**:
309
+ - Check if API needs multipart/form-data vs Base64
310
+ - Use "Extract from File" and "Convert to File" format conversion
311
+
312
+ ### Memory Overload
313
+
314
+ **Problem**: Workflow crashes with large or multiple files
315
+ **Solution**:
316
+ - Process files sequentially or in small batches
317
+ - Enable filesystem mode for binary data storage
318
+ - Drop unnecessary data after extraction
319
+ - Create a sub-workflow in the same workflow using "When Executed by Another Workflow" and "Execute Workflow". Delegate the heavy part of the workflow to the sub-workflow.
320
+
321
+ ### Duplicate Processing
322
+
323
+ **Problem**: Same documents processed repeatedly
324
+ **Solution**:
325
+ - Configure email triggers to mark as read
326
+ - Use "unseen" filters for email fetching
327
+ - Implement deduplication logic based on file hash or name`;
328
+ }
329
+ getDocumentation() {
330
+ return this.documentation;
331
+ }
332
+ }
333
+ exports.DocumentProcessingBestPractices = DocumentProcessingBestPractices;
334
+ //# sourceMappingURL=document-processing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-processing.js","sourceRoot":"","sources":["../../../../src/prompts/best-practices/guides/document-processing.ts"],"names":[],"mappings":";;;AACA,oCAA6C;AAE7C,MAAa,+BAA+B;IAA5C;QACU,cAAS,GAAG,yBAAiB,CAAC,mBAAmB,CAAC;QAClD,YAAO,GAAG,OAAO,CAAC;QAEV,kBAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2DA8TyB,CAAC;IAK5D,CAAC;IAHA,gBAAgB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CACD;AAvUD,0EAuUC"}
@@ -0,0 +1,7 @@
1
+ import type { BestPracticesDocument } from '../types';
2
+ export declare class EnrichmentBestPractices implements BestPracticesDocument {
3
+ readonly technique: "enrichment";
4
+ readonly version = "1.0.0";
5
+ private readonly documentation;
6
+ getDocumentation(): string;
7
+ }
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnrichmentBestPractices = void 0;
4
+ const types_1 = require("../types");
5
+ class EnrichmentBestPractices {
6
+ constructor() {
7
+ this.technique = types_1.WorkflowTechnique.ENRICHMENT;
8
+ this.version = '1.0.0';
9
+ this.documentation = `# Best Practices: Data Enrichment Workflows
10
+
11
+ ## Workflow Design
12
+
13
+ ### Core Principles
14
+ - Start with data retrieval and validation before enrichment
15
+ - Process data incrementally to avoid overwhelming APIs
16
+ - Always include error handling for failed enrichments
17
+ - Design for reusability with sub-workflows where appropriate
18
+
19
+ ### Architecture Pattern
20
+ 1. **Input Stage**: Validate and prepare incoming data
21
+ 2. **Enrichment Stage**: Parallel or sequential API calls based on dependencies
22
+ 3. **Transformation Stage**: Normalize and merge enriched data
23
+ 4. **Output Stage**: Format and deliver enriched results
24
+
25
+ ## Data Enrichment Guidelines
26
+
27
+ ### 1. Input Validation
28
+ **Always validate incoming data before enrichment**
29
+ - Use IF node (n8n-nodes-base.if) to check for required fields
30
+ - Implement Set node (n8n-nodes-base.set) to standardize data format
31
+ - Add Code node (n8n-nodes-base.code) for complex validation logic
32
+
33
+ ### 2. API Rate Limiting
34
+ **Respect external service limits**
35
+ - Implement Wait node (n8n-nodes-base.wait) between batch requests
36
+ - Use SplitInBatches node (n8n-nodes-base.splitInBatches) for large datasets
37
+ - Set batch size: 10-50 items depending on API limits
38
+ - Add delay: 1-2 seconds between batches
39
+
40
+ ### 3. Error Handling
41
+ **Build resilient enrichment flows**
42
+ - Wrap API calls in Try/Catch pattern using Error Trigger node
43
+ - Use StopAndError node (n8n-nodes-base.stopAndError) for critical failures
44
+ - Implement fallback enrichment sources with Switch node (n8n-nodes-base.switch)
45
+ - Log failures to database or file for later retry
46
+
47
+ ### 4. Data Merging
48
+ **Combine enriched data effectively**
49
+ - Use Merge node (n8n-nodes-base.merge) with "Merge By Key" mode
50
+ - Specify unique identifiers for accurate matching
51
+ - Handle missing enrichment data with default values
52
+ - Preserve original data alongside enrichments
53
+
54
+ ### 5. Caching Strategy
55
+ **Minimize redundant API calls**
56
+ - Check cache before making external requests
57
+ - Use Redis node (n8n-nodes-base.redis) or database for caching
58
+ - Set appropriate TTL values:
59
+ - Static data: 7-30 days
60
+ - Dynamic data: 1-24 hours
61
+ - Real-time data: No caching
62
+
63
+ ### 6. Field Mapping
64
+ **Standardize enriched data structure**
65
+ - Use Set node to rename fields consistently
66
+ - Remove unnecessary fields with unset operations
67
+ - Apply data transformations in Code node for complex mappings
68
+ - Document field mappings in workflow description
69
+
70
+ ### 7. Quality Scoring
71
+ **Assess enrichment quality**
72
+ - Add confidence scores to enriched fields
73
+ - Track enrichment source for each field
74
+ - Implement validation rules for enriched data
75
+ - Flag incomplete or suspicious enrichments
76
+
77
+ ## Recommended Nodes
78
+
79
+ ### Essential Nodes
80
+
81
+ **HTTP Request** (n8n-nodes-base.httpRequest):
82
+ - Purpose: Primary enrichment API calls
83
+ - Use cases: Call external APIs for data enrichment
84
+ - Best practices: Configure proper authentication, handle timeouts
85
+
86
+ **Merge** (n8n-nodes-base.merge):
87
+ - Purpose: Combine original and enriched data
88
+ - Modes: Merge By Key, Merge By Index, Append
89
+ - Best practices: Use unique identifiers for matching, handle missing data
90
+
91
+ **Set** (n8n-nodes-base.set):
92
+ - Purpose: Transform and standardize data
93
+ - Use cases: Rename fields, remove unnecessary data, add metadata
94
+ - Best practices: Use "Keep Only Set" carefully, document transformations
95
+
96
+ **IF** (n8n-nodes-base.if):
97
+ - Purpose: Conditional enrichment logic
98
+ - Use cases: Validate required fields, route based on data quality
99
+ - Best practices: Check for null values, validate data types
100
+
101
+ **SplitInBatches** (n8n-nodes-base.splitInBatches):
102
+ - Purpose: Process large datasets in chunks
103
+ - Use cases: Handle datasets with 100+ items
104
+ - Best practices: Set appropriate batch size (10-50 items), add delays
105
+
106
+ ### Enrichment Sources
107
+
108
+ **Clearbit** (n8n-nodes-base.clearbit):
109
+ - Purpose: Company and person enrichment
110
+ - Use cases: Enrich email addresses with company data, get person details
111
+ - Best practices: Handle rate limits, cache results
112
+
113
+ **Hunter** (n8n-nodes-base.hunter):
114
+ - Purpose: Email finder and verification
115
+ - Use cases: Find email addresses, verify email validity
116
+ - Best practices: Respect API quotas, handle verification failures
117
+
118
+ **Brandfetch** (n8n-nodes-base.Brandfetch):
119
+ - Purpose: Company branding data
120
+ - Use cases: Get company logos, colors, brand assets
121
+ - Best practices: Cache brand data, handle missing brands
122
+
123
+ **OpenAI** (@n8n/n8n-nodes-langchain.openAi):
124
+ - Purpose: AI-powered data enrichment
125
+ - Use cases: Extract insights, classify data, generate descriptions
126
+ - Best practices: Minimize token usage, batch similar requests
127
+
128
+ **Google Sheets** (n8n-nodes-base.googleSheets):
129
+ - Purpose: Lookup table enrichment
130
+ - Use cases: Reference data enrichment, mapping tables
131
+ - Best practices: Use efficient lookup methods, cache sheet data
132
+
133
+ ### Utility Nodes
134
+
135
+ **Code** (n8n-nodes-base.code):
136
+ - Purpose: Custom enrichment logic
137
+ - Use cases: Complex transformations, custom algorithms
138
+ - Best practices: Keep code modular, handle errors gracefully
139
+
140
+ **Wait** (n8n-nodes-base.wait):
141
+ - Purpose: Rate limiting delays
142
+ - Use cases: Add delays between API calls, implement backoff
143
+ - Best practices: Use appropriate delay values (1-2 seconds)
144
+
145
+ **DateTime** (n8n-nodes-base.dateTime):
146
+ - Purpose: Timestamp handling
147
+ - Use cases: Add enrichment timestamps, calculate ages
148
+ - Best practices: Use consistent timezone handling
149
+
150
+ **Redis** (n8n-nodes-base.redis):
151
+ - Purpose: Caching layer
152
+ - Use cases: Cache enrichment results, track processed items
153
+ - Best practices: Set appropriate TTL, handle cache misses
154
+
155
+ **Error Trigger** (n8n-nodes-base.errorTrigger):
156
+ - Purpose: Error handling workflow
157
+ - Use cases: Global error handling, logging failures
158
+ - Best practices: Implement retry logic, alert on critical failures
159
+
160
+ **Switch** (n8n-nodes-base.switch):
161
+ - Purpose: Route based on enrichment results
162
+ - Use cases: Fallback enrichment sources, quality-based routing
163
+ - Best practices: Always define default case
164
+
165
+ **Stop and Error** (n8n-nodes-base.stopAndError):
166
+ - Purpose: Halt workflow on critical failures
167
+ - Use cases: Stop processing on invalid data, critical API failures
168
+ - Best practices: Use for unrecoverable errors only
169
+
170
+ ## Common Pitfalls to Avoid
171
+
172
+ ### Performance Issues
173
+
174
+ **Problem**: Enriching all fields for every record
175
+ - **Solution**: Only enrich fields that are actually needed
176
+ - Profile your workflow to identify bottlenecks
177
+ - Use conditional enrichment based on data needs
178
+
179
+ **Problem**: Sequential processing of independent enrichments
180
+ - **Solution**: Use parallel branches for non-dependent enrichments
181
+ - Split workflow into parallel paths
182
+ - Merge results after parallel processing
183
+
184
+ **Problem**: No batching for large datasets
185
+ - **Solution**: Always use SplitInBatches for >100 items
186
+ - Set appropriate batch sizes (10-50 items)
187
+ - Add delays between batches
188
+
189
+ ### Data Quality Problems
190
+
191
+ **Problem**: Overwriting original data with enrichments
192
+ - **Solution**: Preserve original data and add enriched fields separately
193
+ - Use Set node to add new fields without removing original ones
194
+ - Document which fields are enriched
195
+
196
+ **Problem**: Not handling null or missing enrichment results
197
+ - **Solution**: Implement fallback values and error flags
198
+ - Use IF nodes to check for empty results
199
+ - Add default values for missing enrichments
200
+
201
+ **Problem**: Mixing data types in enriched fields
202
+ - **Solution**: Enforce consistent data types through validation
203
+ - Convert types explicitly in Set or Code nodes
204
+ - Document expected data types
205
+
206
+ ### Resource Management
207
+
208
+ **Problem**: No rate limiting on external APIs
209
+ - **Solution**: Implement delays and respect API quotas
210
+ - Use Wait node between API calls
211
+ - Monitor API usage and adjust delays
212
+
213
+ **Problem**: Infinite retry loops on failures
214
+ - **Solution**: Set maximum retry attempts (typically 3)
215
+ - Use exponential backoff for retries
216
+ - Log failed attempts for manual review
217
+
218
+ **Problem**: No caching of expensive enrichments
219
+ - **Solution**: Cache results with appropriate expiration times
220
+ - Use Redis or database for caching
221
+ - Set TTL based on data freshness requirements
222
+
223
+ ### Workflow Design Flaws
224
+
225
+ **Problem**: Single point of failure for entire enrichment
226
+ - **Solution**: Use error boundaries and continue on failure options
227
+ - Enable "Continue on Fail" for non-critical enrichments
228
+ - Implement Error Trigger workflow
229
+
230
+ **Problem**: Hard-coded API keys in workflows
231
+ - **Solution**: Use credentials and environment variables
232
+ - Store sensitive data in n8n credentials system
233
+ - Never commit credentials in workflow JSON
234
+
235
+ **Problem**: No monitoring or logging of enrichment quality
236
+ - **Solution**: Add metrics collection and alerting
237
+ - Log enrichment success/failure rates
238
+ - Track enrichment coverage and quality
239
+
240
+ ### Common Error Scenarios
241
+
242
+ **API Rate Limits**:
243
+ - Implement exponential backoff
244
+ - Add Wait nodes with increasing delays
245
+ - Use SplitInBatches to control request rate
246
+
247
+ **Invalid API Responses**:
248
+ - Validate response structure before processing
249
+ - Use IF nodes to check response format
250
+ - Log unexpected responses for debugging
251
+
252
+ **Timeout Issues**:
253
+ - Set reasonable timeout values (10-30s)
254
+ - Use shorter timeouts for non-critical enrichments
255
+ - Implement retry logic for timeouts
256
+
257
+ **Data Mismatches**:
258
+ - Use fuzzy matching for lookups
259
+ - Normalize data before matching
260
+ - Handle missing keys gracefully
261
+
262
+ **Duplicate Enrichments**:
263
+ - Implement deduplication logic
264
+ - Check cache before enriching
265
+ - Use unique identifiers for tracking
266
+ `;
267
+ }
268
+ getDocumentation() {
269
+ return this.documentation;
270
+ }
271
+ }
272
+ exports.EnrichmentBestPractices = EnrichmentBestPractices;
273
+ //# sourceMappingURL=enrichment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enrichment.js","sourceRoot":"","sources":["../../../../src/prompts/best-practices/guides/enrichment.ts"],"names":[],"mappings":";;;AACA,oCAA6C;AAE7C,MAAa,uBAAuB;IAApC;QACU,cAAS,GAAG,yBAAiB,CAAC,UAAU,CAAC;QACzC,YAAO,GAAG,OAAO,CAAC;QAEV,kBAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiQjC,CAAC;IAKF,CAAC;IAHA,gBAAgB;QACf,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;CACD;AA1QD,0DA0QC"}
@@ -0,0 +1,7 @@
1
+ import type { BestPracticesDocument } from '../types';
2
+ export declare class FormInputBestPractices implements BestPracticesDocument {
3
+ readonly technique: "form_input";
4
+ readonly version = "1.0.0";
5
+ private readonly documentation;
6
+ getDocumentation(): string;
7
+ }