Skip to main content
Version: 2.0

A Quick Guide to Error Handling in the Vectara Python SDK

When using the Vectara Python SDK, errors can occur at three distinct stages of an API call. Understanding these stages helps in writing robust code that can handle failures gracefully.

  1. Client-Side Validation Errors: These happen before any request is sent to Vectara's servers. They are caused by providing incorrect data types or missing required information.
  2. Network and Transport Errors: These occur if the SDK cannot communicate with Vectara's API endpoints due to network problems like timeouts or connectivity issues.
  3. Vectara API Errors: These are returned by Vectara's servers when a request is successfully received but cannot be processed due to issues like an invalid API key, insufficient permissions, or a malformed query.

Client-Side validation errors (pydantic.ValidationError)

The SDK uses Pydantic to validate your inputs before sending them. If you provide data of the wrong type (e.g., a string instead of a number) or omit a required field, a ValidationError is raised.

INCORRECT DATA TYPE
1

Network and transport errors (httpx Exceptions)

The SDK uses the httpx library for network communication. Any network-level failure, such as a request timeout or a connection error, will raise an httpx exception. The most common ones to handle are
httpx.TimeoutException and httpx.ConnectError.

HANDLING A REQUEST TIMEOUT
1

Vectara API errors (vectara.ApiError)

If your request is successfully sent to Vectara but is rejected by the API for a specific reason (e.g., invalid credentials, resource not found), the SDK will raise an ApiError. This exception contains the HTTP
status_code and the body of the error response from the server, which are crucial for debugging.

HANDLING AN INVALID API KEY
1