Conversation
_parse_docstring treated every line in the Args section that contains a colon or a parenthesis as a new argument. An indented continuation line such as a URL or "YYYY-MM-DD (for example: 2024-01-31)" therefore ended the real argument's description early and created a phantom argument, so the tool schema sent to the model lost that part of the description. Treat lines indented deeper than the current argument as continuation lines, which is how Google-style docstrings wrap descriptions.
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.
When a function is passed as a tool, a wrapped argument description is cut short if a continuation line contains a colon or a parenthesis:
The schema that
chat(tools=[get_page])sends today:{"url": {"type": "string", "description": "Page to fetch, for example"}, "date": {"type": "string", "description": "Day to fetch, in the format"}}_parse_docstringstrips every line in theArgs:section and then treats any line with a:(or a(...)) as a new argument. The continuation lineshttps://example.com/docsandYYYY-MM-DD (for example: 2024-01-31)become phantom arguments namedhttpsandYYYY-MM-DD. The real descriptions stop at the line before, so the model never sees the URL example or the date format. Continuation lines without a colon already work, andtest_function_docstring_parsingcovers them.This change keeps each line's indentation for the
Args:section. A line indented deeper than the current argument's line is treated as a continuation, even if it contains a colon, which is how Google-style docstrings wrap descriptions. Lines at the argument's own indentation are parsed as before, so the existing parenthesis and skewed-docstring cases don't change.Verification
test_docstring_continuation_lines_with_colonsfails onmain('Page to fetch, for example') and passes with this change.Client.chat(tools=[get_page])with anhttpx.MockTransport: the request now carries"Page to fetch, for example https://example.com/docs"and"Day to fetch, in the format YYYY-MM-DD (for example: 2024-01-31)".pytest ollama testspasses (103 tests), andruff format --checkandruff checkare clean.