Skip to content

Commit

Permalink
Add custom exception class and helper classes for promptflow-evals (#…
Browse files Browse the repository at this point in the history
…3658)

# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution
guidelines](https://github.com/microsoft/promptflow/blob/main/CONTRIBUTING.md).**
- [ ] **I confirm that all new dependencies are compatible with the MIT
license.**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
diondrapeck authored Aug 19, 2024
1 parent 51aef6f commit 718a2c0
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/promptflow-evals/promptflow/evals/_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
"""This includes enums and classes for exceptions for use in promptflow-evals."""

from enum import Enum

from azure.core.exceptions import AzureError


class ErrorCategory(Enum):
"""Error category to be specified when using PromptflowEvalsException class.
When using PromptflowEvalsException, specify the type that best describes the nature of the error being captured.
* INVALID_VALUE -> One or more inputs are invalid (e.g. incorrect type or format)
* UNKNOWN_FIELD -> A least one unrecognized parameter is specified
* MISSING_FIELD -> At least one required parameter is missing
* FILE_OR_FOLDER_NOT_FOUND -> One or more files or folder paths do not exist
* RESOURCE_NOT_FOUND -> Resource could not be found
* FAILED_EXECUTION -> Execution failed
* UNKNOWN -> Undefined placeholder. Avoid using.
"""

INVALID_VALUE = "INVALID VALUE"
UNKNOWN_FIELD = "UNKNOWN FIELD"
MISSING_FIELD = "MISSING FIELD"
FILE_OR_FOLDER_NOT_FOUND = "FILE OR FOLDER NOT FOUND"
RESOURCE_NOT_FOUND = "RESOURCE NOT FOUND"
FAILED_EXECUTION = "FAILED_EXECUTION"
UNKNOWN = "UNKNOWN"


class ErrorBlame(Enum):
"""Source of blame to be specified when using PromptflowEvalsException class.
When using PromptflowEvalsException, specify whether the error is due to user actions or the system.
"""

USER_ERROR = "UserError"
SYSTEM_ERROR = "SystemError"
UNKNOWN = "Unknown"


class ErrorTarget(Enum):
"""Error target to be specified when using PromptflowEvalsException class.
When using PromptflowEvalsException, specify the code are that was being targeted when the
exception was triggered.
"""

UNKNOWN = "Unknown"


class PromptflowEvalsException(AzureError):
"""The base class for all exceptions raised in promptflow-evals. If there is a need to define a custom
exception type, that custom exception type should extend from this class.
:param message: A message describing the error. This is the error message the user will see.
:type message: str
:param internal_message: The error message without any personal data. This will be pushed to telemetry logs.
:type internal_message: str
:param target: The name of the element that caused the exception to be thrown.
:type target: ~promptflow.evals._exceptions.ErrorTarget
:param error_category: The error category, defaults to Unknown.
:type error_category: ~promptflow.evals._exceptionsErrorCategory
:param error: The original exception if any.
:type error: Exception
"""

def __init__(
self,
message: str,
internal_message: str,
*args,
target: ErrorTarget = ErrorTarget.UNKNOWN,
category: ErrorCategory = ErrorCategory.UNKNOWN,
blame: ErrorBlame = ErrorBlame.UNKNOWN,
**kwargs,
) -> None:
self.category = category
self.target = target
self.blame = blame
self.internal_message = internal_message
super().__init__(message, *args, **kwargs)

0 comments on commit 718a2c0

Please sign in to comment.