Skip to content

Conversation

@fahadAbulSudo
Copy link
Contributor

Description

This PR improves the behavior of the FunctionTool.from_defaults method by enhancing how function signatures are parsed and modified. Specifically:

  • Filters out FieldInfo defaults during signature extraction to avoid retaining internal metadata.
  • Ensures partial_params are correctly excluded from the final parameter list using a cleaner key not in dict approach.
  • Enhances the construction of docstring-based parameter descriptions by appending them directly into the enriched function description.
  • Includes associated unit test updates to verify correct parsing behavior.

Fixes #19506

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 25, 2025
@fahadAbulSudo
Copy link
Contributor Author

PR Ready for Review and Merge

  • This PR enhances the FunctionTool.from_defaults method with the following:
  • Automatic parameter docstring parsing from Sphinx, Google, and Javadoc styles.
  • Enriched description and fn_schema generation using the parsed docstrings.
  • Improved formatting of the description (summary line + param descriptions).
  • All test cases have passed.
  • Fully backward compatible — no breaking changes introduced.

Summary of Changes

  • Parsed docstrings now populate both the description and fn_schema.
  • Skips unknown or conflicting param descriptions.
  • Filters out self, context, and partial/default parameters from the generated schema.
  • Cleaned up handling of newlines in summary formatting.

Requesting review and merge. Let me know if anything further is needed!

@fahadAbulSudo
Copy link
Contributor Author

Hi @logan-markewich,
This PR is ready for review — all checks have passed and the updates align with recent changes to FunctionTool. Since you've reviewed similar PRs in the past and contributed to this area, your input would be very valuable.
Let me know if there’s anything you'd like me to adjust. Thanks in advance!

Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I would just augment the tests as per comment :))


def test_fn_schema_docstring_descriptions():
def sample_tool(a: int, b: Optional[str] = None) -> str:
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we test all the docstring styles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can we test with self and context?

Copy link
Contributor Author

@fahadAbulSudo fahadAbulSudo Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @AstraBert — makes sense!
I’ll augment the test to cover:

  • different docstring styles (e.g. Google-style, )
  • cases with self and context parameters

The current test covers a basic :param: style docstring — I’ll now add test variants to handle self, context, and alternate docstring formats. Thanks for the suggestion!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AstraBert,

Just a quick note regarding the CI status:

Some of the integration test failures appear to be unrelated to the changes in this PR:
llama-index-indices-managed-lancedb fails due to flaky picsum.photos requests (requests.get(...) returns a 525 SSL error).
llama-index-llms-nvidia-tensorrt, colbert-rerank, and colpali-rerank fail due to the unavailability of nvidia-cublas-cu12==12.6.4.1 on NVIDIA’s PyPI index.
All relevant packages and tests directly impacted by this PR are passing.

Let me know if anything else is needed on my side!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not a problem if it fails, we can see where the failure is and we can easily ignore when we merge the change, no need to try and fix unrelated failing tests!

Copy link
Member

@AstraBert AstraBert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests!

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jul 28, 2025
@AstraBert AstraBert merged commit 1e64aae into run-llama:main Jul 28, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Use pydoc :param: to populate description of a function tool field if field is not Annotated

2 participants