Skip to main content
The Client class is the abstract base class for all LLM provider implementations in Verifiers. It defines the interface for converting between Verifiers’ unified types and provider-specific formats.

Overview

The Client class is a generic abstract base class that handles:
  • Converting Verifiers messages to provider-native formats
  • Converting Verifiers tools to provider-native formats
  • Getting responses from LLM providers
  • Converting provider responses back to Verifiers format
  • Error handling and authentication

Type Parameters

The Client class is generic over four types:
  • ClientT - The native client type (e.g., AsyncOpenAI, AsyncAnthropic)
  • MessagesT - The native messages format
  • ResponseT - The native response type
  • ToolT - The native tool format

Constructor

ClientT | ClientConfig
required
Either a pre-configured native client instance or a ClientConfig object to set up a new client.

Example

Properties

client

Returns the underlying native client instance.

Abstract Methods

Subclasses must implement the following methods:

setup_client

Creates and configures the native client from a ClientConfig.
ClientConfig
required
Configuration object containing API keys, base URL, and other settings.
Returns: The configured native client instance.

to_native_tool

Converts a Verifiers Tool to the provider’s native tool format.
Tool
required
A Verifiers tool definition.
Returns: The tool in the provider’s native format.

to_native_prompt

Converts Verifiers Messages to the provider’s native prompt format.
Messages
required
List of Verifiers message objects.
Returns: A tuple of (native_messages, extra_kwargs) where extra_kwargs are additional parameters to pass to get_native_response.

get_native_response

Gets a response from the provider using their native API.
MessagesT
required
The prompt in the provider’s native format.
str
required
Model identifier (e.g., "gpt-4", "claude-3-5-sonnet-20241022").
SamplingArgs
required
Sampling parameters like temperature, max_tokens, etc.
list[ToolT] | None
default:"None"
Optional list of tools in the provider’s native format.
Returns: The provider’s native response object.

raise_from_native_response

Validates the native response and raises ModelError if invalid.
ResponseT
required
The provider’s native response object.
Raises: ModelError subclasses like EmptyModelResponseError or InvalidModelResponseError.

from_native_response

Converts the provider’s native response to a Verifiers Response.
ResponseT
required
The provider’s native response object.
Returns: A Verifiers Response object.

close

Closes the underlying client connection, if applicable.

Public Methods

to_native_tools

Converts a list of Verifiers tools to the provider’s native tool format.
list[Tool] | None
required
List of Verifiers tool definitions, or None.
Returns: List of tools in the provider’s native format, or None if input was None.

get_response

Main method to get a response from the LLM. Handles the full conversion pipeline:
  1. Converts Verifiers messages to native format
  2. Converts Verifiers tools to native format
  3. Gets the native response
  4. Validates the response
  5. Converts back to Verifiers format
Messages
required
List of Verifiers message objects.
str
required
Model identifier.
SamplingArgs
required
Sampling parameters.
list[Tool] | None
default:"None"
Optional list of Verifiers tool definitions.
Returns: A Verifiers Response object. Raises:
  • Authentication errors from the provider (re-raised)
  • ModelError for other provider errors

Example

Error Handling

The Client class catches and handles errors:
  • Verifiers errors (Error subclasses): Re-raised as-is
  • Authentication errors: Re-raised from the provider
  • All other exceptions: Wrapped in ModelError

See Also