Overview
The AI Switch node automatically routes workflow items to different outputs based on AI analysis of specified input data fields. It is designed to help workflows dynamically decide the next processing step by analyzing textual content with an AI language model or fallback keyword matching.
Common scenarios include:
- Routing customer support tickets to different departments based on message content.
- Directing survey responses or feedback to specialized processing branches.
- Automatically categorizing incoming data for further automated handling.
For example, if you have multiple routes like "Billing Issues," "Technical Support," and "General Inquiry," the node analyzes the text in a chosen JSON field and sends each item to the most appropriate route output.
Properties
Name | Meaning |
---|---|
Routes | A list of named routes, each with a description explaining when it should be selected by the AI. |
Analysis Field | The JSON field path (dot notation) from the input data whose text content will be analyzed. |
Response Format | How the AI should format its routing decision: either just the route index number or a structured JSON containing the index and reasoning. |
Debug Mode | If enabled, adds detailed analysis information and logs to the output for troubleshooting purposes. |
Output
The node has multiple outputs corresponding to the defined routes plus one default output at index 0.
- Each output receives the subset of input items routed to that route.
- Items routed to a specific route have an added
aiRouterInfo
JSON object containing:routeName
: The name of the selected route.routeIndex
: The numeric index of the route.reasoning
: Explanation from the AI about why this route was chosen (only if structured response format is used).
- If debug mode is enabled, additional fields such as
aiRouterAnalysis
are added to the item JSON, providing insights into the routing decision process. - Items that cannot be routed to any defined route are sent to the default output (index 0).
The node does not output binary data.
Dependencies
- Requires connection to an AI language model node input to perform text analysis.
- If no AI model is connected, the node falls back to simple keyword matching or routes all items to the default output.
- No external API keys or environment variables are directly required by this node itself, but the connected AI model may require credentials.
Troubleshooting
- No AI Model Connected: If the AI language model input is missing, the node logs an error and routes all items to the default output with an error note in their JSON.
- Empty or Missing Analysis Field: If the specified JSON field is empty or missing, the node attempts to find alternative common text fields (
chatInput
,message
,text
,content
,input
, etc.). If none found, items go to the default output. - AI Model Call Failures: Errors during AI invocation trigger fallback keyword matching. If fallback also fails, items route to default with error details.
- Invalid AI Response Format: If the AI returns unexpected or unparsable output, the node tries to extract a route index using regex. If unsuccessful, defaults to route 0.
- Debug Mode: Enabling debug mode helps identify issues by logging detailed internal states and adding analysis info to output items.
Links and References
- n8n Documentation
- General AI text classification concepts can be explored via OpenAI or LangChain documentation depending on the AI model used.