plexus.dashboard.api.models.score_result module
- class plexus.dashboard.api.models.score_result.ScoreResult(id: str, value: str, itemId: str, accountId: str, scorecardId: str, scoreId: str | None = None, scoreVersionId: str | None = None, score: Dict[str, Any] | None = None, explanation: str | None = None, confidence: float | None = None, metadata: Dict | None = None, trace: Dict | None = None, correct: bool | None = None, cost: Dict | None = None, attachments: List[str] | None = None, scoringJobId: str | None = None, evaluationId: str | None = None, feedbackItemId: str | None = None, code: str | None = '200', type: str | None = 'prediction', status: str | None = 'COMPLETED', createdAt: datetime | None = None, updatedAt: datetime | None = None, client: _BaseAPIClient | None = None)
Bases:
BaseModelRepresents a single classification or scoring result in the Plexus dashboard.
ScoreResult is the core data structure for tracking individual scoring operations, used both for real-time scoring and evaluation. It integrates with the GraphQL API to provide:
Score value tracking with confidence
Metadata storage for debugging and analysis
Links to related entities (items, accounts, scorecards)
Evaluation result tracking
Batch processing support
Common usage patterns: 1. Creating a single score result:
- result = ScoreResult.create(
client=client, value=0.95, itemId=”item-123”, accountId=”acc-456”, scorecardId=”card-789”, metadata={“source”: “phone_call”}
)
- Batch creation for efficiency:
- results = ScoreResult.batch_create(client, [
- {
“value”: 0.95, “itemId”: “item-123”, “accountId”: “acc-456”, “scorecardId”: “card-789”
}, {
“value”: 0.82, “itemId”: “item-124”, “accountId”: “acc-456”, “scorecardId”: “card-789”
}
])
- Updating with evaluation results:
- result.update(
correct=True, evaluationId=”eval-123”, metadata={“human_label”: “Yes”}
)
ScoreResult is commonly used with: - Evaluation for accuracy testing - ScoringJob for batch processing - LangGraphScore for LLM-based classification
- __init__(id: str, value: str, itemId: str, accountId: str, scorecardId: str, scoreId: str | None = None, scoreVersionId: str | None = None, score: Dict[str, Any] | None = None, explanation: str | None = None, confidence: float | None = None, metadata: Dict | None = None, trace: Dict | None = None, correct: bool | None = None, cost: Dict | None = None, attachments: List[str] | None = None, scoringJobId: str | None = None, evaluationId: str | None = None, feedbackItemId: str | None = None, code: str | None = '200', type: str | None = 'prediction', status: str | None = 'COMPLETED', createdAt: datetime | None = None, updatedAt: datetime | None = None, client: _BaseAPIClient | None = None)
- accountId: str
- attachments: List[str] | None = None
- classmethod batch_create(client: _BaseAPIClient, items: List[Dict]) List[ScoreResult]
Create multiple score results in a single API request.
- code: str | None = '200'
- confidence: float | None = None
- correct: bool | None = None
- cost: Dict | None = None
- classmethod create(client: _BaseAPIClient, value: float, itemId: str, accountId: str, scorecardId: str, scoringJobId: str | None = None, evaluationId: str | None = None, code: str = '200', type: str = 'prediction', status: str = 'COMPLETED', **kwargs) ScoreResult
Create a new score result.
- Args:
client: The API client instance value: Score value (required) itemId: ID of scored item (required) accountId: Account context (required) scorecardId: ID of scorecard used (required) scoringJobId: ID of scoring job (optional) evaluationId: ID of evaluation (optional) code: HTTP response code (defaults to ‘200’ for success) type: Type of score result - “prediction”, “evaluation”, etc. (defaults to ‘prediction’) status: Status of score result (defaults to ‘COMPLETED’) **kwargs: Optional fields:
confidence: float
metadata: dict (will be JSON serialized)
trace: dict (will be JSON serialized)
cost: dict (will be JSON serialized)
correct: bool
attachments: List[str]
- Note:
Either scoringJobId or evaluationId should be provided, but not required
- createdAt: datetime | None = None
- evaluationId: str | None = None
- explanation: str | None = None
- feedbackItemId: str | None = None
- classmethod fields() str
Return the GraphQL fields to query for this model
- classmethod find_by_cache_key(client: _BaseAPIClient, item_id: str, type: str, score_id: str, account_id: str | None = None) ScoreResult | None
Find the most recent ScoreResult using cache key components.
This method encapsulates the cache lookup logic for finding existing ScoreResults based on the standard cache key: itemId + type + scoreId. It uses the time-based GSI to return the most recent result by updatedAt.
- Args:
client: API client for database operations item_id: Item ID (should be resolved DynamoDB ID) type: Type of score result (should be “prediction” or “evaluation”) score_id: Score ID (should be resolved DynamoDB ID) account_id: Optional account ID for additional context/validation
- Returns:
Most recent ScoreResult matching the cache key, or None if not found
- Example:
# Find cached score result cached_result = ScoreResult.find_by_cache_key(
client=client, item_id=”da270073-83ab-4c43-a1e6-961851c13d92”, type=”prediction”, score_id=”687361f7-44a9-466f-8920-7f9dc351bcd2”
)
- classmethod from_dict(data: Dict[str, Any], client: _BaseAPIClient) ScoreResult
Create a ScoreResult instance from API response data.
- classmethod get_by_id(score_result_id: str, client: _BaseAPIClient) ScoreResult | None
Get a ScoreResult by its ID.
- Args:
score_result_id: The ID of the score result to retrieve client: The API client to use
- Returns:
ScoreResult object if found, None otherwise
- itemId: str
- metadata: Dict | None = None
- property numeric_value: float | None
Get the numeric value as a float, or None if invalid.
- score: Dict[str, Any] | None
- scoreId: str | None = None
- property scoreName: str | None
Get the score name from the related score object.
- scoreVersionId: str | None = None
- scorecardId: str
- scoringJobId: str | None = None
- status: str | None = 'COMPLETED'
- trace: Dict | None = None
- type: str | None = 'prediction'
- update(**kwargs) ScoreResult
Update this score result with new values.
- updatedAt: datetime | None = None
- value: str