Skip to content

Parse HookToolset :param descriptions by indentation - #76701

Merged
kaxil merged 3 commits into
apache:mainfrom
aarmens702-hub:hooktoolset-param-docs
Nov 9, 2026
Merged

kaxil merged 3 commits into
apache:mainfrom
aarmens702-hub:hooktoolset-param-docs

Conversation

@aarmens702-hub

Copy link
Copy Markdown
Contributor

Human Summary

HookToolset builds the tool descriptions it sends to the LLM from hook docstrings, and some parameter descriptions come out wrong in three ways:

  • The last parameter takes in all the text after it. In the docs’ own S3 example, one parameter ends up 601 characters long and includes a code block.
  • A :class: reference that wraps onto the next line cuts the description off mid-sentence, leaving just “Either a”.
  • A parameter with no description picks up the next field instead, like :return:.

As a result, the model gets wrong or noisy parameter descriptions. This change parses the docstrings the way reStructuredText does: a description keeps going as long as the next lines are indented deeper. It changes 61 of the 1,690 hook-method descriptions, and I checked each one.

AI Summary

Click here

HookToolset builds each tool's parameter descriptions from the hook method's :param docs, using a regex that runs until the next line starting with : or the end of the docstring. That goes wrong in three ways:

  • The last parameter absorbs everything after it. In S3Hook.list_keys (the example in the HookToolset docs), apply_wildcard gets a 601-character description that includes an example and a code block. FTPHook.retrieve_file gives block_size 850 characters.
  • A continuation line starting with a role cuts the description short. In BigQueryHook.create_routine, routine is described only as "The routine to create. Either a", because the next line starts with :class:.
  • A parameter with no description takes the next field. For example, a :return: line becomes the parameter's description.

This follows how reStructuredText field lists work instead: a description continues while lines are indented deeper than its :param line, and empty descriptions are left out.

Across all 1,690 provider hook methods with :param docs, 61 descriptions change: 23 are trimmed, 27 are completed and 11 empty ones are dropped. I read through the changed ones.

Tests: three new cases in TestParseParamDocs (trailing text after the last param, a continuation line starting with a role, and a param without a description). All three fail on main and pass here. The full test_hook.py passes (106 passed). The Google-style Args: branch is unchanged.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Code following the guidelines

HookToolset matched each :param description with a regex that ran until the
next line starting with ":" or the end of the docstring. So the last
parameter absorbed everything after it (601 characters, including a code
block, for apply_wildcard in S3Hook.list_keys, the docs' own example), a
continuation line starting with a role such as :class: cut a description
short, and a parameter with no description took the next field as its own.

Follow reStructuredText field lists instead: a description continues while
lines are indented deeper than its :param line.

Generated-by: Claude Code following the guidelines
@himanshuchawla0807-gif

Copy link
Copy Markdown
Contributor

An empty Sphinx field can now suppress the Google-style fallback entirely. On bd208da, the following returns {}; the parent returns {"path": "Path to read."}:

doc = "Read records.\n\nArgs:\n    path: Path to read.\n\n:param undocumented:"
assert _parse_param_docs(doc) == {"path": "Path to read."}

The final line creates an entry in params, but the Sphinx return expression filters that entry out after the decision to skip fallback. Filtering empty descriptions before the if params decision restores the Google description and passes all five existing parser cases. I ran the exact parser function and test methods from Git in an isolated Python harness. Codex generated and ran this check.

An empty :param field still left an entry in params, so the Google-style
fallback was skipped and then the empty entry was filtered out, returning
nothing. Drop empty descriptions before deciding whether to fall back.

Reported by @himanshuchawla0807-gif.

Generated-by: Claude Code following the guidelines
@aarmens702-hub

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed on bd208da. Fixed in d7e1087: empty descriptions are now dropped before deciding whether to fall back to Args. I also added your docstring as a test. It fails before the fix and passes after.

…k line

GoogleDisplayVideo360Hook.erf_uri's entity_type continuation line sat at
the same indent as its :param line, so the field ended after the first
line, and partner_id was missing its colon. A scan of every provider hook
found no other docstring with either problem.

The new parser case covers a description whose second paragraph follows a
blank line, shaped like S3Hook.copy_object's source_bucket_key.

Generated-by: Claude Code following the guidelines
@kaxil
kaxil enabled auto-merge (squash) November 9, 2026 18:39
@kaxil
kaxil merged commit d26160d into apache:main Nov 9, 2026
84 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.

3 participants