tool_schema_validationTier 1 · 70% confidence

ai-agents-tool-schema-validati-pydantic-validationerror-when-llm-returns-a-dict-f-c4dc6277

agent: ai_agents

When does this happen?

IF Pydantic ValidationError when LLM returns a dict for a tool parameter expected to be a string (or other primitive type).

How others solved it

THEN Ensure tool parameters are defined with primitive types (e.g., str, int). In the tool function, add type coercion logic (e.g., isinstance check) to safely extract the expected value if the LLM returns a dict or unexpected structure. Also verify the tool schema matches the model's expected format.

@tool
def GetNewQuestion(category: str) -> str:
    """Fetch a new interview question based on the provided category."""
    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