ollama-python icon indicating copy to clipboard operation
ollama-python copied to clipboard

RequestError is documented in four methods but never raised

Open Uneadlight opened this issue 1 month ago • 1 comments

What

Four docstrings in ollama/_client.py promise a RequestError:

  • Client.generate — line 278
  • Client.chat — line 385
  • AsyncClient.generate — line 938
  • AsyncClient.chat — line 1044
"""
Create a response using the requested model.

Raises `RequestError` if a model is not provided.
Raises `ResponseError` if the request could not be fulfilled.
...
"""

But searching the package finds no raise RequestError anywhere:

_client.py:278 / 385 / 938 / 1044   -> docstrings only
_types.py:696                        -> class definition
__init__.py:13 / 47                  -> export

What actually happens

client.generate(model='') builds GenerateRequest(model=''), which validates fine (model: str accepts the empty string), sends {"model": ""} to the server, gets a 400 back, and the client raises ResponseError.

So code written to the docstring never catches anything:

try:
    client.generate(model='')
except RequestError:      # unreachable
    ...

Why I am opening an issue instead of a PR

There are two reasonable fixes and I do not want to pick one for you:

  1. Make it real — validate locally and raise RequestError('model is required') before sending. This changes behaviour: the call no longer reaches the network, and callers catching ResponseError would need to add RequestError.
  2. Make the docs true — delete the Raises RequestError line from the four docstrings, since ResponseError already covers the failure.

Option 1 matches the docstrings. Option 2 matches the current design. Either is fine by me; I will send a PR for whichever you prefer.

Happy to also add a regression test in tests/test_client.py that pins the chosen behaviour.

Uneadlight avatar Oct 31 '26 07:10 Uneadlight

Hi! I'd like to pick this up. I'd go with option 2 (remove the Raises RequestError line from the four docstrings), since it matches current behavior and doesn't change what callers catch. If you'd rather have option 1 (validate locally and raise RequestError), I can do that with a test instead. Which do you prefer?

suhailult777 avatar Nov 02 '26 20:11 suhailult777