When and Why to Use
Use these to disqualify respondents based on logic at any point in the survey.
terminate_if()allows you to specify a condition to check inlineterminate()immediately ends the survey with a given reason
Best for:
- Screening out respondents who don't meet key criteria
- Enforcing business logic (e.g., device ownership, past usage)
- Ending surveys early while still recording a clear disqualification reason
terminate_if(condition, reason, number_seconds)
| Parameter | Type | Required | Description |
|---|---|---|---|
condition | bool | yes | If True, the respondent will be terminated |
reason | str | yes | Message shown to the respondent and recorded in the response log |
number_seconds | int | no | Seconds to wait before allowing the respondent to continue. Defaults to 0. |
Example Code
has_xbox = s.select_question("Do you own an Xbox?", options=["Yes", "No"])
s.terminate_if(
condition=(has_xbox == "No"),
reason="Sorry, you don't qualify for this survey because you don't have an Xbox."
)
Notes
- Only the first true condition encountered will trigger termination
- Termination reason should be clear and respondent-friendly
- Use
terminate()directly if the condition has already been evaluated elsewhere - For quota-based termination, use
set_quota()— it also terminates respondents who do not qualify for the quotas
Related: terminate(reason, number_seconds)
Use this to force a termination unconditionally or outside of an if expression. It takes the same reason and optional number_seconds parameters as terminate_if().
s.terminate("This survey is now closed to new participants.")
- Immediately ends the survey for the respondent and stops execution — no code after the call runs
- Typically used in fallback logic or forced re-routes
- Still logs the reason and ends the session cleanly

