pyrit.score.ScorerIdentifier#

class ScorerIdentifier(type: str, system_prompt_template: str | None = None, user_prompt_template: str | None = None, sub_identifier: List[ScorerIdentifier] | None = None, target_info: Dict[str, Any] | None = None, score_aggregator: str | None = None, scorer_specific_params: Dict[str, Any] | None = None)[source]#

Bases: object

Configuration class for Scorers.

This class encapsulates the modifiable parameters that can be used to create a complete scoring configuration. These parameters can be modified, and configurations can be compared to each other via scorer evaluations.

__init__(type: str, system_prompt_template: str | None = None, user_prompt_template: str | None = None, sub_identifier: List[ScorerIdentifier] | None = None, target_info: Dict[str, Any] | None = None, score_aggregator: str | None = None, scorer_specific_params: Dict[str, Any] | None = None) None#

Methods

__init__(type[, system_prompt_template, ...])

compute_hash([hashable_dict])

Compute a hash representing the current configuration.

from_compact_dict(data)

Create a ScorerIdentifier from a compact dictionary (as stored in JSONL).

to_compact_dict()

Convert the ScorerIdentifier to a compact dictionary for storage.

Attributes

compute_hash(hashable_dict: Dict[str, Any] | None = None) str[source]#

Compute a hash representing the current configuration.

Parameters:

hashable_dict – Pre-computed hashable dict to avoid recomputation. If None, _to_hashable_dict() will be called.

Returns:

A hash string representing the configuration.

Return type:

str

classmethod from_compact_dict(data: Dict[str, Any]) ScorerIdentifier[source]#

Create a ScorerIdentifier from a compact dictionary (as stored in JSONL).

Handles the __type__ -> type field mapping and recursively reconstructs nested sub_identifiers.

Note

This is a LOSSY reconstruction. Long prompts (>100 chars) are stored as “sha256:{hash[:16]}” and the original text is not recoverable. Hash-based lookups still work correctly since compute_hash() is deterministic and uses the same hashing logic for long prompts before computing the hash.

Parameters:

data (Dict[str, Any]) – The compact dictionary representation.

Returns:

A new ScorerIdentifier instance (with possibly hashed prompt fields).

Return type:

ScorerIdentifier

score_aggregator: str | None = None#
scorer_specific_params: Dict[str, Any] | None = None#
sub_identifier: List[ScorerIdentifier] | None = None#
system_prompt_template: str | None = None#
target_info: Dict[str, Any] | None = None#
to_compact_dict() Dict[str, Any][source]#

Convert the ScorerIdentifier to a compact dictionary for storage.

Long prompts (>100 characters) are hashed to sha256:{hash[:16]} format. Nested sub_identifiers are recursively compacted. Includes the computed hash of the configuration.

Returns:

A compact dictionary representation with hash.

Return type:

Dict[str, Any]

type: str#
user_prompt_template: str | None = None#