Skip to Content
SDKEntitiesOverview

Entities

Entities are typed Python objects that map to platform resources, letting you create, read, update, and delete data programmatically. They appear throughout the SDK—for example, synthesizers return a TestSet entity containing multiple Test entities.

Working with entities requires a configured API key.

Available Entities

EntityDescription
ProjectTop-level organizational unit for resources
ModelLLM configurations with provider, model name, and API key
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
EndpointLLM applications and APIs tests run against

Entity vs Collection Classes

Each entity comes as two classes:

  • Entity classes (TestSet, Test, Endpoint) represent a single record. Use them to create, update, and delete individual items.
  • Collection classes (TestSets, Tests, Endpoints) provide query methods. Use them to fetch and search records.

All entities share the interface below. Per-entity pages document only what is specific to that entity.

Fetching entities

Retrieve records using the collection class:

fetch_entities.py
from rhesis.sdk.entities import TestSets

# Get all
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, must be unique)
test_set = TestSets.pull(name="My Test Set")

# Get first record
first = TestSets.first()

pull(name=...) raises ValueError if the name matches no record or more than one.

Filtering results

Pass an OData filter string to all():

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 and updating

Instantiate an entity and call push() to save it. push() creates a record when id is unset and updates it otherwise:

create_update.py
from rhesis.sdk.entities import Category, Categories

# Create
category = Category(name="Safety", description="Safety-critical behaviors")
category.push()
print(f"Created with ID: {category.id}")

# Update
category = Categories.pull(name="Safety")
category.description = "Updated description"
category.push()

Refreshing from the platform

Call pull() on an instance to overwrite its fields with the current server state:

refresh_entity.py
test_set = TestSets.pull(id="abc123")
# ... data may change on the platform ...
test_set.pull()
print(f"Updated test count: {test_set.test_count}")

Checking existence and deleting

exists_delete.py
from rhesis.sdk.entities import Categories

# exists() returns a bool without loading the full record
if Categories.exists("abc123"):
    category = Categories.pull(id="abc123")

# delete() returns True on success, False if the record was not found
deleted = category.delete()

Exporting

Entities convert to dictionaries and single-row CSV files:

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

data = category.to_dict()
category.to_csv("category.csv")

Next: create a project, register an endpoint, or build test sets.