Skip to content

Define meaningful LMStudioPredictionError subclasses #96

@ncoghlan

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

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