Skip to content

Parse description field if return type of a function is a pydantic.BaseModel #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lienchen0526
Copy link

@lienchen0526 lienchen0526 commented Apr 11, 2025

Parse description field if return type of a function is a pydantic.BaseModel

The usage will be like:

from pydantic import BaseModel, Field
from google.adk.tools._automatic_function_calling_util import build_function_declaration

class M(BaseModel):
  foo_field: int = Field(description = "This is a tested description")

def foo() -> M:
  pass

print(build_function_declaration(foo, variant='VERTEX_AI'))

Before this commit, the printed will be looks like:

response=Schema(example=None, pattern=None, default=None, max_length=None, min_length=None, min_properties=None, max_properties=None, any_of=None, description=None, enum=None, format=None, items=None, max_items=None, maximum=None, min_items=None, minimum=None, nullable=None, properties={'foo_field': Schema(example=None, pattern=None, default=None, max_length=None, min_length=None, min_properties=None, max_properties=None, any_of=None, description=None, enum=None, format=None, items=None, max_items=None, maximum=None, min_items=None, minimum=None, nullable=None, properties=None, property_ordering=None, required=None, title=None, type=<Type.INTEGER: 'INTEGER'>)}, property_ordering=None, required=None, title=None, type=<Type.OBJECT: 'OBJECT'>) description=None name='foo' parameters=None

which we do not track the description of foo_field of class M. After this commit, the printed will be like:

response=Schema(example=None, pattern=None, default=None, max_length=None, min_length=None, min_properties=None, max_properties=None, any_of=None, description=None, enum=None, format=None, items=None, max_items=None, maximum=None, min_items=None, minimum=None, nullable=None, properties={'foo_field': Schema(example=None, pattern=None, default=None, max_length=None, min_length=None, min_properties=None, max_properties=None, any_of=None, description='This is a tested description', enum=None, format=None, items=None, max_items=None, maximum=None, min_items=None, minimum=None, nullable=None, properties=None, property_ordering=None, required=None, title=None, type=<Type.INTEGER: 'INTEGER'>)}, property_ordering=None, required=None, title=None, type=<Type.OBJECT: 'OBJECT'>) description=None name='foo' parameters=None

TESTED=manual

@lienchen0526 lienchen0526 marked this pull request as ready for review April 12, 2025 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant