Skip to content
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

Cannot process return type annotations for pydantic types #491

Closed
vikigenius opened this issue Dec 19, 2024 · 4 comments · Fixed by #606
Closed

Cannot process return type annotations for pydantic types #491

vikigenius opened this issue Dec 19, 2024 · 4 comments · Fixed by #606

Comments

@vikigenius
Copy link

I did a follow up experiment on this issue #134

And changed the get_location tool to have a docstring

@agent_pydantic_output_tool.tool
def get_location(ctx: RunContext[None], place_name: str) -> Location:
    """Gets the lattitude and longitude of a location.
    
    Args:
        place_name: The name of the place to get location for.

    Returns:
        The location information.
    """
    return Location(latitude=36.53, longitude=-116.93)

This causes a warning.

WARNING:griffe:<module>:7: No type or annotation for returned value 1

Is this expected?

How are the docstrings and return type annotations used by pydantic in tool call results? Is it better to convert the return type into simpler types for tools?

@vikigenius vikigenius changed the title Cannot process return type annotations for complex types Cannot process return type annotations for pydantic types Dec 19, 2024
@vikigenius
Copy link
Author

@samuelcolvin I see that this could be related to this issue: mkdocstrings/griffe#293

It seems like the error is happening here in griffe

            # try to retrieve the annotation from the docstring parent
            annotation = _annotation_from_parent(docstring, gen_index=2, multiple=len(block) > 1, index=index)

And because parent is a signature object

this errors out

        annotation = docstring.parent.annotation  # type: ignore[union-attr]

@vikigenius
Copy link
Author

Since the return type annotations and docstrings is not used at all, would the solution be to somehow disable this specific warning?

Alternatively I can just stop putting the returns statement in the docstring, but that does not seem ideal.

@samuelcolvin
Copy link
Member

weird, yes because we're not using the return type we should find a way to mute this warning or even avoid parsing that part of the function completely.

@abo-mapp
Copy link

abo-mapp commented Jan 2, 2025

Could it be that the @wraps annotation is missing?
cf. https://chatgpt.com/share/e/6776b1cb-5978-8012-9b2b-6668eaecb34a

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 a pull request may close this issue.

3 participants