[Bug] Pydantic tool schemas are named after the metaclass or the last docstring param, never the model (#1848) - #1870
Merged
kyegomez merged 1 commit intoAug 11, 2026
Conversation
…metaclass or the last docstring param]
|
Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the bug half of #1848 (the part the issue says to fix regardless of the dedup).
What
base_model_to_openai_functionemitted the wrong function name into the schema handed to the LLM. Two independent bugs compounded:swarms/tools/pydantic_to_json.py:58—name = type(pydantic_type).__name__.pydantic_typeis the class, not an instance, so this reads the metaclass:"ModelMetaclass".if (name := param.arg_name) in parameters["properties"]rebindsnameon every match, so whenever the model's docstring documents its fields, the emitted name becomes whichever parameter matched last.The second one masks the first, which is why this reads as "wrong name" rather than a constant. On a model with a documented docstring:
Strip the docstring params and it falls through to
ModelMetaclassinstead. Either way the model is told the tool has a name it does not have — and the name is what the LLM emits back to call it.This is not an internal helper: it is exported from
swarms.toolsand used bybase_tool.py(:281,:673), so it reaches real tool schemas.Fix
name = pydantic_type.__name__prop_nameinstead ofname, so attaching per-parameter descriptions can no longer overwrite the function name. Those descriptions still attach — asserted in the test.check_pydantic_name(:20-37): it has zero callers, is not exported fromswarms/tools/__init__.py, and carried the sametype(...)mistake, so leaving it there is a live copy of the bug waiting to be picked up.Deliberately out of scope
#1848 also covers the three-way duplication of pydantic→OpenAI schema conversion and the legacy
{"function_call": …, "functions": […]}envelope. Those change the shape callers receive; this PR does not touch them, so it stays reviewable on its own and safe to land first. Happy to take the consolidation separately.Test
Appended to
tests/tools/test_output_str_fix.py— no new file, it already owns this function. It uses a model whose docstring documents its fields, so it covers the walrus path (the one that actually fires in practice) and asserts the parameter descriptions survive.Red checks are the repo-wide pre-existing ones (
buildnever installs the package;test-main-featuresdies on Poetry 2.x--no-dev), both addressed in #1812.