Skip to main content

Installation

Core Functions

init()

Initializes the ZeroEval SDK. Must be called before using any other SDK features.
Example:
redaction uses snake_case keys in Python. Redaction applies only to ingested payload fields (input_data and output_data). Attributes, tags, session metadata, and error messages are not redacted.
See PII redaction for scope, placeholder behavior, normalization rules, and examples.

Decorators

@span

Decorator and context manager for creating spans around code blocks.
Parameters:
  • name (str): Name of the span
  • session_id (str, optional): Deprecated - Use session parameter instead
  • session (Union[str, dict], optional): Session information. Can be:
    • A string containing the session ID
    • A dict with {"id": "...", "name": "..."}
  • attributes (dict, optional): Additional attributes to attach to the span
  • input_data (str, optional): Manual input data override
  • output_data (str, optional): Manual output data override
  • tags (dict, optional): Tags to attach to the span
Usage as Decorator:
Usage as Context Manager:

artifact_span

Ergonomic wrapper for creating artifact-bearing spans. Produces a span with kind="llm" and the completion_artifact_* attributes pre-filled so the prompt completions page surfaces it as a first-class artifact.
Parameters:
  • name (str): Name of the span
  • artifact_type (str): Artifact type identifier (e.g. "final_decision", "customer_card")
  • role (str): "primary" (used for row preview) or "secondary". Defaults to "primary"
  • label (str, optional): Human-friendly label shown in the artifact switcher. Defaults to the span name
  • kind (str): Span kind. Defaults to "llm"
  • session (Union[str, dict], optional): Session information
  • attributes (dict, optional): Additional attributes merged with artifact metadata. Artifact keys take precedence
  • input_data (str, optional): Manual input data override
  • output_data (str, optional): Manual output data override
  • tags (dict, optional): Tags to attach to the span
Usage as Context Manager:
Usage as Decorator:
ze.artifact_span is available in the Python SDK only for now.

@experiment

Decorator that attaches dataset and model information to a function.
Parameters:
  • dataset (Dataset, optional): Dataset to use for the experiment
  • model (str, optional): Model identifier
Example:

Classes

Dataset

A class to represent a named collection of dictionary records.

Constructor

Parameters:
  • name (str): The name of the dataset
  • data (list[dict]): A list of dictionaries containing the data
  • description (str, optional): A description of the dataset
Example:

Methods

push()
Push the dataset to the backend, creating a new version if it already exists.
Parameters:
  • self: The Dataset instance
  • create_new_version (bool, optional): For backward compatibility. This parameter is no longer needed as new versions are automatically created when a dataset name already exists. Defaults to False
Returns: Returns self for method chaining
pull()
Static method to pull a dataset from the backend.
Parameters:
  • cls: The Dataset class itself (automatically provided when using @classmethod)
  • dataset_name (str): The name of the dataset to pull from the backend
  • version_number (int, optional): Specific version number to pull. If not provided, pulls the latest version
Returns: A new Dataset instance populated with data from the backend
add_rows()
Add new rows to the dataset.
Parameters:
  • self: The Dataset instance
  • new_rows (list[dict]): A list of dictionaries representing the rows to add
add_image()
Add an image to a specific row.
Parameters:
  • self: The Dataset instance
  • row_index (int): Index of the row to update (0-based)
  • column_name (str): Name of the column to add the image to
  • image_path (str): Path to the image file to add
add_audio()
Add audio to a specific row.
Parameters:
  • self: The Dataset instance
  • row_index (int): Index of the row to update (0-based)
  • column_name (str): Name of the column to add the audio to
  • audio_path (str): Path to the audio file to add
add_media_url()
Add a media URL to a specific row.
Parameters:
  • self: The Dataset instance
  • row_index (int): Index of the row to update (0-based)
  • column_name (str): Name of the column to add the media URL to
  • media_url (str): URL pointing to the media file
  • media_type (str, optional): Type of media - “image”, “audio”, or “video”. Defaults to “image”

Properties

  • name (str): The name of the dataset
  • description (str): The description of the dataset
  • columns (list[str]): List of all unique column names
  • data (list[dict]): List of the data portion for each row
  • backend_id (str): The ID in the backend (after pushing)
  • version_id (str): The version ID in the backend
  • version_number (int): The version number in the backend

Example

Experiment

Represents an experiment that runs a task on a dataset with optional evaluators.

Constructor

Parameters:
  • dataset (Dataset): The dataset to run the experiment on
  • task (Callable): Function that processes each row and returns output
  • evaluators (list[Callable], optional): List of evaluator functions that take (row, output) and return evaluation result
  • name (str, optional): Name of the experiment. Defaults to task function name
  • description (str, optional): Description of the experiment. Defaults to task function’s docstring
Example:

Methods

run()
Run the complete experiment (task + evaluators).
Parameters:
  • self: The Experiment instance
  • subset (list[dict], optional): Subset of dataset rows to run the experiment on. If None, runs on entire dataset
Returns: List of experiment results for each row
run_task()
Run only the task without evaluators.
Parameters:
  • self: The Experiment instance
  • subset (list[dict], optional): Subset of dataset rows to run the task on. If None, runs on entire dataset
  • raise_on_error (bool, optional): If True, raises exceptions encountered during task execution. If False, captures errors. Defaults to False
Returns: List of experiment results for each row
run_evaluators()
Run evaluators on existing results.
Parameters:
  • self: The Experiment instance
  • evaluators (list[Callable], optional): List of evaluator functions to run. If None, uses evaluators from the Experiment instance
  • results (list[ExperimentResult], optional): List of results to evaluate. If None, uses results from the Experiment instance
Returns: The evaluated results

Span

Represents a span in the tracing system. Usually created via the @span decorator.

Methods

set_io()
Set input and output data for the span.
Parameters:
  • self: The Span instance
  • input_data (str, optional): Input data to attach to the span. Will be converted to string if not already
  • output_data (str, optional): Output data to attach to the span. Will be converted to string if not already
set_tags()
Set tags on the span.
Parameters:
  • self: The Span instance
  • tags (dict[str, str]): Dictionary of tags to set on the span
set_attributes()
Set attributes on the span.
Parameters:
  • self: The Span instance
  • attributes (dict[str, Any]): Dictionary of attributes to set on the span
set_error()
Set error information for the span.
Parameters:
  • self: The Span instance
  • code (str): Error code or exception class name
  • message (str): Error message
  • stack (str, optional): Stack trace information
add_screenshot()
Attach a screenshot to the span for visual evaluation by LLM judges. Screenshots are uploaded during ingestion and can be evaluated alongside text data.
Parameters:
  • self: The Span instance
  • base64_data (str): Base64 encoded image data. Accepts raw base64 or data URL format (data:image/png;base64,...)
  • viewport (str, optional): Viewport type - "desktop", "mobile", or "tablet". Defaults to "desktop"
  • width (int, optional): Image width in pixels
  • height (int, optional): Image height in pixels
  • label (str, optional): Human-readable description of the screenshot
Example:
add_image()
Attach a generic image to the span for visual evaluation. Use this for non-screenshot images like charts, diagrams, or UI component states.
Parameters:
  • self: The Span instance
  • base64_data (str): Base64 encoded image data. Accepts raw base64 or data URL format
  • label (str, optional): Human-readable description of the image
  • metadata (dict, optional): Additional metadata to store with the image
Example:
Attaching images via URL (S3 presigned or CDN)
If your images are already hosted externally, you can pass an HTTPS URL instead of base64 data. ZeroEval will download, validate, and copy the image into its own storage during ingestion. Supported URL sources:
  • S3 presigned URLs (*.amazonaws.com with valid authentication parameters)
  • CDN URLs from trusted domains
Attach URLs directly via attributes.attachments using the url key:
Images attached to spans can be evaluated by LLM judges configured for multimodal evaluation. See the Multimodal Evaluation guide for setup instructions.

Context Functions

get_current_span()

Returns the currently active span, if any.
Returns: The currently active Span instance, or None if no span is active

get_current_trace()

Returns the current trace ID.
Returns: The current trace ID, or None if no trace is active

get_current_session()

Returns the current session ID.
Returns: The current session ID, or None if no session is active

set_tag()

Sets tags on a span, trace, or session.
Parameters:
  • target: The target to set tags on
    • Span: Sets tags on the specific span
    • str: Sets tags on the trace (if valid trace ID) or session (if valid session ID)
  • tags (dict[str, str]): Dictionary of tags to set
Example:

Judge Feedback APIs

send_feedback()

Programmatically submit user feedback for a completion or judge evaluation.
Notes:
  • Existing usage without criteria_feedback is unchanged.
  • criteria_feedback is optional and supported for scored judges.
  • judge_id is required when sending expected_score, score_direction, or criteria_feedback.

get_judge_criteria()

Fetch normalized criteria metadata for a judge (useful before criterion-level feedback).
Returns:
  • judge_id
  • evaluation_type
  • score_min, score_max, pass_threshold
  • criteria (list of {key, label, description})

CLI Commands

The ZeroEval SDK includes a CLI tool for running experiments and setup.

zeroeval run

Run a Python script containing ZeroEval experiments.

zeroeval setup

Interactive setup to configure API credentials.

Environment Variables

Set before importing ZeroEval to configure default behavior.

Runtime Configuration

Configure after initialization via ze.tracer.configure().

Available Integrations

Control integrations via:
  • Environment: ZEROEVAL_DISABLED_INTEGRATIONS="langchain,claude_agent"
  • Init: disabled_integrations=["claude_agent"] or enabled_integrations=["openai"]
  • Runtime: ze.tracer.configure(integrations={"claude_agent": False})

Configuration Examples

Production

Development

Memory-Optimized