ollama / ollama/ollama-python

ChatRequest.model_dump() crashes when a tool has no parameters or no function

Open Beginner friendly
#733 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
10.5k
Forks
1.2k
Avg merge
4m
Merged PRs (30d)
1

Description

Actual behavior

Serializing a ChatRequest whose tools lack parameters (or lack function entirely) raises PydanticSerializationError unless exclude_none=True is passed:

from ollama._types import ChatRequest, Tool

ChatRequest(model='m', tools=[Tool(function=Tool.Function(name='f'))]).model_dump()
# PydanticSerializationError: Error calling function `serialize_model`:
# TypeError: argument of type 'NoneType' is not iterable

ChatRequest(model='m', tools=[Tool()]).model_dump_json()
# same error

The wrap serializer in ChatRequest evaluates 'parameters' in tool['function'] and 'defs' in tool['function']['parameters'], which fails when function or parameters serialized as None.

Expected behavior

model_dump() / model_dump_json() succeed regardless of whether exclude_none is set; the defs$defs rename still applies when parameters is present.

Environment

  • ollama-python: main @ fa8509936be08809bd15ca90a371165eb9abeb50
  • pydantic 2.10.6, Python 3.11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ChatRequest wrap serializer in ollama._types and reproduce the two model_dump and model_dump_json examples from the issue. Check how serialized function and parameters values are handled when they are None. Done means both calls succeed with and without exclude_none, while the defs-to-$defs rename still works when parameters is present.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.