Skip to content

Define meaningful LMStudioPredictionError subclasses #96

Description

@ncoghlan

LMStudioPredictionError is raised/reported in the following cases:

  • the server sends an "error" message on the prediction's streaming channel
  • the server sends a "toolCallGenerationFailed" message on the prediction's streaming channel
  • the server sends a tool request on the final round of an .act() call (when tool requests are disabled)
  • the server sends a tool request for an unknown tool name
  • the server sends a tool request for a known tool, but parsing the tool parameters fails
  • a valid tool call request raises an unhandled Python exception during execution

The first two are raised directly by the SDK, the last three are processed through the handle_invalid_tool_request callback (which defaults to sending them back to the LLM as text rather than raising them locally). The "tool call request when tool requests are disabled" handling is currently a hybrid of the two: handle_invalid_tool_request is invoked, but without any request details, and the exception is raised directly by the SDK (since the LLM interaction is complete, the invalid call can't be reported back to the LLM to fix)

Each of these could meaningfully report additional structured information:

  • the two server errors could report the triggering message from the server
  • the four tool call request errors could report the request that resulted in the error
  • tool calls with invalid args could report the tool details in addition to the tool call request
  • failed tool calls could report the raised exception (as __cause__), the parsed tool call args, and the tool details

Potential hierarchy:

- LMStudioPredictionError
  - LMStudioServerPredictionError
  - LMStudioToolCallError
    - LMStudioServerToolCallError  # Also inherits from LMStudioServerPredictionError
    - LMStudioToolCallInvalidError
      - LMStudioToolCallUnknownError
      - LMStudioToolCallInvalidArgsError
    - LMStudioToolCallFailedError # Has __cause__ set to the unhandled tool call exception

The 6 specific cases would then map to

  • server "error" message -> LMStudioServerPredictionError
  • server "toolCallGenerationFailed" message -> LMStudioServerToolCallError
  • unknown tool name -> LMStudioToolCallUnknownError
  • parsing the tool parameters fails -> LMStudioToolCallInvalidArgsError
  • tool request when tool requests are disabled -> LMStudioToolCallInvalidError (no dedicated subclass)
  • unhandled Python exception -> LMStudioToolCallFailedError

Activity

  1. added theissue type on Jun 10, 2025
  2. ArEnSc commented on Aug 15, 2025

    @ArEnSc
    Contributor

    @ncoghlan hey you guys still hiring for this role ? I was thinking of doing a few features to get a feel of what its like to work on this specific team before applying thanks

  3. ncoghlan commented on Aug 15, 2025

    @ncoghlan
    ContributorAuthor

    Aye, assuming you're referring to https://lmstudio.ai/careers?ashby_jid=3f8c9629-79e0-4c7a-8a88-241b636bb539, that's still open for applications.

    If you'd like to get an idea of my review style #136 is a previous attempt at this issue (I'd still be happy to review an independent attempt if you think this issue sounds interesting, though).

  4. ArEnSc commented on Aug 15, 2025

    @ArEnSc
    Contributor

    @ncoghlan thanks ill take a look

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions