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
TheClient 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
TheClient class is generic over four types:
ClientT- The native client type (e.g.,AsyncOpenAI,AsyncAnthropic)MessagesT- The native messages formatResponseT- The native response typeToolT- The native tool format
Constructor
Either a pre-configured native client instance or a
ClientConfig object to set up a new client.Example
Properties
client
Abstract Methods
Subclasses must implement the following methods:setup_client
ClientConfig.
Configuration object containing API keys, base URL, and other settings.
to_native_tool
Tool to the provider’s native tool format.
A Verifiers tool definition.
to_native_prompt
Messages to the provider’s native prompt format.
List of Verifiers message objects.
(native_messages, extra_kwargs) where extra_kwargs are additional parameters to pass to get_native_response.
get_native_response
The prompt in the provider’s native format.
Model identifier (e.g.,
"gpt-4", "claude-3-5-sonnet-20241022").Sampling parameters like temperature, max_tokens, etc.
Optional list of tools in the provider’s native format.
raise_from_native_response
ModelError if invalid.
The provider’s native response object.
ModelError subclasses like EmptyModelResponseError or InvalidModelResponseError.
from_native_response
Response.
The provider’s native response object.
Response object.
close
Public Methods
to_native_tools
List of Verifiers tool definitions, or None.
get_response
- Converts Verifiers messages to native format
- Converts Verifiers tools to native format
- Gets the native response
- Validates the response
- Converts back to Verifiers format
List of Verifiers message objects.
Model identifier.
Sampling parameters.
Optional list of Verifiers tool definitions.
Response object.
Raises:
- Authentication errors from the provider (re-raised)
ModelErrorfor other provider errors
Example
Error Handling
TheClient class catches and handles errors:
- Verifiers errors (
Errorsubclasses): Re-raised as-is - Authentication errors: Re-raised from the provider
- All other exceptions: Wrapped in
ModelError
See Also
- OpenAIChatCompletionsClient - OpenAI implementation
- AnthropicMessagesClient - Anthropic implementation
- ClientConfig - Client configuration type