CrewAI - Langchain StructuredTool JSON markdown string as input
I have a custom tool using the langchain StructuredTool.from_function
from langchain.tools.base import StructuredTool
from langchain_core.pydantic_v1 import BaseModel, Field
create_draft_tool = StructuredTool.from_function(
func=create_draft,
name="Create Draft",
description="""
Create an email draft. Ensure to pass input as a valid JSON.
Only pass in a JSON object. Do not pass in any markdown string anywhere.
""",
args_schema=DraftInput,
return_direct=True
)
where DraftInput is a Pydantic class (fields excluded)
class DraftInput(BaseModel):
to: str = Field(
...,
description="Who to send the email to",
alias="to"
)
but when the tool is called, it passes in the correct JSON but inside a markdown string like so:
Action: Create Draft
Action Input:
```json
{
"to": "<email>"
}
```.
and so the tool fails with the error Task output: Error: the Action Input is not a valid key, value dictionary.
How can I force it to just input the JSON object and not inside the markdown string.
langchain~=0.2.6
crewai==0.36.0
I've been having problems with my tools as well not sure why my search tool decided to stop working along with every other tool.
@theCyberTech any thoughts? This is quite a big issue when using tools.
i have the same issue with build-in FileWriteTool. crewai version: 0.63.2 crewai-tools 0.12.1 Python 3.12.6 langchain 0.2.16 Windows 11
# Agent: Thinker
## Thought: Thought: I need to write content to a specified TXT file to meet the given criteria.
## Using tool: File Writer Tool
## Tool Input:
"{\"filename\": \"important_document.txt\", \"content\": \"This is the content of the important document that must be written to the file.\", \"overwrite\": true}"
## Tool Output:
Error: the Action Input is not a valid key, value dictionary.
i think that https://github.com/crewAIInc/crewAI/issues/1344 is connected with the issue
I would recommend build tools using the from crewai_tools import BaseTool class - https://docs.crewai.com/how-to/Create-Custom-Tools/
@voytas75 I think this might be not related, but could you try on the new version 0.63.6 ?
@joaomdmoura this error still occurs on 0.63.6
I will just add that now, as in previous versions, calling the tool directly creates a file:
from crewai_tools import FileWriterTool
file_writer_tool = FileWriterTool()
input_args = {
'filename': "test.txt",
'content': "test content",
'directory': "c:\\temp",
'overwrite': True,
'encoding': 'utf-8'
}
file_writer_tool._run(** input_args)
Nice testing it today, what model you're using so I can use the same?
azure/gpt4o https://gist.github.com/voytas75/1d73b9d4b1c6d5a6e995fb823e47c688
crewai version: 0.64
the same issue as earlier https://github.com/crewAIInc/crewAI/issues/923#issuecomment-2371935965
@ChristianJohnston97 what about you custom tool?
Thanks for the crew gist I'll look into this one soon
crewai version: 0.70.1
the same issue as earlier https://github.com/crewAIInc/crewAI/issues/923#issuecomment-2371935965
@ChristianJohnston97 what about your custom tool?
I have the same problem, for me sometimes it works with
## Tool Input:
{\"query\": \"my query\"}
but most of the time I get something like
## Tool Input:
"{\"name\": \"my query\", \"description\": \"\", \"args_schema\": {}, \"return_direct\": false, \"verbose\": false}"
resulting in
## Tool Output:
Error: the Action Input is not a valid key, value dictionary.
using gpt-4o-mini and tried @tool and using the base class
same issue with 0.76.2. In fact, just running "crewai create crew" and then uncommenting the Custom Tool in the template, I get this error.
I have the same error and this is very impredictable.
For the same custom tool, one iteration it works, next one it fails.
when ## Tool Input: "{"query": {"description": >> It fails ...... and I get the message Input should be a valid string
but sometimes, without changing anything , description disappears and it works!
Tool Input:
"{"query": " Expected prompt.... > and it works.
crewai-tools = "==0.13.4" crewai = "==0.76.9"
i have the same issue with build-in FileWriteTool. crewai version: 0.63.2 crewai-tools 0.12.1 Python 3.12.6 langchain 0.2.16 Windows 11
# Agent: Thinker ## Thought: Thought: I need to write content to a specified TXT file to meet the given criteria. ## Using tool: File Writer Tool ## Tool Input: "{\"filename\": \"important_document.txt\", \"content\": \"This is the content of the important document that must be written to the file.\", \"overwrite\": true}" ## Tool Output: Error: the Action Input is not a valid key, value dictionary.i think that #1344 is connected with the issue
it worked! crewai version: 0.79.4 crewai tools version: 0.14.0
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
Just refreshing this as I think the issue is related to the fact that some inputs are being returned in json format from the llm with lowercase boolean values, whereas when that input is run through ast_literal.eval(), it throws an error because python literal dicts need booleans in uppercase. I made a comment on this post to hopefully see if this is indeed the root cause of these "Error: the Action Input is not a valid key, value dictionary." issues. https://github.com/crewAIInc/crewAI/issues/1344#issuecomment-2549417475
This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.