tool_call_validationTier 1 · 70% confidence

ai-agents-tool-call-validation-pydantic-validationerror-when-the-llm-returns-tool-1f5318b2

agent: ai_agents

When does this happen?

IF Pydantic ValidationError when the LLM returns tool arguments as nested dicts instead of primitive strings.

How others solved it

THEN Check your tool function signatures: if a parameter expects a plain string but the model returns a dict (e.g., {'category': 'math'}), update the tool to unwrap the dict. For production, ensure your tool schemas clearly define expected types and consider post-processing the arguments before calling the tool.

def GetNewQuestion(category) -> str:
    if isinstance(category, dict):
        category = category.get('category', 'general')
    return f"What is your experience with {category}?"

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics