Skip to main content
In the first example below we construct a survey of questions and then add a rule to skip one question based on the response to another question. In the second example we add some complexity. We first create different “scenarios” (versions) of questions and combine them in a survey. Then we add multiple rules to skip specific versions of the questions based on responses to a particular version of a question. EDSL is an open-source library for simulating surveys, experiments and other research with AI agents and large language models. Before running the code below, please ensure that you have installed the EDSL library and either activated remote inference from your Expected Parrot account or stored API keys for the language models that you want to use with EDSL. Please also see our documentation page for tips and tutorials on getting started using EDSL.

Example 1

In the first example below we construct questions, combine them in a survey, and add a rule to skip the second question based on the response to the first question. Then we create Scenario objects for contents that will be added to the questions when the survey is run. The effect of this is that the second question will be skipped based on the response to the first question for each individual scenario. We start by constructing questions:
We combine the questions in a survey to administer them together:
Survey # questions: 3; question_name list: [‘recent_purchase’, ‘amount’, ‘next_purchase’]; Here we add a rule to skip q2 based on the response to q1:
Next we create scenarios for the “item” to be used with each question:
Note:Note that we could also use a method for the data type that we are using–this is equivalent:
We can inspect the flow of the survey that has been created with the scenarios that we’re using:
../_images/notebooks_skip_logic_scenarios_13_0.png
Next we create some agent personas to answer the questions:
Next we select a model to generate the responses (check available models and pricing):
We can inspect (or modify) the default parameters of the model that will be used:
We run the survey by adding any scenarios, agents and models and then calling the run:
We can inspect a list of the columns of the dataset of results that has been generated:
We can select and inspect any components of the results. We can see by a “None” response that a question was skipped:

Example 2

In the next example, we use the same scenarios to create versions of the questions before we combine them in a survey. This allows us to add a skip rule based on a question/scenario combination, as opposed to skipping a question for all scenarios:
The loop method creates new versions of questions with scenarios already inserted:
We combine the questions in a survey to administer them together the same as before:
Here we add different rules specifying that questions with one scenario (phones) should be administered or skipped based on the answer to a question with another scenario (electronics):
../_images/notebooks_skip_logic_scenarios_34_0.png
Here we run the survey with the scenarios, agents and model:
There is no “scenario” field in results because the scenarios were already added to questions. Instead, there are separate columns for each version of a question:

Posting to Expected Parrot

Here we post this notebook to Expected Parrot, a free platform for creating and sharing AI-based research (learn more about how it works):