Skip to main content

What is a Scenario?

A Scenario is a dictionary of one or more key/value pairs representing data or content to be added to questions; a ScenarioList is a list of Scenario objects. Scenario keys are used as question parameters that get replaced with the values when the scenarios are added to the questions, allowing you to create variants of questions efficiently. For example:

Using scenarios

Scenarios can be added to questions when constructing a survey or when running it. Functionally, the same question context is delivered to agents and models whether they are added during or after survey construction. The difference is how the information is arranged in the results that are generated by the models.

Methods

Adding scenarios at survey construction: loop

Each question type (QuestionMultipleChoice, QuestionFreeText, etc.) has a loop() method that generates a copy of the question for each scenario in a ScenarioList that is passed to it, returning a list of the questions that are generated. The loop() method is used when survey questions are being constructed. The typical workflow is:
  • Construct a (single) Question with one or more parameters
  • Construct a ScenarioList
  • Call the loop() method on the question and pass it the scenario list
  • Pass the list of the questions to a Survey
From the example above this looks like:
When the survey is run, the results that are generated will include columns for each question and answer; there are no scenario columns in the results (unless scenarios are also added when the survey is run).

Running a survey with scenarios: by

Scenarios can also be passed to a question or survey at the time that it is run. This is done by calling the by() method on a survey, passing it the scenarios, and then calling the run() method. The typical workflow is:
  • Construct a question (or survey of multiple questions) with one or more parameters
  • Construct scenarios
  • Call the by() method on the question or survey and pass it the scenarios
  • Call the run() method to administer the question or survey
From the example above this looks like:
(If any agents or models have been created and specified, they would also be added in separated by() calls. See details on designing agents and selecting language models.)

Example: Looping a question with scenarios

The loop() method is called on a Question object, and takes a ScenarioList of values to be inserted in copies of the question. We can optionally use the scenario key in the question name as well (so long as it is Pythonic); otherwise, unique identifiers are added to the original question name. We start by constructing a question that takes a parameter:
Next we create a scenario list to pass to the loop() method. EDSL comes with many methods for generating scenarios from different data sources, such as PDF, PNG, CSV, docs, tables, dicts, lists, etc. We can use the from_source() method to construct a scenario list and specify the data type (“csv”, “pdf”, “list”, etc.). Learn about other methods for generating scenarios.
Next we call the loop() method with the scenario list to create a list of the copies of the question, and verify that formatted questions have been generated:
We can pass the questions to a Survey and then run it:
We can check the columns of dataset of Results that have been generated, and see that there are sets of columns for each question identifiable by question name (but no scenario columns):
We can access built-in methods for analyzing results, e.g., printing a table:

Running a question with scenarios

If we instead want to add the scenarios to the question when it is run, we simply add them with the by() method. This will re-administer a question for each scenario:
The results now include columns for the single question but with a separate row for each scenario:

Posting to Expected Parrot

Expected Parrot is a platform for creating, storing and sharing LLM-based research and validating it with human respondents. We can post surveys, agents, results and notebooks, such as this one. Learn more about posting content.