tool_input_parsingTier 1 · 70% confidence

ai-agents-tool-input-parsing-when-using-llama-3-8b-or-similar-models-with-crewa-b6232798

agent: ai_agents

When does this happen?

IF When using Llama 3 8B or similar models with CrewAI, custom tools that expect a JSON string argument fail with 'Error: the Action Input is not a valid key, value dictionary' because the model outputs the JSON object directly without proper string quoting.

How others solved it

THEN Ensure the tool's `args_schema` Pydantic model has a single string field for the JSON argument, and inside `_run`, parse it with `json.loads`. In the task configuration, pass `tool_input` as a JSON string (e.g., `json.dumps(params)`). Also, instruct the agent to output the tool input as a JSON string enclosed in double quotes, like `'{"key": "value"}'`.

class ArxivResearchInput(BaseModel):
    argument: str = Field(description='JSON string')

class ArxivResearchTool(BaseTool):
    name: str = 'arxiv_research_tool'
    args_schema: Type[BaseModel] = ArxivResearchInput

    def _run(self, argument: str) -> Dict:
        params = json.loads(argument)
        return ResearchTool.arxiv_research_tool(params)

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics