Map every `MistralError` from the Mistral SDK to `ModelHTTPError` or `ModelAPIError`

Merged
DO
2mo ago
+66-4

Found while auditing how each provider adapter maps SDK errors (related: #8722).

MistralModel's _map_api_errors caught only SDKError, but the Mistral SDK raises two other MistralError subclasses from the same calls:

  • HTTPValidationError for a 422, on both request and request_stream
  • ResponseValidationError for a 200 body it can't parse

Both escaped Agent.run() raw, so except ModelHTTPError / except ModelAPIError missed them and FallbackModel's default fallback_on=(ModelAPIError,) never fell back. The mapper now catches the SDK base class: a 4xx/5xx still becomes ModelHTTPError with the real status, body and headers, and anything else becomes ModelAPIError, both chained from the SDK error.

New public surface: none.

Verification

  • tests/models/test_mistral.py::test_model_validation_error_raises_model_http_error[request] and [stream]: a 422 surfaces as ModelHTTPError(422) with body and headers, __cause__ is HTTPValidationError.
  • tests/models/test_mistral.py::test_model_unparseable_response_body_raises_model_api_error: a blank 200 body surfaces as ModelAPIError, __cause__ is ResponseValidationError.
  • All three fail with the raw SDK error when the fix is reverted.

What changes for existing users: a Mistral 422 or unparseable 200 now raises ModelHTTPError / ModelAPIError instead of the raw SDK exception. Other errors are unaffected.

Not changed here: connection errors and timeouts still escape as raw httpx2 errors from MistralModel, as they do from several other adapters; that is a separate cross-provider fix.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
  • PR title is fit for the release changelog.

๐Ÿค– Generated with Claude Code