Skip to content

fix: preserve function tool schema constraints - #718

Open
weivwang wants to merge 1 commit into
ollama:mainfrom
weivwang:fix/preserve-tool-schema-constraints
Open

fix: preserve function tool schema constraints#718
weivwang wants to merge 1 commit into
ollama:mainfrom
weivwang:fix/preserve-tool-schema-constraints

Conversation

@weivwang

Copy link
Copy Markdown

Summary

Preserve JSON Schema constraints generated for Python function parameters when converting callables into Ollama tools.

convert_function_to_tool currently replaces each property schema with only type and description. That drops constraints such as array items and Literal enum values, so models are not told what array elements or allowed values a tool accepts.

This change keeps the generated property fields, removes the superseded anyOf, and then applies the existing normalized type and docstring description behavior.

Testing

  • NO_PROXY=localhost,127.0.0.1 no_proxy=localhost,127.0.0.1 uv run --with pytest --with pytest-anyio --with pytest-httpserver pytest ollama tests -q (103 passed)
  • uv run --with ruff ruff check ollama tests
  • uv run --with ruff ruff format --check ollama tests
  • git diff --check

@weivwang
weivwang marked this pull request as ready for review August 13, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant