scouter-types 0.25.0

Client and server contract for scouter
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
use pyo3::exceptions::PyRuntimeError;
use pyo3::pyclass::PyClassGuardError;
use pyo3::PyErr;
use pythonize::PythonizeError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum UtilError {
    #[error("Failed to get parent path")]
    GetParentPathError,

    #[error("Failed to create directory")]
    CreateDirectoryError,

    #[error("Failed to read to create path")]
    CreatePathError,

    #[error(transparent)]
    IoError(#[from] std::io::Error),

    #[error(transparent)]
    SerdeJsonError(#[from] serde_json::Error),
}

impl From<UtilError> for PyErr {
    fn from(err: UtilError) -> PyErr {
        let msg = err.to_string();
        PyRuntimeError::new_err(msg)
    }
}

#[derive(Error, Debug)]
pub enum TypeError {
    #[error("{0}")]
    Error(String),

    #[error("Start time must be before end time")]
    StartTimeError,

    #[error("Invalid schedule")]
    InvalidScheduleError,

    #[error("Invalid PSI threshold configuration")]
    InvalidPsiThresholdError,

    #[error("Invalid time interval for converting to start and end times")]
    InvalidTimeIntervalError,

    #[error("Invalid alert dispatch configuration")]
    InvalidDispatchConfigError,

    #[error("Invalid equal width binning method")]
    InvalidEqualWidthBinningMethodError,

    #[error("Missing space argument")]
    MissingSpaceError,

    #[error("Missing name argument")]
    MissingNameError,

    #[error("Missing version argument")]
    MissingVersionError,

    #[error("Missing uid argument")]
    MissingUidError,

    #[error("Missing alert_config argument")]
    MissingAlertConfigError,

    #[error("No metrics found")]
    NoMetricsError,

    #[error(transparent)]
    SerdeJsonError(#[from] serde_json::Error),

    #[error("Invalid number")]
    InvalidNumberError,

    #[error("Root must be an object")]
    RootMustBeObject,

    #[error("Unsupported type: {0}")]
    UnsupportedType(String),

    #[error("Failed to downcast Python object: {0}")]
    DowncastError(String),

    #[error("Invalid data type")]
    InvalidDataType,

    #[error("Missing value for string feature")]
    MissingStringValueError,

    #[error("{0}")]
    PyError(String),

    #[error(
        "Unsupported feature type. Feature must be an integer, float or string. Received: {0}"
    )]
    UnsupportedFeatureTypeError(String),

    #[error("Unsupported features type. Features must be a list of Feature instances or a dictionary of key value pairs. Received: {0}")]
    UnsupportedFeaturesTypeError(String),

    #[error("Unsupported metrics type. Metrics must be a list of Metric instances or a dictionary of key value pairs. Received: {0}")]
    UnsupportedMetricsTypeError(String),

    #[error("{0}")]
    InvalidParameterError(String),

    #[error("{0}")]
    InvalidBinCountError(String),

    #[error("{0}")]
    InvalidValueError(String),

    #[error("Empty Array Detected: {0}")]
    EmptyArrayError(String),

    #[error("Invalid binning strategy")]
    InvalidBinningStrategyError,

    #[error("Unsupported status. Status must be one of: All, Pending or Processed. Received: {0}")]
    InvalidStatusError(String),

    #[error("Failed to supply either input or response for the genai record")]
    MissingInputOrResponse,

    #[error("Invalid context type. Context must be a PyDict or a Pydantic BaseModel")]
    MustBeDictOrBaseModel,

    #[error("Failed to check if the context is a Pydantic BaseModel. Error: {0}")]
    FailedToCheckPydanticModel(String),

    #[error("Failed to import pydantic module. Error: {0}")]
    FailedToImportPydantic(String),

    #[error("Unsupported Python object type for conversion")]
    UnsupportedPyObjectType,

    #[error("Invalid dictionary key type. Dictionary keys must be strings, int, float or bool")]
    InvalidDictKeyType,

    #[error("Invalid compressions type")]
    InvalidCompressionTypeError,

    #[error("Invalid evaluation task type: {0}")]
    InvalidEvalType(String),

    #[error("Compression type not supported: {0}")]
    CompressionTypeNotSupported(String),

    #[error("Missing dependency: {0}")]
    MissingDependency(String),

    #[error("Expected a Python dict")]
    ExpectedPyDict,

    #[error("List contains an item that is neither AssertionTask nor LLMJudgeTask")]
    InvalidAssertionTaskType,

    #[error("{0}")]
    FailedToCreateProfile(String),

    #[error("Duplicate task IDs found in evaluation tasks")]
    DuplicateTaskIds,

    #[error("Key not found: {key}")]
    KeyNotFound { key: String },

    #[error("{0}")]
    InvalidLength(String),

    #[error(transparent)]
    FromHexError(#[from] hex::FromHexError),

    #[error(transparent)]
    StdIOError(#[from] std::io::Error),

    #[error(transparent)]
    SerdeYamlError(#[from] serde_yaml::Error),

    #[error("Array {index} out of bounds for length {length}")]
    IndexOutOfBounds { index: isize, length: usize },

    #[error("Expected an integer index or a slice")]
    IndexOrSliceExpected,

    #[error(transparent)]
    PotatoTypeError(#[from] potato_head::TypeError),
}

impl From<pythonize::PythonizeError> for TypeError {
    fn from(err: PythonizeError) -> Self {
        TypeError::PyError(err.to_string())
    }
}

impl<'a, 'py> From<pyo3::CastError<'a, 'py>> for TypeError {
    fn from(err: pyo3::CastError<'a, 'py>) -> Self {
        TypeError::DowncastError(err.to_string())
    }
}

impl From<TypeError> for PyErr {
    fn from(err: TypeError) -> PyErr {
        let msg = err.to_string();
        PyRuntimeError::new_err(msg)
    }
}

impl From<PyErr> for TypeError {
    fn from(err: PyErr) -> TypeError {
        TypeError::PyError(err.to_string())
    }
}

impl<'a, 'py> From<PyClassGuardError<'a, 'py>> for TypeError {
    fn from(err: PyClassGuardError<'a, 'py>) -> Self {
        TypeError::PyError(err.to_string())
    }
}

#[derive(Error, Debug)]
pub enum ContractError {
    #[error(transparent)]
    TypeError(#[from] TypeError),

    #[error("{0}")]
    PyError(String),
}

impl From<ContractError> for PyErr {
    fn from(err: ContractError) -> PyErr {
        let msg = err.to_string();
        PyRuntimeError::new_err(msg)
    }
}

impl From<PyErr> for ContractError {
    fn from(err: PyErr) -> ContractError {
        ContractError::PyError(err.to_string())
    }
}

#[derive(Error, Debug)]
pub enum RecordError {
    #[error("Unable to extract record into any known ServerRecord variant")]
    ExtractionError,

    #[error("No server records found")]
    EmptyServerRecordsError,

    #[error(transparent)]
    SerdeJsonError(#[from] serde_json::Error),

    #[error("Unexpected record type")]
    InvalidDriftTypeError,

    #[error("{0}")]
    PyError(String),

    #[error("Failed to supply either input or response for the genai record")]
    MissingInputOrResponse,

    #[error(transparent)]
    PotatoUtilError(#[from] potato_head::UtilError),

    #[error(transparent)]
    TypeError(#[from] TypeError),

    #[error("Invalid context type. Context must be dictionary or Pydantic BaseModel")]
    MustBeDictOrBaseModel,

    #[error("Failed to downcast Python object: {0}")]
    DowncastError(String),

    #[error("{0}")]
    SliceError(String),

    #[error(transparent)]
    FromHexError(#[from] hex::FromHexError),
}

impl<'a, 'py> From<pyo3::CastError<'a, 'py>> for RecordError {
    fn from(err: pyo3::CastError) -> Self {
        RecordError::DowncastError(err.to_string())
    }
}

impl From<pythonize::PythonizeError> for RecordError {
    fn from(err: PythonizeError) -> Self {
        RecordError::PyError(err.to_string())
    }
}

impl From<RecordError> for PyErr {
    fn from(err: RecordError) -> PyErr {
        let msg = err.to_string();
        PyRuntimeError::new_err(msg)
    }
}

impl From<PyErr> for RecordError {
    fn from(err: PyErr) -> RecordError {
        RecordError::PyError(err.to_string())
    }
}

impl<'a, 'py> From<PyClassGuardError<'a, 'py>> for RecordError {
    fn from(err: PyClassGuardError<'a, 'py>) -> Self {
        RecordError::PyError(err.to_string())
    }
}

#[derive(Error, Debug)]
pub enum ProfileError {
    #[error(transparent)]
    SerdeJsonError(#[from] serde_json::Error),

    #[error("Features and array are not the same length")]
    FeatureArrayLengthError,

    #[error("Unexpected record type")]
    InvalidDriftTypeError,

    #[error(transparent)]
    UtilError(#[from] UtilError),

    #[error(transparent)]
    TypeError(#[from] TypeError),

    #[error(transparent)]
    IoError(#[from] std::io::Error),

    #[error("Missing sample argument")]
    MissingSampleError,

    #[error("Missing sample size argument")]
    MissingSampleSizeError,

    #[error("Custom alert thresholds have not been set")]
    CustomThresholdNotSetError,

    #[error("Custom alert threshold not found")]
    CustomAlertThresholdNotFound,

    #[error("{0}")]
    PyError(String),

    #[error("Invalid binning strategy")]
    InvalidBinningStrategyError,

    #[error("Missing evaluation workflow")]
    MissingWorkflowError,

    #[error("Invalid argument for workflow. Argument must be a Workflow object")]
    InvalidWorkflowType,

    #[error(transparent)]
    AgentError(#[from] potato_head::AgentError),

    #[error(transparent)]
    WorkflowError(#[from] potato_head::WorkflowError),

    #[error("Invalid metric name found: {0}")]
    InvalidMetricNameError(String),

    #[error("No AssertionTasks or LLMJudgeTasks found in the workflow")]
    EmptyTaskList,

    #[error("LLM Metric requires at least one bound parameter")]
    NeedAtLeastOneBoundParameterError(String),

    #[error(
        "Missing prompt in LLM Metric. If providing a list of metrics, prompt must be present"
    )]
    MissingPromptError(String),

    #[error("No tasks found in the workflow when validating: {0}")]
    NoTasksFoundError(String),

    #[error("No metrics found for the output task: {0}")]
    MetricNotFoundForOutputTask(String),

    #[error("Metric not found in profile LLM metrics: {0}")]
    MetricNotFound(String),

    #[error(transparent)]
    PotatoTypeError(#[from] potato_head::TypeError),

    #[error("Invalid task type. Expected either AssertionTask or LLMJudgeTask: {0}")]
    InvalidTaskType(String),

    #[error("Detected circular dependency in evaluation tasks")]
    CircularDependency,
}

impl From<ProfileError> for PyErr {
    fn from(err: ProfileError) -> PyErr {
        let msg = err.to_string();
        PyRuntimeError::new_err(msg)
    }
}

impl From<PyErr> for ProfileError {
    fn from(err: PyErr) -> ProfileError {
        ProfileError::PyError(err.to_string())
    }
}

impl<'a, 'py> From<PyClassGuardError<'a, 'py>> for ProfileError {
    fn from(err: PyClassGuardError<'a, 'py>) -> Self {
        ProfileError::PyError(err.to_string())
    }
}

impl<'a, 'py> From<pyo3::CastError<'a, 'py>> for ProfileError {
    fn from(err: pyo3::CastError) -> Self {
        ProfileError::PyError(err.to_string())
    }
}