Skip to content

fix(types): serialize Tool parameters with the $defs alias on standalone model_dump - #793

Open
mafujahmedridoy22-commits wants to merge 1 commit into
ollama:mainfrom
mafujahmedridoy22-commits:fix/787-tool-model-dump-defs-alias
Open

mafujahmedridoy22-commits wants to merge 1 commit into
ollama:mainfrom
mafujahmedridoy22-commits:fix/787-tool-model-dump-defs-alias

Conversation

@mafujahmedridoy22-commits

Copy link
Copy Markdown

Fixes #787.

Tool.model_dump() serializes the $defs parameter alias as defs because pydantic emits by field name. While ChatRequest had a serializer that restored the alias, a standalone Tool dump (e.g. Tool.model_dump()) leaked defs.

A model_serializer on Tool.Function.Parameters now rewrites defs → $defs for every dump, so both standalone Tool and ChatRequest output the correct key.

Tests:

  • test_tool_standalone_defs_alias_restored
  • Updated test_function_with_only_description / test_function_with_only_description_with_args expectations to the correct $defs key.

pytest tests/test_type_serialization.py tests/test_utils.py → 29 passed; the only 2 failures are pre-existing and unrelated (image-path serialization on this platform).

This branch has not been deployed

No deployments
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.

Tool.model_dump() serializes the $defs parameter alias as 'defs' (nested-in-request dumps do not)

2 participants