Generating results
A Results object is not typically instantiated directly, but is returned by calling the run() method of a Survey after any agents, language models and scenarios are added to it. In order to demonstrate how to access and interact with results, we use the following code to generate results for a simple survey. Note that specifying agent traits, scenarios (question parameter values) and language models is optional, and we include those steps here for illustration purposes. See the Agents, Scenarios and models sections for more details on these components.Note:You must store API keys for language models in order to generate results. Please see the Managing Keys section for instructions on activating Remote Inference or storing your own API keys for inference service providers.
Result objects
We can check the number of Result objects created by inspecting the length of the Results:Generating multiple results
If we want to generate multiple results for a survey–i.e., more than 1 result for each combination of Agent, Model and Scenario objects used–we can pass the desired number of iterations when calling the run() method. For example, the following code will generate 3 results for our survey (n=3):Results components
Results contain components that can be accessed and analyzed individually or collectively. We can see a list of these components by calling the columns method:Visualizing column structure
For complex Results with many nested columns, you can use theshow_columns() method to generate a tree visualization showing the hierarchical structure of your columns:
The columns include information about each agent, model and corresponding prompts used to simulate the answer to each question and scenario in the survey, together with each raw model response. If the survey was run multiple times (run(n=<integer>)) then the iteration.iteration column will show the iteration number for each result.
Agent information:
- agent.agent_index: The index of the agent in the AgentList used to create the survey.
- agent.instruction: The instruction for the agent. This field is the optional instruction that was passed to the agent when it was created.
- agent.agent_name: This field is always included in any Results object. It contains a unique identifier for each Agent that can be specified when an agent is is created (Agent(name=<name>, traits={<traits_dict>})). If not specified, it is added automatically when results are generated (in the form Agent_0, etc.).
- agent.persona: Each of the traits that we pass to an agent is represented in a column of the results. Our example code created a “persona” trait for each agent, so our results include a “persona” column for this information. Note that the keys for the traits dictionary should be a valid Python keys.
- answer.important: Agent responses to the linear scale important question.
- answer.read: Agent responses to the multiple choice read question.
- cache_keys.important_cache_key: The cache key for the important question.
- cache_keys.important_cache_used: Whether the existing cache was used for the important question.
- cache_keys.read_cache_key: The cache key for the read question.
- cache_keys.read_cache_used: Whether the existing cache was used for the read question.
- comment.important_comment: Agent commentary on responses to the important question.
- comment.read_comment: Agent commentary on responses to the read question.
- generated_tokens.important_generated_tokens: The generated tokens for the important question.
- generated_tokens.read_generated_tokens: The generated tokens for the read question.
- model.frequency_penalty: The frequency penalty for the model.
- model.logprobs: The logprobs for the model.
- model.maxOutputTokens: The maximum number of output tokens for the model.
- model.max_tokens: The maximum number of tokens for the model.
- model.model: The name of the model used.
- model.presence_penalty: The presence penalty for the model.
- model.stopSequences: The stop sequences for the model.
- model.temperature: The temperature for the model.
- model.topK: The top k for the model.
- model.topP: The top p for the model.
- model.top_logprobs: The top logprobs for the model.
- model.top_p: The top p for the model.
- model.use_cache: Whether the model uses cache.
Note: Some of the above fields are particular to specific models, and may have different names (e.g., top_p vs. topP).
- prompt.important_system_prompt: The system prompt for the important question.
- prompt.important_user_prompt: The user prompt for the important question.
- prompt.read_system_prompt: The system prompt for the read question.
- prompt.read_user_prompt: The user prompt for the read question.
- question_options.important_question_options: The options for the important question, if any.
- question_options.read_question_options: The options for the read question, if any.
- question_text.important_question_text: The text of the important question.
- question_text.read_question_text: The text of the read question.
- question_type.important_question_type: The type of the important question.
- question_type.read_question_type: The type of the read question.
- raw_model_response.important_cost: The cost of the result for the important question, applying the token quanities & prices.
- raw_model_response.important_input_price_per_million_tokenss: The price per million input tokens for the important question for the relevant model.
- raw_model_response.important_input_tokens: The number of input tokens for the important question for the relevant model.
- raw_model_response.important_one_usd_buys: The number of identical results for the important question that 1USD would cover.
- raw_model_response.important_output_price_per_million_tokens: The price per million output tokens for the important question for the relevant model.
- raw_model_response.important_output_tokens: The number of output tokens for the important question for the relevant model.
- raw_model_response.important_raw_model_response: The raw model response for the important question.
- raw_model_response.read_cost: The cost of the result for the read question, applying the token quanities & prices.
- raw_model_response.read_input_price_per_million_tokens: The price per million input tokens for the read question for the relevant model.
- raw_model_response.read_input_tokens: The number of input tokens for the read question for the relevant model.
- raw_model_response.read_one_usd_buys: The number of identical results for the read question that 1USD would cover.
- raw_model_response.read_output_price_per_million_tokens: The price per million output tokens for the read question for the relevant model.
- raw_model_response.read_output_tokens: The number of output tokens for the read question for the relevant model.
- raw_model_response.read_raw_model_response: The raw model response for the read question.
Note:Note that the cost of a result for a question is specific to the components (scenario, agent, model used with it).
- scenario.scenario_index: The index of the scenario.
- scenario.topic: The values provided for the “topic” scenario for the questions.
Note:We recently added support for OpenAI reasoning models. See an example notebook for usage here. The Results that are generated with reasoning models include additional fields for reasoning summaries.
Creating tables by selecting columns
Each of these columns can be accessed directly by calling the select() method and passing the column names. Alternatively, we can specify the columns to exclude by calling the drop() method. These methods can be chained together to display the specified columns in a table format.Wildcard pattern support
The select() method supports wildcard patterns using* to match multiple columns at once. This is particularly useful when you want to select all columns of a certain type or with a common prefix:
Sorting results
We can sort the columns by calling the sort_by method and passing it the column names to sort by:Labeling results
We can also add some table labels by passing a dictionary to the pretty_labels argument of the print method (note that we need to include the column prefixes when specifying the table labels, as shown below):Filtering results
Results can be filtered by using the filter method and passing it a logical expression identifying the results that should be selected. For example, the following code will filter results where the answer to important is “5” and then just print the topic and important_comment columns:
Note: The filter method allows us to pass the unique short names of the columns (without the prefixes) when specifying the logical expression. However, because the model.model column name is also a prefix, we need to include the prefix when filtering by this column, as shown in the example below:
Limiting results
We can select and print a limited number of results by passing the desired number of max_rows to the print() method. This can be useful for quickly checking the first few results:Sampling results
We can select a sample of n results by passing the desired number of random results to the sample() method. This can be useful for checking a random subset of the results with different parameters:Shuffling results
We can shuffle results by calling the shuffle() method. This can be useful for quickly checking the first few results:Adding results
We can add results together straightforwardly by using the + operator:Flattening results
If a field of results contains dictionaries we can flatten them into separate fields by calling the flatten() method. This method takes a list of the fields to flatten and a boolean indicator whether to preserve the original fields in the new Results object that is returned. For example:Retrieving results
We can retrieve details about results posted to Expected Parrot by calling the list() method on the Results class. For example, the following code will return information about the 10 most recent results posted to the platform:
To access the next page of results, you can specify the page= parameter:
Coop client object (to retrieve details of objects of any type).
Generating a report
We can create a report of the results by calling the report() method and passing the columns to be included (all columns are included by default). This generates a report in markdown by iterating through the rows, presented as observations. You can optionally pass headers, a divider and a limit on the number of observations to include. It can be useful if you want to display some sample part of larger results in a working notebook you are sharing. For example, the following code will generate a report of the first 4 results:Accessing results with SQL
We can interact with results via SQL using the sql method. This is done by passing a SQL query and a shape (“long” or “wide”) for the resulting table, where the table name in the query is “self”. For example, the following code will return a table showing the model, persona, read and important columns for the first 4 results:Dataframes
We can also export results to other formats. The to_pandas method will turn our results into a Pandas dataframe:Exporting to CSV or JSON
The to_csv method will write the results to a CSV file:Revising prompts to improve results
If any of your results are missing model responses, you can use the spot_issues() method to help identify the issues and then revise the prompts to improve the results. This method runs a meta-survey of (2) questions for any prompts that generated a bad or null response, and then returns the results of the meta-survey. The first question in the survey is a QuestionFreeText question which prompts the model to describe the likely issues with the prompts:Exceptions
If any exceptions are raised when the survey is run a detailed exceptions report is generated and can be opened in your browser. See the Exceptions & Debugging section for more information on exceptions.Result class
Bases:class edsl.results.Result(agent: Agent, scenario: Scenario, model: LanguageModel, iteration: int, answer: dict[QuestionName, AnswerValue], prompt: dict[QuestionName, str] = None, raw_model_response: dict | None = None, survey: ‘Survey’ | None = None, question_to_attributes: dict[QuestionName, Any] | None = None, generated_tokens: dict | None = None, comments_dict: dict | None = None, reasoning_summaries_dict: dict | None = None, cache_used_dict: dict[QuestionName, bool] | None = None, indices: dict | None = None, cache_keys: dict[QuestionName, str] | None = None, validated_dict: dict[QuestionName, bool] | None = None)[source]
Base, UserDict
The Result class captures the complete data from one agent interview.
A Result object stores the agent, scenario, language model, and all answers provided during an interview, along with metadata such as token usage, caching information, and raw model responses. It provides a rich interface for accessing this data and supports serialization for storage and retrieval.
The Result class inherits from both Base (for serialization) and UserDict (for dictionary-like behavior), allowing it to be accessed like a dictionary while maintaining a rich object model.
agent: The Agent object that was interviewed. scenario: The Scenario object that was presented to the agent. model: The LanguageModel object that was used to generate responses. answer: Dictionary mapping question names to answer values. sub_dicts: Organized sub-dictionaries for different data types. combined_dict: Flattened dictionary combining all sub-dictionaries. problem_keys: List of keys that have naming conflicts.Attributes:
Results are typically created by the Jobs system when running interviews and collected into a Results collection for analysis. You rarely need to create Result objects manually.Note:
Examples:
Bases:class ClassOrInstanceMethod(func)[source]
object
Descriptor that allows a method to be called as both a class method and an instance method.
init(func)[source]
Initialize a Result object.init(agent: Agent, scenario: Scenario, model: LanguageModel, iteration: int, answer: dict[QuestionName, AnswerValue], prompt: dict[QuestionName, str] = None, raw_model_response: dict | None = None, survey: ‘Survey’ | None = None, question_to_attributes: dict[QuestionName, Any] | None = None, generated_tokens: dict | None = None, comments_dict: dict | None = None, reasoning_summaries_dict: dict | None = None, cache_used_dict: dict[QuestionName, bool] | None = None, indices: dict | None = None, cache_keys: dict[QuestionName, str] | None = None, validated_dict: dict[QuestionName, bool] | None = None)[source]
Args:agent: The Agent object that was interviewed. scenario: The Scenario object that was presented. model: The LanguageModel object that generated responses. iteration: The iteration number for this result. answer: Dictionary mapping question names to answer values. prompt: Dictionary of prompts used for each question. Defaults to None. raw_model_response: The raw response from the language model. Defaults to None. survey: The Survey object containing the questions. Defaults to None. question_to_attributes: Dictionary of question attributes. Defaults to None. generated_tokens: Dictionary of token usage statistics. Defaults to None. comments_dict: Dictionary of comments for each question. Defaults to None. reasoning_summaries_dict: Dictionary of reasoning summaries. Defaults to None. cache_used_dict: Dictionary indicating cache usage for each question. Defaults to None. indices: Dictionary of indices for data organization. Defaults to None. cache_keys: Dictionary of cache keys for each question. Defaults to None. validated_dict: Dictionary indicating validation status for each question. Defaults to None.
Return the Agent object.property agent*: Agent*[source]
Return the answers.property answer*: dict[str, Any]*[source]
apply_command(command_name, kwargs)[source]
Organize result data by question with optional flattening of nested dictionaries. This method reorganizes the result data structure to be organized by question name, making it easier to analyze answers and related metadata on a per-question basis. Args: flatten_nested_dicts: Whether to flatten nested dictionaries using the separator. Defaults to False. separator: The separator to use when flattening nested dictionaries. Defaults to “_”. Returns: A dictionary organized by question name, with each question containing its associated data (answer, prompt, metadata, etc.).by_question_data(flatten_nested_dicts: bool = False, separator: str = ’_’)[source]
Check if an expression references a problematic key. Args: expression: The expression string to check for problematic keys. Raises: ResultsColumnNotFoundError: If the expression contains a problematic key that should use the full qualified name instead.check_expression(expression: str) → None[source]
clear() → None. Remove all items from D.[source]
Copy this object’s representation to the system clipboard. This method first checks if the object has a custom clipboard_data() method. If it does, it uses that method’s output. Otherwise, it serializes the object to a dictionary (without version info) and copies it to the system clipboard as JSON text. Returns: None, but prints a confirmation messageclipboard()[source]
Return a string of code that can be used to recreate the Result object. Raises: ResultsError: This method is not implemented for Result objects.code()[source]
property combined_dict[source]
Return a copy of the Result object.copy() → Result[source]
A new Result object that is a copy of this one.Returns:
Examples:
Generate a downloadable link for this object. Creates a temporary file containing the serialized object and generates a download link that can be shared with others. Returns: str: A URL that can be used to download the objectcreate_download_link()[source]
Delete the object from coop.classmethod delete(url_or_uuid: str | UUID) → None[source]
Create a flattened dictionary representation for display purposes. This method creates a flattened view of nested structures using colon notation in keys to represent hierarchy. Returns: dict: A flattened dictionary suitable for displaydisplay_dict()[source]
Display a rich-formatted chat transcript of the interview. This method creates a ChatTranscript object and displays the conversation between questions and agent responses in a beautiful, chat-like format using the Rich library. Args: show_options: Whether to display question options if available. Defaults to True. show_agent_info: Whether to show agent information at the top. Defaults to True.display_transcript(show_options: bool = True, show_agent_info: bool = True) → None[source]
Create and return a deep copy of the object. Args: add_edsl_version: Whether to include EDSL version information in the duplicated object Returns: A new instance of the same class with identical propertiesduplicate(add_edsl_version=False)[source]
Return an example Result object. Returns: A sample Result object for testing and demonstration purposes.classmethod example() → Result[source]
Examples:
Return a Result object from a dictionary representation. Args: json_dict: Dictionary containing Result data. Returns: A new Result object created from the dictionary data.classmethod from_dict(data: dict) → Result[source]
Return a Result object from an interview dictionary. This method ensures no reference to the original interview is maintained, creating a clean Result object from the interview data. Args: interview: An interview dictionary containing the raw interview data. Returns: A new Result object created from the interview data.classmethod from_interview(interview) → Result[source]
Create an instance from YAML data. Deserializes a YAML string or file into a new instance of the class. Args: yaml_str: YAML string containing object data filename: Path to a YAML file containing object data Returns: A new instance of the class populated with the deserialized data Raises: BaseValueError: If neither yaml_str nor filename is providedclassmethod from_yaml(yaml_str: str | None = None, filename: str | None = None)[source]
classmethod fromkeys(iterable, value=None)[source]
get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
Get the description of this object.get_description() → str[source]
Get a string hash representation of this object based on its content. Returns: str: A string representation of the hash valueget_hash() → str[source]
Get the UUID of this object from the Expected Parrot cloud service based on its hash. This method calculates the hash of the object and queries the cloud service to find if there’s an uploaded version with the same content. If found, it returns the UUID of that object. Returns: str: The UUID of the object in the cloud service if found Raises: CoopServerResponseError: If the object is not found or there’s an error communicating with the serverget_uuid() → str[source]
Return the value for a given data type and key. This method provides a consistent way to access values across different sub-dictionaries in the Result object. It’s particularly useful when you need to programmatically access values without knowing which data type a particular key belongs to.get_value(data_type: str, key: str) → Any[source]
Args:data_type: The category of data to retrieve from. Valid options include: “agent”, “scenario”, “model”, “answer”, “prompt”, “comment”, “generated_tokens”, “raw_model_response”, “question_text”, “question_options”, “question_type”, “cache_used”, “cache_keys”. key: The specific attribute name within that data type.
Returns:The value associated with the key in the specified data type.
Examples:
Display the class documentation string. This is a convenience method to quickly access the docstring of the class. Returns: None, but prints the class docstring to stdoutclassmethod help()[source]
Create an interactive inspector widget for this object. This method uses the InspectorWidget registry system to find the appropriate inspector widget class for this object’s type and returns an instance of it. Returns: InspectorWidget subclass instance: Interactive widget for inspecting this object Raises: KeyError: If no inspector widget is registered for this object’s class ImportError: If the widgets module cannot be importedinspect()[source]
items() → a set-like object providing a view on D’s items[source]
Get a formatted JSON representation of this object. Returns: DisplayJSON: A displayable JSON representationjson()[source]
property key_to_data_type[source]
Get the key names in the object’s dictionary representation. This method returns all the keys in the serialized form of the object, excluding metadata keys like version information. Returns: list: A list of key nameskeys()[source]
List objects from coop. Notes: - The visibility parameter is not supported for remote inference jobs. - The job_status parameter is not supported for objects. - search_query only works with the description field. - If sort_ascending is False, then the most recently created objects are returned first.classmethod list(visibility: Literal[‘private’, ‘public’, ‘unlisted’] | List[Literal[‘private’, ‘public’, ‘unlisted’]] | None = None, job_status: Literal[‘queued’, ‘running’, ‘completed’, ‘failed’, ‘cancelled’, ‘cancelling’, ‘partial_failed’] | List[Literal[‘queued’, ‘running’, ‘completed’, ‘failed’, ‘cancelled’, ‘cancelling’, ‘partial_failed’]] | None = None, search_query: str | None = None, page: int = 1, page_size: int = 10, sort_ascending: bool = False) → CoopObjects[source]
Load the object from a JSON file (compressed or uncompressed). This method deserializes an object from a file, automatically detecting whether the file is compressed with gzip or not. Args: filename: Path to the file to load Returns: An instance of the class populated with data from the file Raises: Various exceptions may be raised if the file doesn’t exist or contains invalid dataclassmethod load(filename)[source]
Return the LanguageModel object.property model*: LanguageModel*[source]
Pull the object from coop. Args: url_or_uuid: Either a UUID string or a URL pointing to the objectclassmethod old_pull(url_or_uuid: str | UUID | None = None)[source]
Read and parse a compressed JSON file. Args: filename: Path to a gzipped JSON file Returns: dict: The parsed JSON contentstatic open_compressed_file(filename)[source]
Read and parse an uncompressed JSON file. Args: filename: Path to a JSON file Returns: dict: The parsed JSON contentstatic open_regular_file(filename)[source]
patch(**kwargs)[source]
Patch an uploaded object’s attributes (class method version). - description changes the description of the object on Expected Parrot - value changes the value of the object on Expected Parrot. has to be an EDSL object - visibility changes the visibility of the object on Expected Parrotclassmethod patch_cls(url_or_uuid: str | UUID, description: str | None = None, value: Any | None = None, visibility: str | None = None)[source]
Auto-generate commands list from methods decorated with @polly_commandproperty polly_commands[source]
If key is not found, d is returned if given, otherwise KeyError is raised.pop(k[, d]) → v, remove specified key and return the corresponding value.[source]
as a 2-tuple; but raise KeyError if D is empty.popitem() → (k, v), remove and return some (key, value) pair[source]
Print a formatted table representation of this object. Args: format: The output format (currently only ‘rich’ is supported) Returns: None, but prints a formatted table to the consoleprint(format=‘rich’)[source]
property problem_keys[source]
Get a signed URL for directly downloading an object from Google Cloud Storage. This method provides a more efficient way to download objects compared to the old pull() method, especially for large files, by generating a direct signed URL to the storage bucket. Args: url_or_uuid (Union[str, UUID], optional): Identifier for the object to retrieve. Can be one of: - UUID string (e.g., “123e4567-e89b-12d3-a456-426614174000”) - Full URL (e.g., “https://expectedparrot.com/content/123e4567…”) - Alias URL (e.g., “https://expectedparrot.com/content/username/my-survey”) expected_parrot_url (str, optional): Optional custom URL for the coop service Returns: dict: A response containing the signed_url for direct downloadclassmethod pull(url_or_uuid: str | UUID | None = None, expected_parrot_url: str | None = None) → dict[source]
Example:
Get a signed URL for directly uploading an object to Google Cloud Storage. This method provides a more efficient way to upload objects compared to the push() method, especially for large files, by generating a direct signed URL to the storage bucket. Args: expected_parrot_url (str, optional): Optional custom URL for the coop service Returns: dict: A response containing the signed_url for direct upload and optionally a job_idpush(description: str | None = None, alias: str | None = None, visibility: str | None = ‘unlisted’, expected_parrot_url: str | None = None) → dict[source]
Example:
property rb[source]
Save the object to a file as JSON with optional compression. Serializes the object to JSON and writes it to the specified file. By default, the file will be compressed using gzip. File extensions are handled automatically.save(filename: str | None = None, compress: bool = True)[source]
Args:filename: Path where the file should be saved compress: If True, compress the file using gzip (default: True)
Returns:None
Examples:
Return the Scenario object.property scenario*: Scenario*[source]
Score the result using a passed-in scoring function.score(scoring_function: Callable) → int | float[source]
Args:scoring_function: A callable that takes parameters from the Result’s combined_dict and returns a numeric score.
Returns:The numeric score returned by the scoring function.
Raises:ResultsError: If a required parameter for the scoring function is not found in the Result object.
Examples:
Score the result against a reference answer key. This method evaluates the correctness of answers by comparing them to a provided answer key. It returns a dictionary with counts of correct, incorrect, and missing answers. The answer key can contain either single values or lists of acceptable values. If a list is provided, the answer is considered correct if it matches any value in the list.score_with_answer_key(answer_key: dict) → dict[str, int][source]
Args:answer_key: A dictionary mapping question names to expected answers. Values can be single items or lists of acceptable answers.
Returns:A dictionary with keys ‘correct’, ‘incorrect’, and ‘missing’, indicating the counts of each answer type.
Examples:
Search for objects on coop.classmethod search(query)[source]
setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D[source]
Display all public methods available on this object. This utility method helps explore the capabilities of an object by listing all its public methods and optionally their documentation. Args: show_docstrings: If True, print method names with docstrings; if False, return the list of method names Returns: None or list: If show_docstrings is True, prints methods and returns None. If show_docstrings is False, returns a list of method names.show_methods(show_docstrings=True)[source]
Store this object in a dictionary with an optional key. Args: d: The dictionary in which to store the object key_name: Optional key to use (defaults to the length of the dictionary) Returns: Nonestore(d: dict, key_name: str | None = None)[source]
property sub_dicts[source]
Convert the result to a dataset format. This method transforms the result data into a Dataset object suitable for analysis and data manipulation. Args: flatten_nested_dicts: Whether to flatten nested dictionaries using the separator. Defaults to False. separator: The separator to use when flattening nested dictionaries. Defaults to “_”. Returns: A Dataset object containing the result data organized for analysis.to_dataset(flatten_nested_dicts: bool = False, separator: str = ’_’)[source]
Return a dictionary representation of the Result object. Args: add_edsl_version: Whether to include EDSL version information in the output. Defaults to True. include_cache_info: Whether to include cache information in the output. Defaults to False. Returns: A dictionary representation of the Result object containing all relevant data.to_dict(add_edsl_version: bool = True, include_cache_info: bool = False, full_dict: bool = False) → dict[str, Any][source]
Examples:
Serialize this object to a JSON string. Returns: str: A JSON string representation of the objectto_json()[source]
Convert the object to YAML format. Serializes the object to YAML format and optionally writes it to a file. Args: add_edsl_version: Whether to include EDSL version information filename: If provided, write the YAML to this file path Returns: str: The YAML string representation if no filename is provided None: If written to fileto_yaml(add_edsl_version=False, filename: str = None) → str | None[source]
Return the questions and answers in a human-readable transcript.transcript(format: str = ‘simple’) → str[source]
Args:format: The format for the transcript. Either ‘simple’ or ‘rich’. ‘simple’ (default) returns plain-text format with questions, options, and answers separated by blank lines. ‘rich’ uses the rich library to wrap each Q&A block in a Panel with colors and formatting.
Returns:A formatted transcript string of the interview.
Raises:ImportError: If ‘rich’ format is requested but the rich library is not installed.
Examples:
Get the ResultTransformer instance for this Result.property transformer[source]
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = vupdate([E, ]**F) → None. Update D from mapping/iterable E and F.[source]
Get the values in the object’s dictionary representation. Returns: set: A set containing all the values in the objectvalues()[source]
Display an interactive visualization of this object. Returns: The result of the dataset’s view methodview()[source]
Get a formatted YAML representation of this object. Returns: DisplayYAML: A displayable YAML representationyaml()[source]
Results class
Bases:class edsl.results.Results(survey: Optional[‘Survey’] = None, data: Optional[list[‘Result’]] = None, name: Optional[str] = None, created_columns: Optional[list[str]] = None, cache: Optional[‘Cache’] = None, job_uuid: Optional[str] = None, total_results: Optional[int] = None, task_history: Optional[‘TaskHistory’] = None, sort_by_iteration: bool = False, data_class: Optional[type] = <class ‘list’>)[source]
MutableSequence, ResultsOperationsMixin, Base
A collection of Result objects with powerful data analysis capabilities.
The Results class is the primary container for working with data from EDSL surveys. It provides a rich set of methods for data analysis, transformation, and visualization inspired by data manipulation libraries like dplyr and pandas. The Results class implements a functional, fluent interface for data manipulation where each method returns a new Results object, allowing method chaining.
Attributes:
survey: The Survey object containing the questions used to generate results. data: A list of Result objects containing the responses. created_columns: A list of column names created through transformations. cache: A Cache object for storing model responses. completed: Whether the Results object is ready for use. task_history: A TaskHistory object containing information about the tasks. known_data_types: List of valid data type strings for accessing data.
Key features:
- List-like interface for accessing individual Result objects
- Selection of specific data columns with select()
- Filtering results with boolean expressions using filter()
- Creating new derived columns with mutate()
- Recoding values with recode() and answer_truncate()
- Sorting results with order_by()
- Converting to other formats (dataset, table, pandas DataFrame)
- Serialization for storage and retrieval
- Support for remote execution and result retrieval
- Each Results object contains multiple Result objects
- Each Result object contains data organized by type (agent, scenario, model, answer, etc.)
- Each data type contains multiple attributes (e.g., “how_feeling” in the answer type)
Examples:
Bases:class ClassOrInstanceMethod(func)[source]
object
Descriptor that allows a method to be called as both a class method and an instance method.
init(func)[source]
Instantiate a Results object with a survey and a list of Result objects. Args: survey: A Survey object containing the questions used to generate results. data: A list of Result objects containing the responses. created_columns: A list of column names created through transformations. cache: A Cache object for storing model responses. job_uuid: A string representing the job UUID. total_results: An integer representing the total number of results. task_history: A TaskHistory object containing information about the tasks. sort_by_iteration: Whether to sort data by iteration before initializing. data_class: The class to use for the data container (default: list).init(survey: Optional[‘Survey’] = None, data: Optional[list[‘Result’]] = None, name: Optional[str] = None, created_columns: Optional[list[str]] = None, cache: Optional[‘Cache’] = None, job_uuid: Optional[str] = None, total_results: Optional[int] = None, task_history: Optional[‘TaskHistory’] = None, sort_by_iteration: bool = False, data_class: Optional[type] = <class ‘list’>)[source]
add_task_history_entry(interview: Interview) → None[source]
Returns a dictionary of agent answers. The keys are the agent names and the values are the answers.agent_answers_by_question(agent_key_fields: List[str] | None = None, separator: str = ’,’) → dict[source]
Return a set of all of the keys that are in the Agent data. Example:property agent_keys*: list[str]*[source]
Return a list of all of the agents in the Results. Example:property agents*: AgentList*[source]
Return a set of all of the keys that are in the Results. Example:property all_keys*: list[str]*[source]
Return a mapping of answer keys to question text. Example:property answer_keys*: dict[str, str]*[source]
apply_command(command_name, kwargs)[source]
Group Result objects into buckets keyed by the specified column values. Each key in the returned dictionary is a tuple containing the values of the requested columns (in the same order as supplied). The associated value is a list ofbucket_by(*columns: str) → dict[tuple, list[Result]][source]
Result instances whose values match that key.
Args:*columns: Names of the columns to group by. Column identifiers follow the same rules used by
select() – they can be specified either as fully-qualified names (e.g. "agent.status") or by bare attribute name when unambiguous.
Returns:dict[tuple, list[Result]]: Mapping from value tuples to lists of
Result objects.
Raises:ResultsError: If no columns are provided or an invalid column name is supplied.
Examples:
Create a chart from the results.chart()[source]
Copy this object’s representation to the system clipboard. This method first checks if the object has a custom clipboard_data() method. If it does, it uses that method’s output. Otherwise, it serializes the object to a dictionary (without version info) and copies it to the system clipboard as JSON text. Returns: None, but prints a confirmation messageclipboard()[source]
Return TSV representation of this object for clipboard operations. This method is called by the clipboard() method in the base class to provide a custom format for copying objects to the system clipboard. Returns: str: Tab-separated values representation of the objectclipboard_data() → str[source]
Method for generating code representations.code()[source]
Raises:ResultsError: This method is not implemented for Results objects.
Examples:
Return a list of all of the columns that are in the Results. Example:property columns*: list[str]*[source]
Compare two Results objects and return the differences.compare(other_results: Results) → dict[source]
Compute the cost of a completed job in USD. This method delegates to the JobCostCalculator class to calculate the total cost of all model responses in the results. By default, it only counts the cost of responses that were not cached.compute_job_cost(include_cached_responses_in_cost: bool = False) → float[source]
Args:include_cached_responses_in_cost: Whether to include the cost of cached responses in the total. Defaults to False.
Returns:float: The total cost in USD.
Examples:
Generate a downloadable link for this object. Creates a temporary file containing the serialized object and generates a download link that can be shared with others. Returns: str: A URL that can be used to download the objectcreate_download_link()[source]
Delete the object from coop.classmethod delete(url_or_uuid: str | UUID) → None[source]
Create a flattened dictionary representation for display purposes. This method creates a flattened view of nested structures using colon notation in keys to represent hierarchy. Returns: dict: A flattened dictionary suitable for displaydisplay_dict()[source]
Create and return a deep copy of the object. Args: add_edsl_version: Whether to include EDSL version information in the duplicated object Returns: A new instance of the same class with identical propertiesduplicate(add_edsl_version=False)[source]
Return an example Results object. Example usage:classmethod example(randomize: bool = False) → Results[source]
Extend the Results list with items from another iterable. This method preserves ordering based on ‘order’ attribute if present, otherwise falls back to ‘iteration’ attribute.extend_sorted(other)[source]
Poll the server for job completion and update this Results instance. This method delegates to the ResultsRemoteFetcher class to handle the polling and fetching operation. Args: polling_interval: Number of seconds to wait between polling attempts (default: 1.0) Returns: Results: The updated Results instance Raises: ResultsError: If no job info is available or if there’s an error during fetch.fetch(polling_interval: float | int = 1.0) → Results[source]
Fetch remote Results object and update this instance with the data. This method delegates to the ResultsRemoteFetcher class to handle the remote fetching operation. Args: job_info: RemoteJobInfo object containing the job_uuid and other remote job details Returns: bool: True if the fetch was successful, False if the job is not yet completed. Raises: ResultsError: If there’s an error during the fetch process.fetch_remote(job_info: Any) → bool[source]
Filter results based on a boolean expression. This method delegates to the ResultsFilter class to evaluate a boolean expression against each Result object in the collection and returns a new Results object containing only those that match.filter(expression: str) → Results[source]
Args:expression: A string containing a Python expression that evaluates to a boolean. The expression is applied to each Result object individually. Can be a multi-line string for better readability. Supports template-style syntax with
{{ field }} notation.
Returns:A new Results object containing only the Result objects that satisfy the expression.
Raises:ResultsFilterError: If the expression is invalid or uses improper syntax (like using ‘=’ instead of ‘==’).
Examples:
Return the first observation in the results. Example:first() → Result[source]
Expand a field containing dictionaries into separate fields. This method takes a field that contains a list of dictionaries and expands it into multiple fields, one for each key in the dictionaries. This is useful when working with nested data structures or results from extraction operations.flatten(field: str, keep_original: bool = False) → Dataset[source]
Parameters:field: The field containing dictionaries to flatten keep_original: Whether to retain the original field in the result
Returns:A new Dataset with the dictionary keys expanded into separate fields
Notes:
- Each key in the dictionaries becomes a new field with name pattern “.”
- All dictionaries in the field must have compatible structures
- If a dictionary is missing a key, the corresponding value will be None
- Non-dictionary values in the field will cause a warning
Examples:
Convert a dictionary to a Results object. This method delegates to the ResultsSerializer class to handle the conversion of a dictionary representation back to a Results object.classmethod from_dict(data: dict[str, Any]) → Results[source]
Args:data: A dictionary representation of a Results object.
Returns:Results: A new Results object created from the dictionary data
Examples:
Load a Results object from a zip file. This method delegates to the ResultsSerializer class to handle the disk deserialization. This method: 1. Extracts the SQLite database file 2. Loads the metadata 3. Creates a new Results instance with the restored dataclassmethod from_disk(filepath: str) → Results[source]
> Args:
filepath: Path to the zip file containing the serialized ResultsReturns:Results: A new Results instance with the restored data
Raises:ResultsError: If there’s an error during deserialization
Instantiate a Results object from a job info dictionary. This method creates a Results object in a not-ready state that will fetch its data from a remote source when methods are called on it.classmethod from_job_info(job_info: dict) → Results[source]
Args:job_info: Dictionary containing information about a remote job.
Returns:Results: A new Results instance with completed=False that will fetch remote data when needed.
Examples:
Create an instance from YAML data. Deserializes a YAML string or file into a new instance of the class. Args: yaml_str: YAML string containing object data filename: Path to a YAML file containing object data Returns: A new instance of the class populated with the deserialized data Raises: BaseValueError: If neither yaml_str nor filename is providedclassmethod from_yaml(yaml_str: str | None = None, filename: str | None = None)[source]
Get the answers for a given question name.get_answers(question_name: str) → list[source]
Args:question_name: The name of the question to fetch answers for.
Returns:list: A list of answers, one from each result in the data.
Examples:
Get the description of this object.get_description() → str[source]
Get a string hash representation of this object based on its content.get_hash() → str[source]
Returns:str: A string representation of the hash value
Retrieve a Result object from persistent storage. This method delegates to the ResultsSerializer class to handle the retrieval operation. Args: key: The hash key of the Result to retrieve Returns: Result: The stored Result object Raises: ResultsError: If the key doesn’t exist or if there’s an error retrieving the Resultget_shelved_result(key: str) → Result[source]
Internal method to get tabular data in a standard format. Args: remove_prefix: Whether to remove the prefix from column names pretty_labels: Dictionary mapping original column names to pretty labels Returns: Tuple containing (header_row, data_rows)get_tabular_data(remove_prefix: bool = False, pretty_labels: dict | None = None) → Tuple[List[str], List[List]][source]
Get the UUID of this object from the Expected Parrot cloud service based on its hash. This method calculates the hash of the object and queries the cloud service to find if there’s an uploaded version with the same content. If found, it returns the UUID of that object. Returns: str: The UUID of the object in the cloud service if found Raises: CoopServerResponseError: If the object is not found or there’s an error communicating with the serverget_uuid() → str[source]
Create visualizations using R’s ggplot2 library. This method provides a bridge to R’s powerful ggplot2 visualization library, allowing you to create sophisticated plots directly from EDSL data structures.ggplot2(ggplot_code: str, shape: str = ‘wide’, sql: str | None = None, remove_prefix: bool = True, debug: bool = False, height: float = 4, width: float = 6, factor_orders: dict | None = None)[source]
Parameters:ggplot_code: R code string containing ggplot2 commands shape: Data shape to use (“wide” or “long”) sql: Optional SQL query to transform data before visualization remove_prefix: Whether to remove prefixes (like “answer.”) from column names debug: Whether to display debugging information height: Plot height in inches width: Plot width in inches factor_orders: Dictionary mapping factor variables to their desired order Returns: A plot object that renders in Jupyter notebooks
Notes:
- Requires R and the ggplot2 package to be installed
- Data is automatically converted to a format suitable for ggplot2
- The ggplot2 code should reference column names as they appear after any transformations from the shape and remove_prefix parameters
Examples:
property has_unfixed_exceptions*: bool*[source]
property hashes*: set*[source]
Display the class documentation string. This is a convenience method to quickly access the docstring of the class. Returns: None, but prints the class docstring to stdoutclassmethod help()[source]
html(filename: str | None = None, cta: str = ‘Open in browser’, return_link: bool = False)[source]
initialize_cache_from_results()[source]
Move all shelved results into memory using insert_sorted method. This method delegates to the ResultsSerializer class to handle the shelf operations. Clears the shelf after successful insertion. This method preserves the original order of results by using their ‘order’ attribute if available, which ensures consistent ordering even after serialization/deserialization. Raises: ResultsError: If there’s an error accessing or clearing the shelfinsert_from_shelf() → None[source]
Insert a Result object into the Results list while maintaining sort order. Uses the ‘order’ attribute if present, otherwise falls back to ‘iteration’ attribute. Utilizes bisect for efficient insertion point finding.insert_sorted(item: Result) → None[source]
Args:item: A Result object to insert Examples:
Create an interactive inspector widget for this object. This method uses the InspectorWidget registry system to find the appropriate inspector widget class for this object’s type and returns an instance of it. Returns: InspectorWidget subclass instance: Interactive widget for inspecting this object Raises: KeyError: If no inspector widget is registered for this object’s class ImportError: If the widgets module cannot be importedinspect()[source]
Get a formatted JSON representation of this object. Returns: DisplayJSON: A displayable JSON representationjson()[source]
Get the key names in the object’s dictionary representation. This method returns all the keys in the serialized form of the object, excluding metadata keys like version information. Returns: list: A list of key nameskeys()[source]
List objects from coop. Notes: - The visibility parameter is not supported for remote inference jobs. - The job_status parameter is not supported for objects. - search_query only works with the description field. - If sort_ascending is False, then the most recently created objects are returned first.classmethod list(visibility: Literal[‘private’, ‘public’, ‘unlisted’] | List[Literal[‘private’, ‘public’, ‘unlisted’]] | None = None, job_status: Literal[‘queued’, ‘running’, ‘completed’, ‘failed’, ‘cancelled’, ‘cancelling’, ‘partial_failed’] | List[Literal[‘queued’, ‘running’, ‘completed’, ‘failed’, ‘cancelled’, ‘cancelling’, ‘partial_failed’]] | None = None, search_query: str | None = None, page: int = 1, page_size: int = 10, sort_ascending: bool = False) → CoopObjects[source]
Load the object from a JSON file (compressed or uncompressed). This method deserializes an object from a file, automatically detecting whether the file is compressed with gzip or not. Args: filename: Path to the file to load Returns: An instance of the class populated with data from the file Raises: Various exceptions may be raised if the file doesn’t exist or contains invalid dataclassmethod load(filename)[source]
Turn the results into a tabular format. Parameters: remove_prefix – Whether to remove the prefix from the column names.make_tabular(remove_prefix: bool, pretty_labels: dict | None = None) → tuple[list, List[list]][source]
Return a set of all of the keys that are in the LanguageModel data.property model_keys*: list[str]*[source]
Return a list of all of the models in the Results. Example:property models*: ModelList*[source]
Create a new column based on a computational expression. This method delegates to the ResultsTransformer class to handle the mutation operation.mutate(new_var_string: str, functions_dict: dict | None = None) → Results[source]
Args:new_var_string: A string containing an assignment expression in the form “new_column_name = expression”. The expression can reference any existing column and use standard Python syntax. functions_dict: Optional dictionary of custom functions that can be used in the expression. Keys are function names, values are function objects. Returns: A new Results object with the additional column. Examples:
Return the number of observations in the dataset.num_observations()[source]
Pull the object from coop. Args: url_or_uuid: Either a UUID string or a URL pointing to the objectclassmethod old_pull(url_or_uuid: str | UUID | None = None)[source]
Read and parse a compressed JSON file. Args: filename: Path to a gzipped JSON file Returns: dict: The parsed JSON contentstatic open_compressed_file(filename)[source]
Read and parse an uncompressed JSON file. Args: filename: Path to a JSON file Returns: dict: The parsed JSON contentstatic open_regular_file(filename)[source]
optimzie_scenarios()[source]
Sort the results by one or more columns. This method delegates to the ResultsTransformer class to handle the sorting operation.order_by(*columns: str, reverse: bool = False) → Results[source]
Args:columns: One or more column names as strings. reverse: A boolean that determines whether to sort in reverse order.
Returns:Results: A new Results object with sorted data.
Examples:
patch(**kwargs)[source]
Patch an uploaded object’s attributes (class method version). - description changes the description of the object on Expected Parrot - value changes the value of the object on Expected Parrot. has to be an EDSL object - visibility changes the visibility of the object on Expected Parrotclassmethod patch_cls(url_or_uuid: str | UUID, description: str | None = None, value: Any | None = None, visibility: str | None = None)[source]
Auto-generate commands list from methods decorated with @polly_commandproperty polly_commands[source]
Print a formatted table representation of this object. Args: format: The output format (currently only ‘rich’ is supported) Returns: None, but prints a formatted table to the consoleprint(format=‘rich’)[source]
Print the results in a long format. >>> from edsl.results import Results >>> r = Results.example() >>> r.select(‘how_feeling’).print_long() answer.how_feeling: OK answer.how_feeling: Great answer.how_feeling: Terrible answer.how_feeling: OKprint_long()[source]
Get a signed URL for directly downloading an object from Google Cloud Storage. This method provides a more efficient way to download objects compared to the old pull() method, especially for large files, by generating a direct signed URL to the storage bucket.classmethod pull(url_or_uuid: str | UUID | None = None, expected_parrot_url: str | None = None) → dict[source]
Args:url_or_uuid (Union[str, UUID], optional): Identifier for the object to retrieve. Can be one of: - UUID string (e.g., “123e4567-e89b-12d3-a456-426614174000”) - Full URL (e.g., “https://expectedparrot.com/content/123e4567…”) - Alias URL (e.g., “https://expectedparrot.com/content/username/my-survey”) expected_parrot_url (str, optional): Optional custom URL for the coop service
Returns:dict: A response containing the signed_url for direct download
Example:
Get a signed URL for directly uploading an object to Google Cloud Storage. This method provides a more efficient way to upload objects compared to the push() method, especially for large files, by generating a direct signed URL to the storage bucket.push(description: str | None = None, alias: str | None = None, visibility: str | None = ‘unlisted’, expected_parrot_url: str | None = None) → dict[source]
Args:expected_parrot_url (str, optional): Optional custom URL for the coop service
Returns:dict: A response containing the signed_url for direct upload and optionally a job_id
Example:
Return a list of all of the question names. Example:property question_names*: list[str]*[source]
Return the set of keys that are present in the dataset. Parameters:relevant_cache(cache: Cache) → Cache[source]
- data_type – The data type to filter by.
- remove_prefix – Whether to remove the prefix from the column names.
Returns a new Dataset with the prefix removed from all column names. The prefix is defined as everything before the first dot (.) in the column name. If removing prefixes would result in duplicate column names, an exception is raised.remove_prefix()[source]
Returns:Dataset: A new Dataset with prefixes removed from column names
Raises:ValueError: If removing prefixes would result in duplicate column names
Examples:
Rename an answer column in a Results object. This method delegates to the ResultsTransformer class to handle the renaming operation.rename(old_name: str, new_name: str) → Results[source]
Args:old_name: The current name of the column to rename new_name: The new name for the column
Returns:Results: A new Results object with the column renamed
Examples:
Generates a report of the results by iterating through rows.report(*fields: str | None, top_n: int | None = None, header_fields: List[str] | None = None, divider: bool = True, return_string: bool = False, format: str = ‘markdown’, filename: str | None = None) → str | Document | None[source]
Args:*fields: The fields to include in the report. If none provided, all fields are used. top_n: Optional limit on the number of observations to include. header_fields: Optional list of fields to include in the main header instead of as sections. divider: If True, adds a horizontal rule between observations (markdown only). return_string: If True, returns the markdown string. If False (default in notebooks), only displays the markdown without returning. format: Output format - either “markdown” or “docx”. filename: If provided and format is “docx”, saves the document to this file.
Returns:Depending on format and return_string: - For markdown: A string if return_string is True, otherwise None (displays in notebook) - For docx: A docx.Document object, or None if filename is provided (saves to file)
Examples:
Generates a report using a Jinja2 template for each row in the dataset. This method renders a user-provided Jinja2 template for each observation in the dataset, with template variables populated from the row data. This allows for completely customized report formatting using pandoc for advanced output formats.report_from_template(template: str, *fields: str | None, top_n: int | None = None, remove_prefix: bool = True, return_string: bool = False, format: str = ‘text’, filename: str | None = None, separator: str = ‘nn’, observation_title_template: str | None = None, explode: bool = False, filestore: bool = False) → str | Document | List | FileStore | None[source]
Args:template: Jinja2 template string to render for each row *fields: The fields to include in template context. If none provided, all fields are used. top_n: Optional limit on the number of observations to include. remove_prefix: Whether to remove type prefixes (e.g., “answer.”) from field names in template context. return_string: If True, returns the rendered content. If False (default in notebooks), only displays the content without returning. format: Output format - one of “text”, “html”, “pdf”, or “docx”. Formats other than “text” require pandoc. filename: If provided, saves the rendered content to this file. For exploded output, this becomes a template (e.g., “report_{index}”). separator: String to use between rendered templates for each row (ignored when explode=True). observation_title_template: Optional Jinja2 template for observation titles. Defaults to “Observation ” where index is 1-based. Template has access to all row data plus ‘index’ and ‘index0’ variables. explode: If True, creates separate files for each observation instead of one combined file. filestore: If True, wraps the generated file(s) in FileStore object(s). If no filename is provided, creates temporary files. For exploded output, returns a list of FileStore objects.
Returns:Depending on explode, format, return_string, and filestore: - For text format: String content or None (if displayed in notebook) - For html format: HTML string content or None (if displayed in notebook) - For docx format: Document object or None (if saved to file) - For pdf format: PDF bytes or None (if saved to file) - If explode=True: List of created filenames (when filename provided) or list of documents/content - If filestore=True: FileStore object(s) containing the generated file(s)
Notes:
- Pandoc is required for HTML, PDF, and DOCX output formats
- Templates are treated as Markdown for all non-text formats
- PDF output uses XeLaTeX engine through pandoc
- HTML output includes standalone document structure
Examples:
Display an object as a table.rich_print()[source]
Return a random sample of the results.sample(n: int | None = None, frac: float | None = None, with_replacement: bool = True, seed: str | None = None) → Results[source]
Args:n: The number of samples to take. frac: The fraction of samples to take (alternative to n). with_replacement: Whether to sample with replacement. seed: Random seed for reproducibility.
Returns:Results: A new Results object containing the sampled data.
Save the object to a file as JSON with optional compression. Serializes the object to JSON and writes it to the specified file. By default, the file will be compressed using gzip. File extensions are handled automatically.save(filename: str | None = None, compress: bool = True)[source]
Args:filename: Path where the file should be saved compress: If True, compress the file using gzip (default: True)
Returns:None
Examples:
Return a set of all of the keys that are in the Scenario data.property scenario_keys*: list[str]*[source]
Return a list of all of the scenarios in the Results. Example:property scenarios*: ScenarioList*[source]
Score the results using a function. This method delegates to the ResultsScorer class to handle the scoring operation.score(f: Callable) → list[source]
Args:f: A function that takes values from a Result object and returns a score.
Returns:list: A list of scores, one for each Result object.
Examples:
Score the results using an answer key. This method delegates to the ResultsScorer class to handle the scoring operation.score_with_answer_key(answer_key: dict) → list[source]
Args:answer_key: A dictionary that maps answer values to scores.
Returns:list: A list of scores, one for each Result object.
Search for objects on coop.classmethod search(query)[source]
Extract specific columns from the Results into a Dataset. This method allows you to select specific columns from the Results object and transforms the data into a Dataset for further analysis and visualization. A Dataset is a more general-purpose data structure optimized for analysis operations rather than the hierarchical structure of Result objects.select(**columns: str | list[str]*) → Dataset[source]
Args:*columns: Column names to select. Each column can be:
- A simple attribute name (e.g., “how_feeling”)
- A fully qualified name with type (e.g., “answer.how_feeling”)
- A wildcard pattern (e.g., “answer.*” to select all answer fields)
Returns:A Dataset object containing the selected data.
Notes:
- Column names are automatically disambiguated if needed
- When column names are ambiguous, specify the full path with data type
- You can use wildcard patterns with “*” to select multiple related fields
- Selecting with no arguments returns all data
- Results are restructured in a columnar format in the Dataset
Examples:
Return a copy of the set of shelved result keys. This property delegates to the ResultsSerializer class.property shelf_keys*: set*[source]
Store a Result object in persistent storage using its hash as the key. This method delegates to the ResultsSerializer class to handle the shelving operation.shelve_result(result: Result) → str[source]
Args:result: A Result object to store
Returns:str: The hash key for retrieving the result later
Raises:ResultsError: If there’s an error storing the Result
Print the exceptions.show_exceptions(traceback=False)[source]
Display all public methods available on this object. This utility method helps explore the capabilities of an object by listing all its public methods and optionally their documentation.show_methods(show_docstrings=True)[source]
Args:show_docstrings: If True, print method names with docstrings; if False, return the list of method names
Returns:None or list: If show_docstrings is True, prints methods and returns None. If show_docstrings is False, returns a list of method names.
Return a shuffled copy of the results using Fisher-Yates algorithm.shuffle(seed: str | None = ‘edsl’) → Results[source]
Args:seed: Random seed for reproducibility.
Returns:Results: A new Results object with shuffled data.
Sort the results by one or more columns. This method delegates to the ResultsTransformer class to handle the sorting operation.sort_by(*columns: str, reverse: bool = False) → Results[source]
Args:columns: One or more column names as strings. reverse: A boolean that determines whether to sort in reverse order.
Returns:Results: A new Results object with sorted data.
Examples:
Run a survey to spot issues and suggest improvements for prompts that had no model response. This method delegates to the ResultsAnalyzer class to handle the analysis and debugging. Args: models: Optional ModelList to use for the analysis. If None, uses the default model. Returns: Results: A new Results object containing the analysis and suggestions for improvement. Notes: Future version: Allow user to optionally pass a list of questions to review, regardless of whether they had a null model response.spot_issues(models: ModelList | None = None) → Results[source]
Execute SQL queries on the dataset. This powerful method allows you to use SQL to query and transform your data, combining the expressiveness of SQL with EDSL’s data structures. It works by creating an in-memory SQLite database from your data and executing the query against it.sql(query: str, transpose: bool = None, transpose_by: str = None, remove_prefix: bool = True, shape: str = ‘wide’) → Dataset[source]
Parameters:query: SQL query string to execute transpose: Whether to transpose the resulting table (rows become columns) transpose_by: Column to use as the new index when transposing remove_prefix: Whether to remove type prefixes (e.g., “answer.”) from column names shape: Data shape to use (“wide” or “long”)
- “wide”: Default tabular format with columns for each field
- “long”: Melted format with key-value pairs, useful for certain queries
Returns:A Dataset object containing the query results
Notes:
- The data is stored in a table named “self” in the SQLite database
- In wide format, column names include their type prefix unless remove_prefix=True
- In long format, the data is melted into columns: row_number, key, value, data_type
- Complex objects like lists and dictionaries are converted to strings
Store this object in a dictionary with an optional key.store(d: dict, key_name: str | None = None)[source]
Args:d: The dictionary in which to store the object key_name: Optional key to use (defaults to the length of the dictionary)
Returns:None
table(*fields, tablefmt: str | None = ‘rich’, pretty_labels: dict | None = None, print_parameters: dict | None = None)[source]
Count frequency distributions of values in specified fields. This method tallies the occurrence of unique values within one or more fields, similar to a GROUP BY and COUNT in SQL. When multiple fields are provided, it performs cross-tabulation across those fields.tally(*fields: str | None, top_n: int | None = None, output=‘Dataset’) → dict | Dataset[source]
Parameters:*fields: Field names to tally. If none provided, uses all available fields. top_n: Optional limit to return only the top N most frequent values. output: Format for results, either “Dataset” (recommended) or “dict”.
Returns:By default, returns a Dataset with columns for the field(s) and a ‘count’ column. If output=”dict”, returns a dictionary mapping values to counts.
Notes:
- For single fields, returns counts of each unique value
- For multiple fields, returns counts of each unique combination of values
- Results are sorted in descending order by count
- Fields can be specified with or without their type prefix
Examples:
Convert the results to a list of dictionaries, one per agent.to_agent_list(remove_prefix: bool = True)[source]
Parameters:remove_prefix – Whether to remove the prefix from the column names.
Export the results to a FileStore instance containing CSV data.to_csv(filename: str | None = None, remove_prefix: bool = False, pretty_labels: dict | None = None) → FileStore[source]
Convert this object to a Dataset for advanced data operations.to_dataset() → Dataset[source]
Returns:Dataset: A Dataset object containing this object’s data
Convert the Results object to a dictionary representation. This method delegates to the ResultsSerializer class to handle the conversion of the Results object to a dictionary format suitable for serialization.to_dict(sort: bool = False, add_edsl_version: bool = True, include_cache: bool = True, include_task_history: bool = False, include_cache_info: bool = True, offload_scenarios: bool = True, full_dict: bool = False) → dict[str, Any][source]
Args:sort: Whether to sort the results data by hash before serialization add_edsl_version: Whether to include the EDSL version in the output include_cache: Whether to include cache data in the output include_task_history: Whether to include task history in the output include_cache_info: Whether to include cache information in result data offload_scenarios: Whether to optimize scenarios before serialization
Returns:dict[str, Any]: Dictionary representation of the Results object
Convert the results to a list of dictionaries.to_dicts(remove_prefix: bool = True) → list[dict][source]
Parameters:remove_prefix – Whether to remove the prefix from the column names.
Serialize the Results object to a zip file, preserving the SQLite database. This method delegates to the ResultsSerializer class to handle the disk serialization. This method creates a zip file containing: 1. The SQLite database file from the data container 2. A metadata.json file with the survey, created_columns, and other non-data info 3. The cache data if present Args: filepath: Path where the zip file should be saved Raises: ResultsError: If there’s an error during serializationto_disk(filepath: str) → None[source]
Export the results to a FileStore instance containing DOCX data. Each row of the dataset will be rendered on its own page, with a 2-column table that lists the keys and associated values for that observation.to_docx(filename: str | None = None, remove_prefix: bool = False, pretty_labels: dict | None = None) → FileStore[source]
Export the results to a FileStore instance containing Excel data.to_excel(filename: str | None = None, remove_prefix: bool = False, pretty_labels: dict | None = None, sheet_name: str | None = None)[source]
Serialize this object to a JSON string. Returns: str: A JSON string representation of the objectto_json()[source]
Export the results to a FileStore instance containing JSONL data.to_jsonl(filename: str | None = None)[source]
Convert the results to a list of lists. Parameters:to_list(flatten=False, remove_none=False, unzipped=False) → list[list][source]
- flatten – Whether to flatten the list of lists.
- remove_none – Whether to remove None values from the list.
Convert the results to a pandas DataFrame, ensuring that lists remain as lists. Args: remove_prefix: Whether to remove the prefix from the column names. lists_as_strings: Whether to convert lists to strings. Returns: A pandas DataFrame.to_pandas(remove_prefix: bool = False, lists_as_strings=False)[source]
Convert the results to a Polars DataFrame. Args: remove_prefix: Whether to remove the prefix from the column names. lists_as_strings: Whether to convert lists to strings. Returns: A Polars DataFrame.to_polars(remove_prefix: bool = False, lists_as_strings=False)[source]
Convert the results to a list of dictionaries, one per scenario. Parameters: remove_prefix – Whether to remove the prefix from the column names.to_scenario_list(remove_prefix: bool = True) → list[dict][source]
Export the results to a SQLite database file.to_sqlite(filename: str | None = None, remove_prefix: bool = False, pretty_labels: dict | None = None, table_name: str = ‘results’, if_exists: str = ‘replace’)[source]
Convert the object to YAML format. Serializes the object to YAML format and optionally writes it to a file. Args: add_edsl_version: Whether to include EDSL version information filename: If provided, write the YAML to this file path Returns: str: The YAML string representation if no filename is provided None: If written to fileto_yaml(add_edsl_version=False, filename: str = None) → str | None[source]
Convert the results to a Tree. Args: node_order: The order of the nodes. Returns: A Tree object.tree(node_order: List[str] | None = None)[source]
Unpack list columns into separate columns with provided names or numeric suffixes. For example, if a dataset contains: [{‘data’: [[1, 2, 3], [4, 5, 6]], ‘other’: [‘x’, ‘y’]}] After d.unpack_list(‘data’), it should become: [{‘other’: [‘x’, ‘y’], ‘data_1’: [1, 4], ‘data_2’: [2, 5], ‘data_3’: [3, 6]}]unpack_list(field: str, new_names: List[str] | None = None, keep_original: bool = True) → Dataset[source]
Args:field: The field containing lists to unpack new_names: Optional list of names for the unpacked fields. If None, uses numeric suffixes. keep_original: If True, keeps the original field in the dataset
Returns:A new Dataset with unpacked columns
Examples:
Get the values in the object’s dictionary representation. Returns: set: A set containing all the values in the objectvalues()[source]
View the results in a Jupyter notebook.view() → None[source]
Get a formatted YAML representation of this object. Returns: DisplayYAML: A displayable YAML representationyaml()[source]
