snorkelai.sdk.develop.ErrorAnalysis
- class snorkelai.sdk.develop.ErrorAnalysis(provenance, error_analysis_run_uid)
Bases:
object
This class provides methods for creating, monitoring, and retrieving results from error analysis clustering runs. The clustering algorithm identifies patterns in LLM evaluation failures and groups similar errors together.
Parameters
Parameters
Name Type Default Info provenance Dict[str, int]
Tracking information containing the benchmark_uid and criteria_uid that uniquely identifies the inputs used to create this cluster analysis. error_analysis_run_uid int
Unique identifier for this specific error analysis run. - __init__(provenance, error_analysis_run_uid)
Initialize an ErrorAnalysis instance.
Parameters
Parameters
Name Type Default Info provenance Dict[str, int]
Tracking information that uniquely identifies the inputs used to create this cluster analysis. error_analysis_run_uid int
Unique identifier for this specific cluster analysis run.
\_\_init\_\_
__init__
Methods
__init__
(provenance, error_analysis_run_uid)Initialize an ErrorAnalysis instance. create
(prompt_execution_uid, *[, sync])Create and trigger error analysis clustering job for LLM evaluation results. delete
()Delete this error analysis run and all associated cluster data. get
(error_analysis_run_uid)Retrieve an existing error analysis by its unique run identifier. get_cluster_membership
(cluster_uid)Fetch datapoint membership for a specific cluster. get_clusters
()Fetch clusters from a completed error analysis. get_latest
(prompt_execution_uid)Get the most recent error analysis run for a specific prompt execution. - classmethod create(prompt_execution_uid, *, sync=False)
Create and trigger error analysis clustering job for LLM evaluation results.
Parameters
Parameters
Returns
Returns
An ErrorAnalysis instance representing the clustering job. If sync = False, get_clusters will fail until analysis is complete. If sync = True, results are immediately available.
Return type
Return type
Raises
Raises
ValueError – If benchmark, prompt execution or criteria don’t exist or are not valid
ValueError – If prompt execution has no evaluation results or insufficient error cases to cluster
Name Type Default Info prompt_execution_uid int
Unique identifier of the prompt execution. sync bool
False
If True, method blocks until clustering completes and returns ready ErrorAnalysis. If False, returns immediately with ErrorAnalysis that requires waiting to get clusters. Examples
Create error analysis asynchronously:
>>> error_analysis = ErrorAnalysis.create(
... prompt_execution_uid=456,
... sync=False
... )Create error analysis synchronously:
>>> error_analysis = ErrorAnalysis.create(
... prompt_execution_uid=456,
... sync=True
... )
create
create
- delete()
Delete this error analysis run and all associated cluster data.
Raises
Raises
ValueError – If the error analysis run has already been deleted or does not exist
Return type
Return type
None
Example
>>> error_analysis = ErrorAnalysis.get(error_analysis_run_uid=42)
>>> error_analysis.delete()
delete
delete
- classmethod get(error_analysis_run_uid)
Retrieve an existing error analysis by its unique run identifier.
Parameters
Parameters
Returns
Returns
The ErrorAnalysis instance for the specified run, ready for status checks and results retrieval
Return type
Return type
Raises
Raises
ValueError – If no error analysis run exists with the given ID
Name Type Default Info error_analysis_run_uid int
The unique identifier of the error analysis run to retrieve. Example
>>> error_analysis = ErrorAnalysis.get(error_analysis_run_uid=42)
get
get
- get_cluster_membership(cluster_uid)
Fetch datapoint membership for a specific cluster.
Parameters
Parameters
Returns
Returns
DataFrame containing all the datapoints in the cluster with columns: - datapoint_uid: int - … (additional columns as available)
Return type
Return type
pd.DataFrame
Raises
Raises
ValueError – If cluster uid does not exist
Name Type Default Info cluster_uid int
Unique identifier of the cluster to get membership for. Example
>>> clusters = error_analysis.get_clusters()
>>> cluster_uid = clusters[0]['cluster_uid']
>>> membership_df = error_analysis.get_cluster_membership(cluster_uid)
get\_cluster\_membership
get_cluster_membership
- get_clusters()
Fetch clusters from a completed error analysis.
Returns
Returns
List of cluster dictionaries, each containing: - cluster_uid: int - name: str - description: str - improvement_strategy: str - examples: List[str] - datapoint_count: int
Return type
Return type
List[Dict[str, Any]]
Raises
Raises
RuntimeError – If called before analysis is complete
ValueError – If analysis failed or was deleted
Examples
Get clusters from error analysis:
>>> clusters = analysis.get_clusters()
get\_clusters
get_clusters
- classmethod get_latest(prompt_execution_uid)
Get the most recent error analysis run for a specific prompt execution.
Parameters
Parameters
Returns
Returns
The most recent ErrorAnalysis for the prompt execution or None if no error analysis has been run for this prompt execution
Return type
Return type
ErrorAnalysis or None
Raises
Raises
ValueError – If prompt execution does not exist
Name Type Default Info prompt_execution_uid int
The unique identifier of the prompt execution. Example
>>> latest_analysis = ErrorAnalysis.get_latest(
... prompt_execution_uid=456
... )
get\_latest
get_latest