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

tools require a filled description #336

Open
efriis opened this issue Jan 23, 2025 · 3 comments
Open

tools require a filled description #336

efriis opened this issue Jan 23, 2025 · 3 comments
Labels
bedrock bug Something isn't working

Comments

@efriis
Copy link
Member

efriis commented Jan 23, 2025

Generally langchain tools default to having an empty string as a description. Some (maybe all) bedrock models require a filled description, which affects the ease of use of with_structured_output(method="function_calling") and bind_tools with ChatBedrock

In particular, this impacts model interoperability, where people are trying their tools with different models, and the bedrock versions simply fail.

Some ideas:

  • populate the description with the same as the tool name by default in bedrock to avoid the error
  • raise a more descriptive error to help people populate docstrings on their tool function/basemodel/etc

I'm probably more in favor of auto populating for models this impacts

cc @hinthornw

@3coins 3coins added bug Something isn't working bedrock labels Jan 23, 2025
@3coins
Copy link
Collaborator

3coins commented Jan 23, 2025

cc @patilvishal0597

@patilvishal0597
Copy link

Hello, I tried to recreate this problem with a tool below. I noticed that langchain auto-populates docstrings in tool description field if description is not provided. I have commented the docstrings in the below example:

class WikiInputs(BaseModel):
    # """Inputs to the wikipedia tool."""

    query: str = Field(
        description="query to look up in Wikipedia, should be 3 or less words"
    )

@tool("search-tool", args_schema=WikiInputs, return_direct=True)
def search(query: str) -> str:
    # """Look up things online."""
    return "LangChain"

tools = [search]

I have the following code that is executed next:

def main():
    """Initializing Bedrock Chat for testing ChatBedrock calls"""
    llm = getChatBedrock().bind_tools(tools=tools)

    
    """llm Invoke/converse call"""
    response = llm.invoke(getInputMessage())
    print(response)

I get the following stack trace:

Traceback (most recent call last):
  File "/Users/vishal/Desktop/langchain-aws/langchain-aws/libs/aws/tool_use_example.py", line 18, in <module>
    @tool("search-tool", args_schema=WikiInputs, return_direct=True)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vishal/Library/Caches/pypoetry/virtualenvs/langchain-aws-uKC4YU62-py3.12/lib/python3.12/site-packages/langchain_core/tools/convert.py", line 249, in _tool_factory
    return StructuredTool.from_function(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vishal/Library/Caches/pypoetry/virtualenvs/langchain-aws-uKC4YU62-py3.12/lib/python3.12/site-packages/langchain_core/tools/structured.py", line 190, in from_function
    raise ValueError(msg)
ValueError: Function must have a docstring if description not provided.

Can I request you to provide an example of tool use where the description is an empty string? This can be helpful to debug further. Thanks!

@3coins
Copy link
Collaborator

3coins commented Jan 30, 2025

@patilvishal0597
@tool decorator does require a description as required in the function used as a tool, this is defined in the docs, but you can also bind simple functions as tools (without the @tool decorator). I think the issue raised here by @efriis is related to that use case. Here is a sample code that replicates the issue.

from pydantic import BaseModel, Field
from langchain_aws import ChatBedrockConverse


def search(query: str) -> str:
    return "LangChain"


def main():
    llm = ChatBedrockConverse(
        model="anthropic.claude-3-5-haiku-20241022-v1:0"
    )
    llm_with_tools = llm.bind_tools([search])
    llm_with_tools.invoke("Hello!")


if __name__ == "__main__":
    main()

Here is the exception raised by the Bedrock API.

    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid length for parameter toolConfig.tools[0].toolSpec.description, value: 0, valid min length: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bedrock bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants