ValidationError: Input should be a valid dictionary or instance of BaseTool

You’re still initializing the tool without extending the BaseTool class by defining a subclass. Remove this line completely.

You’re still setting the tool parameter incorrectly.

Also, you didn’t implement the tool. You just copy-pasted my code from the answer above.

Try the following:

from crewai.tools import BaseTool
from langchain_community.tools import DuckDuckGoSearchRun

class MyCustomDuckDuckGoTool(BaseTool):
    name: str = "DuckDuckGo Search Tool"
    description: str = "Search the web for a given query."

    def _run(self, query: str) -> str:
        duckduckgo_tool = DuckDuckGoSearchRun()
        
        response = duckduckgo_tool.invoke(query)

        return response

Then set the tools parameter as follows:

tools=[MyCustomDuckDuckGoTool()]
1 Like