> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/conditional-and-ai-routing.md).

# Conditional and AI routing

Routing sends a workflow along different paths according to its input. Use conditional routing for explicit rules. Use AI routing when a model must interpret the request before choosing a path.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FvWbHcmDUdsf83I3tFunk%2FG024.mp4?alt=media&token=eef26ea6-5291-419c-8c8a-4a10329ef8b4>" %}

## Connect the routing paths

Inspect the paths connected to the routing node.

![Paths connected to the routing node](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/XVeCzN5fUUK8qzufbKra/assets/g024-g024-01-if-canvas.png)

Each path should lead to the processing and output appropriate for that condition.

## Route with explicit conditions

In If/Else, select the comparison operator and enter its comparison value.

![If Else comparison operator and value](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/3WSA943XEM6FCRqD2TOE/assets/g024-g024-02-condition.png)

Use AND, OR, or additional branches when the rule requires more than one condition.

Insert the source value with the reference picker.

![Source reference used by a condition](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/jKkR3vwSFmRf3TjKUbCe/assets/g024-g024-03-condition-reference.png)

Keep the value being checked separate from the fixed value it is compared against.

## Check both condition outcomes

Run an input that matches the condition and inspect the selected branch.

![Matching condition and selected branch](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/A3l0U8vIlTcNDd3Qk3sz/assets/g024-g024-04-if-result.png)

The other branch should be skipped for that execution.

Run an input that does not match and inspect the ELSE path.

![Nonmatching condition and ELSE path](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/PI0ozM6l8fvkyAu3tBNT/assets/g024-g024-05-else-result.png)

This confirms what happens when the main condition is false.

## Route by the meaning of a request

For meaning-based routing, set the AI Routing Input Query and describe each category.

![AI Routing query and category descriptions](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/sRAEAaS7yGwjNecm7fj5/assets/g024-g024-06-ai-settings.png)

Distinct descriptions help the model choose between paths with different purposes.

Submit a request whose meaning fits one category even if it does not contain an exact keyword.

![Meaning-based request and chosen path](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/KUOF4glem445NwaHpwa2/assets/g024-g024-07-ai-billing.png)

Inspect the chosen path to check the classification.

Review additional requests, including ambiguous ones.

![Additional classification requests and routing results](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/gxofh2VM1c9iahXSCtQx/assets/g024-g024-08-ai-technical.png)

AI classification can vary, so make the category boundaries clear and inspect unexpected choices.

## Important behavior

Use If/Else when a condition can be expressed as a rule. Use AI Routing when the request must be interpreted.

Overlapping category descriptions can lead to unexpected AI routing. Make each category’s purpose distinct.

## Related steps

* [Map variables and expressions](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/map-variables-and-expressions.md)
* [Workflow debugging and node results](https://docs.stackai.com/guides-and-quickstarts/workflow-builder/workflow-debugging-and-node-results.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/guides-and-quickstarts/workflow-builder/conditional-and-ai-routing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
