lmstudio-ai / lmstudio-ai/lmstudio-python
Define meaningful `LMStudioPredictionError` subclasses
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 875
- Forks
- 166
- PR merge metrics
- No merged PRs in 30d
Description
`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`
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing LMStudioPredictionError definition and the six prediction and tool-call handling paths described in the issue. Trace how server messages, invalid tool requests, and failed tool calls are currently surfaced, then implement and verify the proposed exception hierarchy and structured context for each mapped case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100