Error Handling

Discover how to handle errors and exceptions in this section. It covers common error scenarios, how to catch and respond to errors, and best practices for ensuring robust and resilient code.

The Fi AI Client employs a robust error-handling mechanism, raising specific exceptions for different types of errors encountered during operation. This ensures that issues are clearly identified and can be addressed promptly, enhancing the reliability and maintainability of your integration. Below is a detailed explanation of each key exception and its usage:

1. AuthError

Description: Raised if the API key or secret key is missing or invalid. This error occurs when the client attempts to authenticate with the Fi AI service but fails due to incorrect or absent credentials.

from fi_client.exceptions import AuthError

try:
    client = Client(api_key=api_key, secret_key=secret_key, uri=base_url)
except AuthError as e:
    print(f"Authentication failed: {e}")

2. InvalidAdditionalHeaders

Description: Raised if there are conflicting or invalid additional headers. This error occurs when the client is initialized with additional headers that are either incorrectly formatted or conflict with required headers.

from fi_client.exceptions import InvalidAdditionalHeaders

try:
    client = Client(api_key=api_key, secret_key=secret_key, uri=base_url, additional_headers={"Invalid-Header": "value"})
except InvalidAdditionalHeaders as e:
    print(f"Invalid additional headers: {e}")

3. InvalidValueType

Description: Raised if a parameter has an invalid type. This error ensures that all provided parameters meet the expected data types, preventing issues during data processing and logging.

from fi_client.exceptions import InvalidValueType

tags = "This should be a dict"

try:
    client.log(model_id="model_id", model_type=ModelTypes.GENERATIVE_LLM, environment=Environments.PRODUCTION, tags=tags)
except InvalidValueType as e:
    print(f"Invalid value type: {e}")

4. InvalidSupportedType

Description: Raised if a model type is not supported. This error ensures that only valid model types are used, preventing issues related to unsupported model types.

from fi_client.exceptions import InvalidSupportedType

invalid_model_type = "UNSUPPORTED_MODEL"

try:
    client.log(model_id="model_id", model_type=invalid_model_type, environment=Environments.PRODUCTION)
except InvalidSupportedType as e:
    print(f"Invalid supported type: {e}")

5. MissingRequiredKey

Description: Raised if a required key is missing from the provided parameters. This error ensures that all necessary information is included, preventing incomplete data submissions.

from fi_client.exceptions import MissingRequiredKey

try:
    client.log(model_type=ModelTypes.GENERATIVE_LLM, environment=Environments.PRODUCTION)
except MissingRequiredKey as e:
    print(f"Missing required key: {e}")

6. InvalidVectorLength

Description: Raised if the vector length is invalid. This error ensures that any vector data provided meets the required length specifications, preventing issues during processing.

from fi_client.exceptions import InvalidVectorLength

invalid_vector = [1, 2, 3]  # Assuming the required length is different

try:
    client.log(model_id="model_id", model_type=ModelTypes.GENERATIVE_LLM, environment=Environments.PRODUCTION, embedding_vector=invalid_vector)
except InvalidVectorLength as e:
    print(f"Invalid vector length: {e}")

Summary

By raising specific exceptions for different types of errors, the Fi AI Client ensures that issues can be clearly identified and addressed promptly. This error-handling mechanism helps maintain the reliability and integrity of your integration, providing clear feedback and preventing common issues from causing major disruptions.

Last updated