Skip to content

fix: preserve *args/**kwargs docstring descriptions in tool schemas - #3956

Merged
seratch merged 1 commit into
openai:mainfrom
TheSaiEaranti:fix-varargs-docstring-descriptions
Jul 25, 2026
Merged

fix: preserve *args/**kwargs docstring descriptions in tool schemas#3956
seratch merged 1 commit into
openai:mainfrom
TheSaiEaranti:fix-varargs-docstring-descriptions

Conversation

@TheSaiEaranti

Copy link
Copy Markdown
Contributor

Summary

Google and NumPy style docstrings write variadic parameters with their stars (*numbers:, **kwargs:), and griffe returns those names verbatim. generate_func_documentation keyed param_descriptions by that verbatim name, while function_schema looks descriptions up by the bare signature parameter name — so *args/**kwargs descriptions were silently dropped from the tool JSON schema for those two styles. Sphinx style (:param numbers:) has no stars and carried them through, and function_schema already plumbs the description into the VAR_POSITIONAL/VAR_KEYWORD Field(...) calls, so the loss was purely a key mismatch. griffe warnings are suppressed during parsing, which made it fully silent.

The fix strips the stars when building the description map (param.name.lstrip("*")). Python identifiers cannot begin with *, so this is a no-op for every non-variadic key.

Before, documenting the same function per each style's own convention behaved inconsistently:

google_style:   'numbers': None            'kwargs': None
numpy_style:    'numbers': None            'kwargs': None
sphinx_style:   'numbers': 'the numbers …' 'kwargs': 'extra options.'

After, all three styles carry the descriptions into params_json_schema.

Test plan

  • Added test_variadic_param_descriptions_preserved, parametrized over google/numpy/sphinx docstrings for the same (x, *numbers, **kwargs) function, asserting all three descriptions land in the schema properties. The google and numpy cases fail without the fix; sphinx passes before and after, pinning the consistency claim.
  • make format, make lint, make typecheck (mypy + pyright), and make tests all pass locally.

Issue number

None — found while reading function_schema.py.

Checks

  • I've added new tests, if relevant
  • I've run .agents/skills/code-change-verification/scripts/run.sh
  • I've confirmed all verification steps pass
  • If using Codex, I've run /review before submitting this PR

Google and NumPy style docstrings write variadic parameters with their stars
("*numbers:", "**kwargs:"), and griffe returns those names verbatim.
generate_func_documentation keyed param_descriptions by that verbatim name
while function_schema looks descriptions up by the bare signature parameter
name, so variadic parameter descriptions were silently dropped from the tool
JSON schema for those two styles. Sphinx style has no stars and carried them
through, and function_schema already plumbs the description into the
VAR_POSITIONAL and VAR_KEYWORD fields, so the loss was purely a key mismatch.

Strip the stars when building the description map and cover all three styles
with a parametrized regression test.
@seratch seratch added this to the 0.19.x milestone Jul 25, 2026
@seratch
seratch merged commit 99e88c1 into openai:main Jul 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants