Skip to content

Errors

openai_model_registry.errors

Error types for the OpenAI model registry.

This module defines the error types used by the model registry for various validation and compatibility issues.

Classes

ConfigFileNotFoundError

Bases: ConfigurationError

Raised when a required configuration file is not found.

Examples:

>>> try:
...     registry._load_config()
... except ConfigFileNotFoundError as e:
...     print(f"Config file not found: {e.path}")
Source code in src/openai_model_registry/errors.py
38
39
40
41
42
43
44
45
46
47
48
class ConfigFileNotFoundError(ConfigurationError):
    """Raised when a required configuration file is not found.

    Examples:
        >>> try:
        ...     registry._load_config()
        ... except ConfigFileNotFoundError as e:
        ...     print(f"Config file not found: {e.path}")
    """

    pass

ConfigurationError

Bases: ModelRegistryError

Base class for configuration-related errors.

This is raised for errors related to configuration loading, parsing, or validation.

Source code in src/openai_model_registry/errors.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class ConfigurationError(ModelRegistryError):
    """Base class for configuration-related errors.

    This is raised for errors related to configuration loading, parsing,
    or validation.
    """

    def __init__(self, message: str, path: Optional[str] = None) -> None:
        """Initialize configuration error.

        Args:
            message: Error message
            path: Optional path to the configuration file that caused the error
        """
        super().__init__(message)
        self.message = message
        self.path = path
Functions
__init__(message, path=None)

Initialize configuration error.

Parameters:

Name Type Description Default
message str

Error message

required
path Optional[str]

Optional path to the configuration file that caused the error

None
Source code in src/openai_model_registry/errors.py
26
27
28
29
30
31
32
33
34
35
def __init__(self, message: str, path: Optional[str] = None) -> None:
    """Initialize configuration error.

    Args:
        message: Error message
        path: Optional path to the configuration file that caused the error
    """
    super().__init__(message)
    self.message = message
    self.path = path

ConstraintNotFoundError

Bases: ModelRegistryError

Raised when a constraint reference cannot be found.

Examples:

>>> try:
...     registry.get_parameter_constraint("unknown.constraint")
... except ConstraintNotFoundError as e:
...     print(f"Constraint not found: {e.ref}")
Source code in src/openai_model_registry/errors.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
class ConstraintNotFoundError(ModelRegistryError):
    """Raised when a constraint reference cannot be found.

    Examples:
        >>> try:
        ...     registry.get_parameter_constraint("unknown.constraint")
        ... except ConstraintNotFoundError as e:
        ...     print(f"Constraint not found: {e.ref}")
    """

    def __init__(self, message: str, ref: str) -> None:
        """Initialize constraint not found error.

        Args:
            message: Error message
            ref: The constraint reference that wasn't found
        """
        super().__init__(message)
        self.message = message
        self.ref = ref
Functions
__init__(message, ref)

Initialize constraint not found error.

Parameters:

Name Type Description Default
message str

Error message

required
ref str

The constraint reference that wasn't found

required
Source code in src/openai_model_registry/errors.py
263
264
265
266
267
268
269
270
271
272
def __init__(self, message: str, ref: str) -> None:
    """Initialize constraint not found error.

    Args:
        message: Error message
        ref: The constraint reference that wasn't found
    """
    super().__init__(message)
    self.message = message
    self.ref = ref

ConstraintViolation

Bases: ParameterValidationError

Raised when a parameter value violates a constraint.

Examples:

>>> try:
...     registry.validate_parameter("temperature", 3.0, "gpt-4o")
... except ConstraintViolation as e:
...     print(f"Constraint violated: {e.param} must {e.rule}")
Source code in src/openai_model_registry/errors.py
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
class ConstraintViolation(ParameterValidationError):
    """Raised when a parameter value violates a constraint.

    Examples:
        >>> try:
        ...     registry.validate_parameter("temperature", 3.0, "gpt-4o")
        ... except ConstraintViolation as e:
        ...     print(f"Constraint violated: {e.param} must {e.rule}")
    """

    def __init__(
        self,
        param: str,
        value: Any,
        rule: str,
        provider: Optional[str] = None,
        model: Optional[str] = None,
    ) -> None:
        """Initialize constraint violation error.

        Args:
            param: Parameter name that violated the constraint
            value: The invalid value
            rule: Description of the constraint rule
            provider: Provider name (optional)
            model: Model name (optional)
        """
        provider_msg = f" on provider '{provider}'" if provider else ""
        message = f"{param} must {rule} (got {value}){provider_msg}"
        super().__init__(message, param, value, model)
        self.param = param
        self.value = value
        self.rule = rule
        self.provider = provider
Functions
__init__(param, value, rule, provider=None, model=None)

Initialize constraint violation error.

Parameters:

Name Type Description Default
param str

Parameter name that violated the constraint

required
value Any

The invalid value

required
rule str

Description of the constraint rule

required
provider Optional[str]

Provider name (optional)

None
model Optional[str]

Model name (optional)

None
Source code in src/openai_model_registry/errors.py
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def __init__(
    self,
    param: str,
    value: Any,
    rule: str,
    provider: Optional[str] = None,
    model: Optional[str] = None,
) -> None:
    """Initialize constraint violation error.

    Args:
        param: Parameter name that violated the constraint
        value: The invalid value
        rule: Description of the constraint rule
        provider: Provider name (optional)
        model: Model name (optional)
    """
    provider_msg = f" on provider '{provider}'" if provider else ""
    message = f"{param} must {rule} (got {value}){provider_msg}"
    super().__init__(message, param, value, model)
    self.param = param
    self.value = value
    self.rule = rule
    self.provider = provider

InvalidConfigFormatError

Bases: ConfigurationError

Raised when a configuration file has an invalid format.

Examples:

>>> try:
...     registry._load_config()
... except InvalidConfigFormatError as e:
...     print(f"Invalid config format: {e}")
Source code in src/openai_model_registry/errors.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class InvalidConfigFormatError(ConfigurationError):
    """Raised when a configuration file has an invalid format.

    Examples:
        >>> try:
        ...     registry._load_config()
        ... except InvalidConfigFormatError as e:
        ...     print(f"Invalid config format: {e}")
    """

    def __init__(
        self,
        message: str,
        path: Optional[str] = None,
        expected_type: str = "dict",
    ) -> None:
        """Initialize invalid format error.

        Args:
            message: Error message
            path: Optional path to the configuration file
            expected_type: Expected type of the configuration
        """
        super().__init__(message, path)
        self.expected_type = expected_type
Functions
__init__(message, path=None, expected_type='dict')

Initialize invalid format error.

Parameters:

Name Type Description Default
message str

Error message

required
path Optional[str]

Optional path to the configuration file

None
expected_type str

Expected type of the configuration

'dict'
Source code in src/openai_model_registry/errors.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
def __init__(
    self,
    message: str,
    path: Optional[str] = None,
    expected_type: str = "dict",
) -> None:
    """Initialize invalid format error.

    Args:
        message: Error message
        path: Optional path to the configuration file
        expected_type: Expected type of the configuration
    """
    super().__init__(message, path)
    self.expected_type = expected_type

InvalidDateError

Bases: ModelVersionError

Raised when a model version has an invalid date format.

Examples:

>>> try:
...     ModelVersion.from_string("2024-13-01")
... except InvalidDateError as e:
...     print(f"Date format error: {e}")
Source code in src/openai_model_registry/errors.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
class InvalidDateError(ModelVersionError):
    """Raised when a model version has an invalid date format.

    Examples:
        >>> try:
        ...     ModelVersion.from_string("2024-13-01")
        ... except InvalidDateError as e:
        ...     print(f"Date format error: {e}")
    """

    def __init__(self, message: str) -> None:
        """Initialize invalid date error.

        Args:
            message: Error message explaining the date format issue
        """
        super().__init__(message)
        self.message = message
Functions
__init__(message)

Initialize invalid date error.

Parameters:

Name Type Description Default
message str

Error message explaining the date format issue

required
Source code in src/openai_model_registry/errors.py
 97
 98
 99
100
101
102
103
104
def __init__(self, message: str) -> None:
    """Initialize invalid date error.

    Args:
        message: Error message explaining the date format issue
    """
    super().__init__(message)
    self.message = message

ModelFormatError

Bases: ModelRegistryError

Raised when a model name has an invalid format.

Examples:

>>> try:
...     ModelVersion.parse_from_model("invalid-model-name")
... except ModelFormatError as e:
...     print(f"Invalid model format: {e.model}")
Source code in src/openai_model_registry/errors.py
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
class ModelFormatError(ModelRegistryError):
    """Raised when a model name has an invalid format.

    Examples:
        >>> try:
        ...     ModelVersion.parse_from_model("invalid-model-name")
        ... except ModelFormatError as e:
        ...     print(f"Invalid model format: {e.model}")
    """

    def __init__(self, message: str, model: str) -> None:
        """Initialize model format error.

        Args:
            message: Error message
            model: The invalid model name
        """
        super().__init__(message)
        self.message = message
        self.model = model
Functions
__init__(message, model)

Initialize model format error.

Parameters:

Name Type Description Default
message str

Error message

required
model str

The invalid model name

required
Source code in src/openai_model_registry/errors.py
117
118
119
120
121
122
123
124
125
126
def __init__(self, message: str, model: str) -> None:
    """Initialize model format error.

    Args:
        message: Error message
        model: The invalid model name
    """
    super().__init__(message)
    self.message = message
    self.model = model

ModelNotSupportedError

Bases: ModelRegistryError

Raised when a model is not supported by the registry.

This error indicates that the requested model is not in the registry of supported models. This is different from version-related errors, which indicate that the model exists but the specific version is invalid.

Examples:

>>> try:
...     registry.get_capabilities("unsupported-model")
... except ModelNotSupportedError as e:
...     print(f"Model {e.model} is not supported")
Source code in src/openai_model_registry/errors.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
class ModelNotSupportedError(ModelRegistryError):
    """Raised when a model is not supported by the registry.

    This error indicates that the requested model is not in the registry of
    supported models. This is different from version-related errors, which
    indicate that the model exists but the specific version is invalid.

    Examples:
        >>> try:
        ...     registry.get_capabilities("unsupported-model")
        ... except ModelNotSupportedError as e:
        ...     print(f"Model {e.model} is not supported")
    """

    def __init__(
        self,
        message: str,
        model: Optional[str] = None,
        available_models: Optional[Union[List[str], Set[str], Dict[str, Any]]] = None,
    ) -> None:
        """Initialize model not supported error.

        Args:
            message: Error message
            model: The unsupported model name
            available_models: List of available models (optional)
        """
        super().__init__(message)
        self.model = model
        self.message = message
        # Convert other collection types to list for consistency
        if available_models is not None:
            if isinstance(available_models, dict):
                self.available_models: Optional[List[str]] = list(available_models.keys())
            elif isinstance(available_models, set):
                self.available_models = list(available_models)
            else:
                self.available_models = available_models
        else:
            self.available_models = None

    def __str__(self) -> str:
        """Return string representation of the error.

        Returns:
            Error message
        """
        return self.message
Functions
__init__(message, model=None, available_models=None)

Initialize model not supported error.

Parameters:

Name Type Description Default
message str

Error message

required
model Optional[str]

The unsupported model name

None
available_models Optional[Union[List[str], Set[str], Dict[str, Any]]]

List of available models (optional)

None
Source code in src/openai_model_registry/errors.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def __init__(
    self,
    message: str,
    model: Optional[str] = None,
    available_models: Optional[Union[List[str], Set[str], Dict[str, Any]]] = None,
) -> None:
    """Initialize model not supported error.

    Args:
        message: Error message
        model: The unsupported model name
        available_models: List of available models (optional)
    """
    super().__init__(message)
    self.model = model
    self.message = message
    # Convert other collection types to list for consistency
    if available_models is not None:
        if isinstance(available_models, dict):
            self.available_models: Optional[List[str]] = list(available_models.keys())
        elif isinstance(available_models, set):
            self.available_models = list(available_models)
        else:
            self.available_models = available_models
    else:
        self.available_models = None
__str__()

Return string representation of the error.

Returns:

Type Description
str

Error message

Source code in src/openai_model_registry/errors.py
203
204
205
206
207
208
209
def __str__(self) -> str:
    """Return string representation of the error.

    Returns:
        Error message
    """
    return self.message

ModelRegistryError

Bases: Exception

Base class for all registry-related errors.

This is the parent class for all registry-specific exceptions.

Source code in src/openai_model_registry/errors.py
10
11
12
13
14
15
16
class ModelRegistryError(Exception):
    """Base class for all registry-related errors.

    This is the parent class for all registry-specific exceptions.
    """

    pass

ModelVersionError

Bases: ModelRegistryError

Base class for version-related errors.

This is raised for any errors related to model versions.

Source code in src/openai_model_registry/errors.py
78
79
80
81
82
83
84
class ModelVersionError(ModelRegistryError):
    """Base class for version-related errors.

    This is raised for any errors related to model versions.
    """

    pass

NetworkError

Bases: ModelRegistryError

Raised when a network operation fails.

Examples:

>>> try:
...     registry.refresh_from_remote()
... except NetworkError as e:
...     print(f"Network error: {e}")
Source code in src/openai_model_registry/errors.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
class NetworkError(ModelRegistryError):
    """Raised when a network operation fails.

    Examples:
        >>> try:
        ...     registry.refresh_from_remote()
        ... except NetworkError as e:
        ...     print(f"Network error: {e}")
    """

    def __init__(self, message: str, url: Optional[str] = None) -> None:
        """Initialize network error.

        Args:
            message: Error message
            url: Optional URL that was being accessed
        """
        super().__init__(message)
        self.message = message
        self.url = url
Functions
__init__(message, url=None)

Initialize network error.

Parameters:

Name Type Description Default
message str

Error message

required
url Optional[str]

Optional URL that was being accessed

None
Source code in src/openai_model_registry/errors.py
336
337
338
339
340
341
342
343
344
345
def __init__(self, message: str, url: Optional[str] = None) -> None:
    """Initialize network error.

    Args:
        message: Error message
        url: Optional URL that was being accessed
    """
    super().__init__(message)
    self.message = message
    self.url = url

ParameterNotSupportedError

Bases: ParameterValidationError

Raised when a parameter is not supported for a model.

Examples:

>>> try:
...     capabilities.validate_parameter("unknown_param", "value")
... except ParameterNotSupportedError as e:
...     print(f"Parameter {e.param_name} not supported for {e.model}")
Source code in src/openai_model_registry/errors.py
240
241
242
243
244
245
246
247
248
249
250
class ParameterNotSupportedError(ParameterValidationError):
    """Raised when a parameter is not supported for a model.

    Examples:
        >>> try:
        ...     capabilities.validate_parameter("unknown_param", "value")
        ... except ParameterNotSupportedError as e:
        ...     print(f"Parameter {e.param_name} not supported for {e.model}")
    """

    pass

ParameterValidationError

Bases: ModelRegistryError

Base class for parameter validation errors.

This is raised for errors related to parameter validation.

Source code in src/openai_model_registry/errors.py
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
class ParameterValidationError(ModelRegistryError):
    """Base class for parameter validation errors.

    This is raised for errors related to parameter validation.
    """

    def __init__(
        self,
        message: str,
        param_name: str,
        value: Any,
        model: Optional[str] = None,
    ) -> None:
        """Initialize parameter validation error.

        Args:
            message: Error message
            param_name: The name of the parameter being validated
            value: The value that failed validation
            model: Optional model name for context
        """
        super().__init__(message)
        self.message = message
        self.param_name = param_name
        self.value = value
        self.model = model
Functions
__init__(message, param_name, value, model=None)

Initialize parameter validation error.

Parameters:

Name Type Description Default
message str

Error message

required
param_name str

The name of the parameter being validated

required
value Any

The value that failed validation

required
model Optional[str]

Optional model name for context

None
Source code in src/openai_model_registry/errors.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
def __init__(
    self,
    message: str,
    param_name: str,
    value: Any,
    model: Optional[str] = None,
) -> None:
    """Initialize parameter validation error.

    Args:
        message: Error message
        param_name: The name of the parameter being validated
        value: The value that failed validation
        model: Optional model name for context
    """
    super().__init__(message)
    self.message = message
    self.param_name = param_name
    self.value = value
    self.model = model

TokenParameterError

Bases: ParameterValidationError

Raised when there's an issue with token-related parameters.

This error is used for issues with max_tokens, completion_tokens, etc.

Examples:

>>> try:
...     capabilities.validate_parameter("max_completion_tokens", 100000)
... except TokenParameterError as e:
...     print(f"Token error: {e}")
Source code in src/openai_model_registry/errors.py
311
312
313
314
315
316
317
318
319
320
321
322
323
class TokenParameterError(ParameterValidationError):
    """Raised when there's an issue with token-related parameters.

    This error is used for issues with max_tokens, completion_tokens, etc.

    Examples:
        >>> try:
        ...     capabilities.validate_parameter("max_completion_tokens", 100000)
        ... except TokenParameterError as e:
        ...     print(f"Token error: {e}")
    """

    pass

VersionTooOldError

Bases: ModelVersionError

Raised when a model version is older than the minimum supported version.

Examples:

>>> try:
...     registry.get_capabilities("gpt-4o-2024-07-01")
... except VersionTooOldError as e:
...     print(f"Version error: {e}")
...     print(f"Try using the alias: {e.alias}")
Source code in src/openai_model_registry/errors.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
class VersionTooOldError(ModelVersionError):
    """Raised when a model version is older than the minimum supported version.

    Examples:
        >>> try:
        ...     registry.get_capabilities("gpt-4o-2024-07-01")
        ... except VersionTooOldError as e:
        ...     print(f"Version error: {e}")
        ...     print(f"Try using the alias: {e.alias}")
    """

    def __init__(
        self,
        message: str,
        model: str,
        min_version: str,
        alias: Optional[str] = None,
    ) -> None:
        """Initialize version too old error.

        Args:
            message: Error message
            model: The model that has a version too old
            min_version: The minimum supported version
            alias: Suggested alias to use instead (if available)
        """
        super().__init__(message)
        self.message = message
        self.model = model
        self.min_version = min_version
        self.alias = alias
Functions
__init__(message, model, min_version, alias=None)

Initialize version too old error.

Parameters:

Name Type Description Default
message str

Error message

required
model str

The model that has a version too old

required
min_version str

The minimum supported version

required
alias Optional[str]

Suggested alias to use instead (if available)

None
Source code in src/openai_model_registry/errors.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def __init__(
    self,
    message: str,
    model: str,
    min_version: str,
    alias: Optional[str] = None,
) -> None:
    """Initialize version too old error.

    Args:
        message: Error message
        model: The model that has a version too old
        min_version: The minimum supported version
        alias: Suggested alias to use instead (if available)
    """
    super().__init__(message)
    self.message = message
    self.model = model
    self.min_version = min_version
    self.alias = alias