> For the complete documentation index, see [llms.txt](https://docs.askyazi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.askyazi.com/build-a-study/logic-and-routing.md).

# Logic and routing

Send participants down different paths with skip rules, Only show if conditions, screen-outs and ending rules, and check the whole flow on the Logic Map.

Logic decides which question each participant sees next. Use it to skip questions that do not apply, send groups down different paths, screen out people who do not qualify, and end a survey early. Yazi gives you two tools: **routing rules** that run after a question is answered, and **Only show if** conditions that decide whether a question is shown at all.

{% hint style="info" %}
**In short:** set routing on a question from its logic (branch) icon: "if the answer is X, go to Q12 / screen out / complete". Set **Only show if** on a question that should only appear for some people. Check every path on the **Logic Map** and in the Test Simulator before you publish. In a WhatsApp Flow, routing happens at the end of each screen and only moves forward.
{% endhint %}

## The two kinds of logic

|             | Routing rule (Question Logic)                      | Only show if                                                     |
| ----------- | -------------------------------------------------- | ---------------------------------------------------------------- |
| Sits on     | The question whose answer decides the route        | The question that should be shown or skipped                     |
| Runs        | After the participant answers                      | Before the question would be sent                                |
| Typical use | "If No, screen out." "If Non-customer, go to Q20." | "Ask Q15 only if Q4 is Daily or Weekly."                         |
| Best when   | One answer sends people to different places        | A question depends on earlier answers, wherever people came from |

**Only show if** saves you from building a chain of skip rules on every question that could lead to a conditional one. If the condition is false, the question is skipped and the participant moves to the next one. It works in in-chat surveys and in WhatsApp Flows.

## Set up a routing rule

{% stepper %}
{% step %}

### Open Question Logic

On the **Build** tab, click the logic (branch) icon on the question. A badge on the icon shows how many rules the question already has.

<figure><img src="https://358667285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzMRQUXiGQlBwWdg6WEmG%2Fuploads%2FnrH0GCJpCIlkd3Hwyu7V%2Ffs-question-logic-empty.webp?alt=media&amp;token=1d87f030-483a-4d74-b9ac-a58c803fe479" alt="The Question Logic window opened from a question: add a conditional rule or an always go to rule"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Add a condition

Choose the answer or answers that trigger the rule. You can combine several conditions with **AND** or **OR** in one rule. For choice questions you pick options, including **Other**, **None of the above** and **All of the above**. For text answers you can route on whether the answer contains a word or phrase.
{% endstep %}

{% step %}

### Choose the action

Pick what happens when the condition is met:

* **Go to** a later question, or to the start of a block;
* **Screen out** the participant, who receives your screen-out message;
* **Complete**: finish the participant here, counted as complete (in an AI interview this skips the interview);
* **End of survey**: end the survey section here (in an AI interview this hands over to the AI interviewer).

<figure><img src="https://358667285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzMRQUXiGQlBwWdg6WEmG%2Fuploads%2Fl6y2PX6LLDOcY018mAYg%2Ffs-question-logic-rule.webp?alt=media&amp;token=1b590ca0-f7ac-447d-9aab-13f1e1795d4b" alt="A conditional rule: when Q1 is Dissatisfied or Very Dissatisfied, go to Q3, with a plain-language summary underneath"><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### Add an Always Go-To if needed

An **Always Go-To** rule sends everyone from this question to a set destination whatever they answered. Use it to bring a sub-group back to the main path, or to jump a branch past questions meant for others.
{% endstep %}

{% step %}

### Save and check the Logic Map

Answers that match no rule follow the normal question order. Open the **Logic Map** to check the route looks right.
{% endstep %}
{% endstepper %}

Choice questions (Single Select and Multi Select), Matrix questions and text answers can all carry routing rules.

## Set an Only show if condition

Open the question that should be conditional and add an **Only show if** condition: the earlier question, the answers that qualify, and AND or OR if there are several. On the Logic Map the question appears as a **Gated** node with its own entry edge.

<figure><img src="https://358667285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzMRQUXiGQlBwWdg6WEmG%2Fuploads%2F1NHrEIz3RvRaGGrNJbvA%2Ffs-question-logic-only-show-if.webp?alt=media&amp;token=7fd9cf78-2cfc-498f-b899-bf89c3693be4" alt="Switching a rule from When to Only show if, to make it an entry condition for the question"><figcaption></figcaption></figure>

If you upload a questionnaire or ask Ask Yazi for "ask Q19 only if Q12 = Yes", Yazi creates an **Only show if** condition on Q19 for you, covering every earlier question the rule names.

## Complete versus End of survey

Both end something, but they mean different things in a study with an AI interview:

| Action            | What happens                                                                                         | Counted as                     |
| ----------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------ |
| **Complete**      | The participant finishes now. They skip anything after, including the AI interview                   | Complete                       |
| **End of survey** | The scripted survey ends here. In an AI interview study, the participant goes on to the AI interview | Complete once the rest is done |
| **Screen out**    | The participant does not qualify and leaves the study                                                | Screened out, not complete     |

In a multi-activity study, these actions end the current activity only, not the whole study.

Use **Screen out**, not Complete, for people who do not consent or do not qualify, so they are not counted as completes.

## Screen-outs and the screen-out message

When someone is screened out they receive a screen-out message. Set it in **Study configuration > Privacy & screening > Screen-Out Message** ("Message sent when participants are disqualified"):

* **Message Type**: a **Text Message**, or a **Template Message** (an approved WhatsApp template with buttons).
* **Custom Message**: your wording. Leave it empty to use the default.
* **Add a button**: **No button**, **Link button** (for example a panel redirect), or **Quick-reply button**, which sends a starter phrase back so you can start another study or template.

Screen-out messages are translated into each participant's language.

In the same section, the **Repeat Attempt Message** is sent when a participant tries to restart a survey they are not allowed to retry.

## The Logic Map

Click **Logic Map** at the top right of the Build tab to see the whole questionnaire as a flow diagram.

<figure><img src="https://358667285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzMRQUXiGQlBwWdg6WEmG%2Fuploads%2FocyVx3tp7rbgJxhlTplW%2Ffs-logic-map-rule.webp?alt=media&amp;token=54b9708c-dff5-4f40-bfac-58e26f07217c" alt="The Logic Map showing the new rule as a conditional route from Q1 to Q3, with the default route to Q2"><figcaption></figcaption></figure>

* **Nodes**: Question, Block, Gated (a question with Only show if), Survey complete, Screen-out.
* **Edges (arrows)**: Conditional, Default fallback, Block routing, Entry condition, Screen-out, Survey complete. Labels show the rule, for example "next" or "if equals 'Undergraduate'".
* **Controls**: Reset, zoom, TB (top to bottom) or LR (left to right) layout, and **+** and **-**.
* **All questions** panel on the right, with search. A red dot marks questions that have rules.

Use the map to spot a question nobody can reach, a branch with no way back, or a screen-out in the wrong place.

## Logic in WhatsApp Flows

In a Flow, several questions can share one screen (a block), so logic works differently:

* **Block routing**: set on the block, it runs when the participant taps **Next**. After this screen, if the answer is X, skip ahead, screen out or end the survey.
* **Forward only**: a Flow can never route back to an earlier screen. This is a WhatsApp rule.
* **Only show if** works and skips screens that do not apply.
* A per-question rule between two questions on the same screen cannot fire, because both are already on screen. Put the dependent question on the next screen or gate it with Only show if.

Block routing with **Always Go-To** and AND/OR conditions also works in in-chat surveys, so blocks can structure an in-chat survey too. See [In-chat vs WhatsApp Flows](https://docs.askyazi.com/build-a-study/in-chat-vs-whatsapp-flows.md).

## Safety checks Yazi runs for you

* **Renamed or deleted options**: rules update automatically when you rename an answer option. If a rule points at an option that no longer exists, you get a warning before launch.
* **Deleted destinations**: a rule pointing at a deleted question is rejected when you publish, with a message naming the rule.
* **Loops**: you cannot save a route that circles back on itself.
* **Duplicates**: duplicating a study copies its logic so it points at the copy's own questions.

## Common patterns

* **NPS routing**: use a Single Select with options 0 to 10, then route 0 to 6, 7 to 8 and 9 to 10 to different follow-ups. Each score is then an option you can pick as a condition.
* **Non-consent**: route "No" on the consent question to **Screen out**.
* **Optional extra questions after the core survey**: put the reward point after the last required question, then offer further questions with a Statement saying they are optional.
* **Different questions per segment**: there is no "segment" setting. Ask a segment question (or use a screener answer) and route from it.

## Limits and things to know

* **Logic cannot reach across activities.** In a multi-activity study, each activity's logic only uses answers from that activity. To split groups across activities, invite each group to its own activity or study.
* **Flows route forward only**, and per-question rules between questions on the same Flow screen cannot fire.
* **Back navigation**: if you let participants go back to earlier questions, keep that off in live fieldwork (it is fine while testing). If participants go back and change answers, later routing may not match what they saw.
* **Text conditions depend on what was typed.** Routing on voice-note content uses the automatic transcript, which can contain errors; use it only for broad keywords.
* **Editing logic on a live study** changes routing for people still answering. Pause, edit, test, resume. See [Publish and go live](https://docs.askyazi.com/study-types/publish-and-go-live.md).
* **Test every path.** The builder preview shows single questions; only the Test Simulator and a real phone show the full route.

## Related

* [Piping](https://docs.askyazi.com/build-a-study/piping.md)
* [Quotas](https://docs.askyazi.com/build-a-study/quotas.md)
* [Screening and incidence](https://docs.askyazi.com/build-a-study/screening-and-incidence.md)
* [In-chat vs WhatsApp Flows](https://docs.askyazi.com/build-a-study/in-chat-vs-whatsapp-flows.md)
* [Test your study](https://docs.askyazi.com/study-types/test-your-study.md)
