- 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.
Note:You can also view and download the contents of this tutorial in a notebook at Expected Parrot
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: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: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.
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:
Here we create a simple multiple choice question:
The Results also include information about the question, model parameters, prompts, generated tokens and raw responses. To see a list of all the components:
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.
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: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:
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: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:Example: Adding context to questions
EDSL provides a variety of ways to add data or content to survey questions. These methods include:- Piping answers to questions into follow-on questions
- Adding “memory” of prior questions and answers in a survey when presenting other questions to a model
- Parameterizing questions with data, e.g., content from PDFs, CSVs, docs, images or other sources that you want to add to questions
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: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):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.
