Skip to content

function_tool: a Google docstring with only an Args: section loses every parameter description (griffe re-runs cleandoc and dedents the parameter lines) #5298

Closed

Description

@ara-stock

Describe the bug

When a tool function's docstring has no summary line and only an Args: section, all parameter descriptions are dropped. The whole Args: block also ends up in the tool description, flattened. docs/tools.md says "Descriptions for each input are taken from the docstring of the function", and that doesn't happen for this shape.

This is the symptom PR #3795 tried to fix. That PR was closed because the added test should "pass unchanged on the PR's base". I ran that test verbatim against current main and it fails with the locked griffelib==2.0.1. It also fails with 2.3.0. Details are below, with the mechanism, since #3795 didn't explain it.

Debug information

  • Agents SDK version: main @ d3304cf (0.23.1)
  • Python version: 3.12.3
  • griffelib: 2.0.1 (as locked in uv.lock) and 2.3.0; the result is the same

Repro steps

from agents import function_tool

@function_tool
def get_weather(city: str, unit: str) -> str:
    """
    Args:
        city: The city to look up.
        unit: Either "c" or "f".
    """
    return "sunny"

print(repr(get_weather.description))
print(get_weather.params_json_schema["properties"])

Actual:

'Args:\ncity: The city to look up.\nunit: Either "c" or "f".'
{'city': {'title': 'City', 'type': 'string'}, 'unit': {'title': 'Unit', 'type': 'string'}}

Expected: description is None, and city / unit carry their descriptions. That is what you get once a summary line ("Get the weather.") is added above Args:.

The test from #3795, copied unchanged into a file and run against main d3304cf with griffelib 2.0.1:

FAILED test_pr3795.py::test_docstring_without_summary_keeps_param_descriptions
assert properties.get("a").get("description") == "the first argument"
  where {'title': 'A', 'type': 'integer'} = ...

Root cause

  1. generate_func_documentation takes inspect.getdoc(func), which cleans the docstring and drops the leading blank line:
    'Args:\n city: The city to look up.\n unit: Either "c" or "f".'
  2. griffe.Docstring(...) runs inspect.cleandoc() on that value again. cleandoc computes the common indent from every line except the first. Here that is only the indented parameter lines, so they are dedented to column 0:
    >>> from griffe import Docstring
    >>> Docstring("Args:\n    city: The city.\n    unit: The unit.").value
    'Args:\ncity: The city.\nunit: The unit.'
    >>> [s.kind.value for s in Docstring("Args:\n    city: The city.\n    unit: The unit.").parse("google")]
    ['text']
  3. The Google parser only accepts a section header when indented lines follow it. After step 2 none do, so the block is parsed as free text and becomes the description.

The closing comment on #3795 says cleandoc removes the added leading newline. It does, but only after it has used that newline as line 0. The indent is then computed over all the real lines, so nothing is dedented:

>>> [s.kind.value for s in Docstring("\nArgs:\n    city: The city.\n    unit: The unit.").parse("google")]
['parameters']

The bug doesn't show in the existing tests because they all have a summary line or another column-0 line, such as a Returns: section. Those make the common indent 0. _ensure_blank_line_before_google_sections skips index 0 on purpose, so it doesn't normalize this shape either.

Expected behavior

An Args:-only Google docstring yields the parameter descriptions and no description text. Either of these fixes it:

The test in #3795 works as the regression test as written.

Disclosure: found while auditing with AI tooling; reproduced locally on both griffelib versions with the commands above.

Activity

  1. nightcityblade commented on Oct 5, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a PR shortly.

  2. nightcityblade commented on Oct 5, 2026

    @nightcityblade

    I found the repository's contributor guide limits pull requests to collaborators, so I'm stepping back and leaving this available for maintainers or collaborators.

  3. jnohclee-rgb commented on Oct 5, 2026

    @jnohclee-rgb

    I independently reproduced this through public function_tool on main d3304cff56f1be2325d00e0f172534d613697f88 (SDK 0.23.1, griffelib 2.0.1, Python 3.14.7). Six docstring shapes were checked: Google Args-only and Args-only with wrapped parameter text lost parameter descriptions; Google with a summary, Google with Returns, NumPy Parameters-only, and Sphinx parameter-only retained them. Function bodies were never invoked, tracing was disabled, and no model/API request was made.

    This isolates the affected layout while preserving alternative parser controls. It does not establish behavior on other griffe/Python versions. The exact offline diagnostic is below.

    To run the diagnostic, save it under a scripts/ directory and create a sibling results/ directory. Use the dependency versions above and the pinned SDK source on PYTHONPATH.

    from pathlib import Path
    import json,importlib.metadata
    from agents import function_tool
    from agents import set_tracing_disabled
    set_tracing_disabled(True)
    CITY='The fictional city to look up.';UNIT='Either c or f.'
    rows=[]
    cases=[('google_args_only',f'Args:\n    city: {CITY}\n    unit: {UNIT}'),('google_summary',f'Look up fictional weather.\n\nArgs:\n    city: {CITY}\n    unit: {UNIT}'),('google_with_returns',f'Args:\n    city: {CITY}\n    unit: {UNIT}\n\nReturns:\n    A fictional forecast.'),('google_wrapped_parameter',f'Args:\n    city: The fictional city\n        to look up.\n    unit: {UNIT}'),('numpy_parameters_only',f'Parameters\n----------\ncity : str\n    {CITY}\nunit : str\n    {UNIT}'),('sphinx_parameters_only',f':param city: {CITY}\n:param unit: {UNIT}')]
    for name,doc in cases:
        def sample(city:str,unit:str)->str:return 'fictional'
        sample.__doc__=doc
        tool=function_tool(sample)
        params=tool.params_json_schema['properties']
        descriptions={k:v.get('description') for k,v in params.items()}
        rows.append({'case':name,'description':tool.description,'parameter_descriptions':descriptions,'both_present':all(descriptions.values())})
    assert not rows[0]['both_present'] and rows[1]['both_present'] and rows[2]['both_present']
    out={'sdk_version':importlib.metadata.version('openai-agents'),'griffelib_version':importlib.metadata.version('griffelib'),'rows':rows,'live_api_calls':0,'tool_bodies_called':0,'scope':'Actual public function_tool construction; no model or client run.'}
    (Path(__file__).resolve().parents[1]/'results/docstrings.json').write_text(json.dumps(out,indent=2)+'\n')
    print(json.dumps({'cases':len(rows),'missing_parameter_descriptions':[r['case'] for r in rows if not r['both_present']],'passing_controls':[r['case'] for r in rows if r['both_present']]}))

    Diagnostic assistance: prepared with Codex and independently executed against the pinned source; all inputs are fictional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions