Skip to Content
SDKEntitiesOverview

Entities

Entities are the SDK’s interface to the Rhesis platform. They provide typed Python objects that map directly to platform resources, enabling you to create, read, update, and delete data programmatically. Entities are used throughout the SDK—for example, synthesizers generate a TestSet entity that contains multiple Test entities.

Prerequisites: To work with entities from app.rhesis.ai , ensure you have configured the SDK with your API key.

Available Entities

EntityDescription
BehaviorExpected behaviors with associated metrics
CategoryTest categorization
TopicSubject matter classification
StatusEntity state tracking
TestIndividual test cases with prompts
TestSetCollections of tests for evaluation
TestRunExecution records for test batches
TestResultIndividual test execution results
TestConfigurationSettings for test execution
EndpointAI services to test against

Entity vs Collection Classes

The SDK uses two class patterns:

  • Entity classes (TestSet, Test, Endpoint): Represent single records. Use for creating, updating, and deleting individual items.
  • Collection classes (TestSets, Tests, Endpoints): Provide query methods. Use for fetching and searching records.
entity_vs_collection.py
from rhesis.sdk.entities import TestSet, TestSets

# Collection: query operations
all_sets = TestSets.all()                    # Get all
one_set = TestSets.pull(id="abc123")         # Get by ID
exists = TestSets.exists("abc123")           # Check existence

# Entity: instance operations
test_set = TestSet(name="New Set", ...)      # Create new
test_set.push()                              # Save to platform
test_set.pull()                              # Refresh from platform
test_set.delete()                            # Remove from platform

Common Operations

All entities share a consistent interface for CRUD operations. Each entity class has a corresponding collection class (e.g., TestSet and TestSets) for querying multiple records.

Fetching Entities

Retrieve entities from the platform using the collection class:

fetch_entities.py
from rhesis.sdk.entities import TestSets, TestSet

# Get all test sets
all_test_sets = TestSets.all()
for ts in all_test_sets:
    print(f"{ts.name}: {ts.test_count} tests")

# Get by ID
test_set = TestSets.pull(id="abc123")

# Get by name (case-insensitive)
test_set = TestSets.pull(name="My Test Set")

# Get first record
first = TestSets.first()

Filtering Results

Use OData filter syntax to query specific records:

filter_entities.py
from rhesis.sdk.entities import TestSets, Tests

# Filter test sets by name pattern
test_sets = TestSets.all(filter="contains(tolower(name), 'safety')")

# Filter tests by category
tests = Tests.all(filter="category eq 'security'")

Creating Entities

Create new entities locally and save them to the platform with push():

create_entity.py
from rhesis.sdk.entities import Category

category = Category(
    name="Safety",
    description="Tests for safety-critical behaviors"
)

# Save to platform
category.push()
print(f"Created with ID: {category.id}")

Updating Entities

Modify entity attributes and call push() to save changes:

update_entity.py
from rhesis.sdk.entities import Categories

# Fetch existing entity
category = Categories.pull(name="Safety")

# Modify and save
category.description = "Updated description for safety tests"
category.push()

Refreshing from Platform

Use pull() on an instance to refresh its data from the platform:

refresh_entity.py
from rhesis.sdk.entities import TestSets

test_set = TestSets.pull(id="abc123")

# ... time passes, data may have changed on platform ...

# Refresh from platform
test_set.pull()
print(f"Updated test count: {test_set.test_count}")

Deleting Entities

Remove entities from the platform:

delete_entity.py
from rhesis.sdk.entities import Categories

category = Categories.pull(name="Deprecated Category")
deleted = category.delete()

if deleted:
    print("Category removed")

Checking Existence

Verify if an entity exists without fetching full data:

check_exists.py
from rhesis.sdk.entities import TestSets

if TestSets.exists("abc123"):
    test_set = TestSets.pull(id="abc123")
else:
    print("Test set not found")

Data Export

Entities support conversion to dictionaries and CSV files:

export_data.py
from rhesis.sdk.entities import Categories

category = Categories.pull(name="Safety")

# Convert to dictionary
data = category.to_dict()
print(data)

# Export to CSV
category.to_csv("category.csv")

Next Steps - Create and manage Test Sets for evaluation