Repository navigation
fix(response): don't use a standard-library type's docstring as the schema description - #3707
Open
BichengWang wants to merge 1 commit into
Open
BichengWang wants to merge 1 commit into
BichengWang wants to merge 1 commit into
Conversation
…chema description
Codecov Report✅ All modified and coverable lines are covered by tests.
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Why are these changes needed?
ResponseSchemafalls back to the type's__doc__when no description is given. For standard-library types that docstring describes the type, not the response, and it is sent to the provider as the schema description:The same happens for
bool,float,list[str],dict[str, int],set[int],datetime.date,Decimal,UUID, and unions (int | stryields "Represent a union type\n\nE.g. for int | str"). The OpenAI, Bedrock, DashScope and Mistral mappers all forwardresponse.description, so every request with such aresponse_schemacarries this text.This change reads the docstring only when the type is not defined in the standard library. User-defined models, dataclasses, TypedDicts and enums behave as before, and an explicit
description=still wins.Two existing tests asserted the leaked docstring (
"description": type_.__doc__forint/float/boolin the OpenAI and DashScope mapper tests); they now assert the key is absent.Related issue number
None.
Checks
AI assistance
Validation run (offline): new tests in test/response/test_schema.py fail before the fix (6 failed) and pass after;
pytest test/response test/config test/providers test/test_usage.py test/agent-> 1983 passed, 365 skipped, 1 xfailed (test_gemini_integration.py ignored: needs redis, not installed);ruff checkandruff format --checkclean;mypy==2.4.0 ag2/response/schema.py test/response/test_schema.py-> no issues.