# Issue with custom tool

**URL:** <https://community.crewai.com/t/issue-with-custom-tool/2181>\
**Category:** General\
**Tags:** tools\_issues\
**Created:** [December 21, 2024, 4:50pm UTC](https://community.crewai.com/t/issue-with-custom-tool/2181 "2024-12-21T16:50:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rushikesh\_jejurkar](https://avatars.discourse-cdn.com/v4/letter/r/dbc845/32.png) [@rushikesh\_jejurkar](https://community.crewai.com/u/rushikesh_jejurkar)\
**Post date:** [December 21, 2024, 4:50pm UTC](https://community.crewai.com/t/issue-with-custom-tool/2181/1 "2024-12-21T16:50:08Z")

</div>

Getting an error  
I encountered an error while trying to use the tool. This was the error: extract\_text\_tool() missing 1 required positional argument: ‘file\_path’.  
Tool Extract Text Tool accepts these inputs: Tool Name: Extract Text Tool

@tool(“Extract Text Tool”)  
def extract\_text\_tool(file\_path):  
“”“This tool reads an image file, converts it to Base64, and extracts text using GPT-4o.”“”  
try:  
# Step 1: Get file extension to determine MIME type  
file\_extension = os.path.splitext(file\_path)[1].lower()  
if file\_extension == ‘.png’:  
mime\_type = ‘image/png’  
elif file\_extension in [‘.jpg’, ‘.jpeg’]:  
mime\_type = ‘image/jpeg’  
else:  
raise ValueError(“Unsupported image format. Only .png, .jpg, and .jpeg are supported.”)

```
    # Step 2: Convert the image to Base64 encoding
    with open(file_path, "rb") as img_file:
        image_base64 = base64.b64encode(img_file.read()).decode('utf-8')

    # Step 3: Prepare the message for GPT-4 Vision
    messages = HumanMessage(
        content=[
            {"type": "text", "text": "Extract Text from image:"},
            {"type": "image_url", "image_url": {"url": f"data:{mime_type};base64,{image_base64}"}}
        ]
    )
   
    # Step 4: Invoke the LLM client to get the response
    print("Processing image with GPT-4 Vision...")
    llm_client = LLM(  

    )  
    response = llm_client.invoke([messages]) # Ensure that llm_client is set up correctly
    print("LLM execution completed.")
   
    # Step 5: Extract and process the text from the response
    if 'content' in response:
        text = response['content'] # Adjust this based on the actual response structure from GPT-4 Vision
    else:
        print("No text found in the response.")
        text = ""

    return text

except Exception as e:
    print(f"Error processing the image: {e}")
    return "Error extracting text."

```

task  
class ShoppingListTasks:  
def **init** (self, user\_input,user\_preferences,file\_path, extract\_text\_tool, text\_extractor\_agent, brand\_quantity\_agent ):  
self.user\_input =user\_input  
self.user\_preferences = user\_preferences  
self.file\_path = file\_path  
self.extract\_text\_tool = extract\_text\_tool  
self.text\_extractor\_agent=text\_extractor\_agent  
self.brand\_quantity\_agent = brand\_quantity\_agent

```
def extract_text_task(self):
    """Create a task to identify the user's shopping list and extract relevant details from the provided image."""
    extract_text_task= Task(
    description=(
       f"""Generate an image based on the shopping list in the provided file {self.file_path}. Extract the product names, quantities, and any additional notes, and display them in a clear, organized, and visually appealing layout."""
    ),
    expected_output="""A list of shopping list products extracted from the shopping list image {self.file_path}, including shopping list product names and any associated quantities or notes (if available).""",
    tools=[self.extract_text_tool],
    agent=self.text_extractor_agent,
    file_path=self.file_path )
    return extract_text_task

```

---

<div class="post-metadata">

**Author:** ![101010](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/101010/32/1616_2.png) [@101010](https://community.crewai.com/u/101010)\
**Post date:** [December 24, 2024, 12:48pm UTC](https://community.crewai.com/t/issue-with-custom-tool/2181/2 "2024-12-24T12:48:11Z")

</div>

Please revise your post formatting so that the code is enclosed in three consecutive single backticks. Which represents a code block.  
Is your tool located in \src\<crew-folder\>\tools\custom\_tool.py?

Change your function like:

```auto
    @tool(“Extract Text Tool”)
    def extract_text_tool(file_path: str) -> str:

```

You are using the decorator, if this approach doesnt work try creating you tool by subclassing BaseTool. [Create Custom Tools - CrewAI](https://docs.crewai.com/how-to/create-custom-tools#subclassing-basetool)

Hope this helps somehow. I am new to crewai myself and also struggle with creating my own custom tool. 😉
