Skip to main content
Goals of this tutorial We begin with technical setup: instructions for installing the EDSL library and storing API keys to access language models. Then we demonstrate some of the basic features of EDSL, with examples for constructing and running surveys with agents and models, and analyzing responses as datasets. By the end of this tutorial, you will be able to use EDSL to do each of the following:
  • Construct various types of questions tailored to your research objectives.
  • Combine questions into surveys and integrate logical rules to control the survey flow.
  • Add context to questions by pipinganswers, adding memory of prior questions and answers, and using scenarios to add data or content to questions.
  • Design personas for AI agents to simulate responses to your surveys.
  • Choose and deploy language models to generate responses for AI agents.
  • Analyze results as datasets with built-in analytical tools.
  • Validate LLM answers with human respondents.
Storing & sharing your work We also introduce Expected Parrot: a platform for creating, storing and sharing AI-based research. Expected Parrot is fully integrated with EDSL and free to use. At the end of the tutorial we show how to post content created in this tutorial for anyone to view. Learn more in the Expected Parrot documentation.
Note:You can also view and download the contents of this tutorial in a notebook at Expected Parrot
Further reading In addition to this tutorial, please also see an Overview of features and common use cases for EDSL and a Survey logic checklist of tips for using EDSL effectively in the EDSL documentation page. To see recent research using or citing EDSL, see Papers & Citations in the documentation. Questions If you encounter any issues or have questions, please email us at [email protected] or post a question at our Discord channel.

Pre-requisites

EDSL is compatible with Python 3.9 - 3.13. Before starting this tutorial, please ensure that you have a Python environment set up on your machine or in a cloud-based environment, such as Google Colab. You can find instructions for installing Python at the Python Software Foundation.

Recommendations

Run code examples in a notebook The code examples in this tutorial are designed to be run in a Jupyter notebook or another Python environment, or in a cloud-based environment such as Google Colab. If you are using Google Colab, please see additional instructions for setting up EDSL in the Colab setup page in the documentation. Use a virtual environment We also recommend using a virtual environment when installing and using EDSL in order to avoid conflicts with other Python packages. You can find instructions for setting up a virtual environment at the Python Packaging Authority. Special instructions for Colab users If you are using EDSL in a cloud-based environment, such as Google Colab, you can find additional instructions for setting up EDSL in the Colab setup page in the documentation.

Installation

To begin using EDSL, you first need to install the library. This can either be done locally on your machine or in a cloud-based environment, such as Google Colab. Once you have decided where to install EDSL, you can choose to whether install it from PyPI or GitHub: From PyPI Install EDSL directly using pip, which is straightforward and recommended for most users. We also recommend using a virtual environment to manage your Python packages (see Recommendations above). Run the following command in your notebook to install EDSL from PyPI:
From GitHub You can find the source code for EDSL and contribute to the project at GitHub. Installing from GitHub allows you to get the latest updates to EDSL before they are released to a new version at PyPI. This is recommended if you are using new features or contributing to the project. Run the following command to install EDSL from GitHub:
After installing EDSL, you can check the version that you have installed by running the following command in your notebook:
To update your installation of EDSL to the latest version at PyPI, run the following command:

Create an account

Creating an account allows you to run survey jobs at Expected Parrot using language models of your choice, and automatically cache your results. Your account also allows you to launch human surveys and share your content and workflows with other users. Your account comes with $25 in credits for API calls to LLMs for getting started, and a referal code for earning more credits. Create an account with an email address and password, or run the following code to be prompted automatically:
The above code also automatically stores your Expected Parrot API key for use with EDSL (see below).

Accessing Language Models

The next step is to decide how you want to access language models. EDSL works with many popular language models that you can choose from to generate responses to your surveys. These models are hosted by various service providers, such as Anthropic, Azure, Bedrock, Deep Infra, DeepSeek, Google, Groq, Mistral, OpenAI, Replicate, Together and Xai. In order to run a survey, you need to provide API keys for the service providers of models that you want to use. There are two methods for providing API keys to EDSL:
  • Use an Expected Parrot API key to access all available models
  • Provide your own API keys from service providers

Managing keys

The easiest way to manage your keys is from your Expected Parrot account. Log in to your account and navigate to your Keys page to find options for adding and sharing your keys. Your Expected Parrot key is automatically available to use by default whenever remote inference is activated. This key allows you to access the Expected Parrot server and run surveys with all available models. Please see the Managing Keys section for more details on methods of storing and managing keys.
Note: If you try to run a survey without storing a required API key, you will be provided a link to activate remote inference and use your Expected Parrot key.

Credits & tokens

Running surveys with language models requires tokens. If you are using your own API keys, service providers will bill you directly. If you are using your Expected Parrot API key to access models, you will need to purchase credits to cover token costs. Please see the model pricing page for details on available models and their current prices.
Note: Your account comes with 2,500 free credits ($25 worth of API calls). You can purchase more credits at any time at your Credits page.
After installing EDSL and storing API keys you are ready to run some examples!

Example: Running a simple question

EDSL comes with a variety of question types that we can choose from based on the form of the response that we want to get back from a model, including multiple choice, checkbox, rank, top-k, linear scale, likert five, yes/no, numerical, free text, extract, list, matrix and functional questions. We can inspect the components of a particular question type by importing the question type class and calling the example method on it:
Output: Here we create a simple multiple choice question:
We can administer it to a language model by calling the run() method on it.
This generates a dataset of Results that we can readily access with built-in methods for analysis. Here we inspect the response, together with the model that was used and the model’s “comment” about its response–a field that is automatically added to all question types other than free text:
Output: The Results also include information about the question, model parameters, prompts, generated tokens and raw responses. To see a list of all the components:
Output:
Note: If we are running the job locally we can pass run(progress_bar=True) to view a Progress Report. Any exceptions will appear in the console.
If remote inference is activated, a link to a Progress Report will appear automatically, as well as a link to an Exceptions Report if there are any. When the job is completed, a link to the Results page will also appear.

Example: Conducting a survey with agents and models

In the next example we construct a more complex survey consisting of multiple questions and design personas for AI agents to answer it. Then we select specific language models to generate the answers. We start by creating questions in different types and passing them to a Survey:
We construct a Survey by passing a list of questions:

Agents

An important feature of EDSL is the ability to create AI agents to answer questions. This is done by passing dictionaries of relevant “traits” to Agent objects that are used by language models to generate responses. Learn more about designing agents. Here we construct several simple agent personas to use with our survey:

Language models

EDSL works with many popular large language models that we can select to use with a survey. This makes it easy to compare responses among models in the results that are generated. To see a current list of available models:
To check the default model that will be used if no models are specified for a survey (e.g., as in the first example above):
Output (may be different if the default model has changed): Here we select some models to use with our survey:

Running a survey

We add agents and models to a survey using the by method. Then we administer a survey the same way that we do an individual question, by calling the run method on it:
Example output:

Running a survey in the background

If remote inference is activated, we can optionally run the survey in the background and continue working (or not) while waiting for results to be generated:
This will return a link to the progress bar page (as usual), which you can check at any time. You can also check the status of the job by running:
This will return either a status update or the results. Once the job is completed, you can call the results as usual, e.g.:

Example: Adding context to questions

EDSL provides a variety of ways to add data or content to survey questions. These methods include:

Piping question answers

Here we demonstrate how to pipe the answer to a question into the text of another question. This is done by using a placeholder in the text of the follow-on question where the answer to the prior question is to be inserted when the survey is run. This causes the questions to be administered in the required order (survey questions are administered asynchronously by default). Learn more about piping question answers. Here we insert the answer to a numerical question into the text of a follow-on yes/no question:
We can check the user_prompt for the prime question to verify that the answer to the random_number question was piped into it:
Example output:

Adding “memory” of questions and answers

Here we instead add a “memory” of the first question and answer to the context of the second question. This is done by calling a memory rule and identifying the question(s) to add. Instead of just the answer, information about the full question and answer are presented with the follow-on question text, and no placeholder is used. Learn more about question memory rules. Here we demonstrate the add_targeted_memory method (we could also use set_full_memory_mode or other memory rules):
We can again use the user_prompt to verify the context that was added to the follow-on question:
Example output:

Scenarios

We can also add external data or content to survey questions. This can be useful when you want to efficiently create and administer multiple versions of questions at once, e.g., for conducting data labeling tasks. This is done by creating Scenario dictionaries for the data or content to be used with a survey, where the keys match {{ placeholder }} names used in question texts (or question options) and the values are the content to be added. Scenarios can also be used to add metadata to survey results, e.g., data sources or other information that you may want to include in the results for reference but not necessarily include in question texts. In the next example we revise the prior survey questions about reading to take a parameter for other activities that we may want to add to the questions, and create simple scenarios for some activities. EDSL provides methods for automatically generating scenarios from a variety of data sources, including PDFs, CSVs, docs, images, tables and dicts. We use the from_list method to convert a list of activities into scenarios. Then we demonstrate how to use scenarios to create multiple versions of our questions either (i) when constructing a survey or (ii) when running it:
  • In the latter case, the by method is used to add scenarios to a survey of questions with placeholders at the time that it is run (the same way that agents and models are added to a survey). This adds a scenario column to the results with a row for each answer to each question for each scenario.
  • In the former case, the loop method is used to create a list of versions of a question with the scenarios already added to it; when the questions are passed to a survey and it is run, the results include columns for each individual question; there is no scenario column and a single row for each agent’s answers to all the questions.
Learn more about using scenarios. Here we create simple scenarios for a list of activities:

Adding scenarios using the by method

Here we add the scenarios to the survey when we run it, together with any desired agents and models:
Output:

Exploring Results

EDSL comes with built-in methods for analyzing and visualizing survey results. For example, you can call the to_pandas method to convert results into a dataframe:
The Results object also supports SQL-like queries with the the sql method:
Output:

Posting to Expected Parrot

Expected Parrot is a platform for creating, storing and sharing LLM-based research. It is fully integrated with EDSL and accessible from your workspace or Expected Parrot account page. Learn more about creating an account and posting content. We can post any EDSL object to Expected Parrot by calling the push method on it, optionally passing a description, a convenient alias for the URL that is created and a visibility status (public, private or unlisted by default):
Example output (UUIDs will be unique to objects):
To post a notebook:
You can view and download a notebook for this tutorial at Expected Parrot.