Skip to content

Normalize LM Studio exceptions - #1900

Open
Dikshj wants to merge 1 commit into
dottxt-ai:mainfrom
Dikshj:fix-lmstudio-provider-exceptions
Open

Normalize LM Studio exceptions#1900
Dikshj wants to merge 1 commit into
dottxt-ai:mainfrom
Dikshj:fix-lmstudio-provider-exceptions

Conversation

@Dikshj

@Dikshj Dikshj commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Thank you for opening a PR!

A few important guidelines and requirements before we can merge your PR:

  • We should be able to understand what the PR does from its title only;
  • There is a high-level description of the changes;
  • If I add a new feature, there is an issue discussing it already;
  • There are links to all the relevant issues, discussions and PRs;
  • The branch is rebased on the latest main commit;
  • Commit messages follow these guidelines;
  • One commit per logical change;
  • The code respects the current naming conventions;
  • Docstrings follow the numpy style guide;
  • pre-commit is installed and configured on your machine, and you ran it before opening the PR;
  • There are tests covering the changes;
  • The documentation is up-to-date;

Description

Follow-up to #1823 / #1658.

#1823 added the shared exception hierarchy and provider error normalization for most client-backed model wrappers. After that merge, LM Studio still appears to be missing from the provider normalization path: runtime transport failures can escape as raw exceptions from the LM Studio client.

This PR adds LM Studio to the shared provider exception mapping and wraps LM Studio sync and async client calls with normalize_provider_errors("lmstudio").

Changes

  • Map LM Studio ConnectionError failures to APIConnectionError.
  • Map LM Studio TimeoutError failures to APITimeoutError.
  • Continue using status-code fallback for provider errors that expose HTTP-like status codes, including rate limits.
  • Wrap sync and async LM Studio model lookup, generation, and streaming calls.
  • Preserve the original provider exception through original_exception and Python exception chaining.
  • Keep local validation and programmer errors, such as ValueError, passing through unchanged.

Compatibility

This keeps the existing LM Studio public API unchanged. It only standardizes provider/runtime failures under the existing Outlines exception hierarchy, while preserving the underlying exception for debugging.

Streaming is covered for both provider failures and early consumer cancellation. Since normalize_provider_errors catches Exception, GeneratorExit and other BaseException subclasses are not wrapped when a caller stops consuming a stream early.

Verification

  • pre-commit run --all-files
  • python -m pytest tests/test_exceptions.py -k lmstudio
  • python -m pytest tests/models/test_lmstudio.py

LM Studio was the remaining client-backed model wrapper that still let transport failures escape as raw runtime exceptions. Map common connection and timeout failures into the shared Outlines APIError hierarchy and wrap sync and async client calls so callers can catch the same exception types across providers.

The wrapper still lets local validation and programmer errors pass through unchanged. Stream tests also cover early consumer cancellation so GeneratorExit is not mistaken for a provider failure.
@Dikshj

Dikshj commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

This is a follow-up to #1823.

#1823 added the shared exception hierarchy and provider error normalization across Outlines, resolving the broader #1658 work. After that merge, LM Studio still appears to be missing from the provider normalization path: runtime transport failures can escape as raw ConnectionError / TimeoutError from the LM Studio client.

This PR does not replace #1823. It fills that LM Studio-specific gap by adding lmstudio to the existing provider exception map and wrapping LM Studio sync/async generation and streaming calls with normalize_provider_errors(" lmstudio).

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

📚 Documentation preview: https://dottxt-ai.github.io/outlines/pr-preview/pr-1900/

Preview updates automatically with each commit.

@RobinPicard RobinPicard left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea, but we need actual sdk error mapping to make it work and be useful. Right now the lmstudio handling in src/outlines/models/lmstudio.py is too light as it only covers generic Python errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants