What are Tool Calls?
Tool calling (also called function calling) lets AI models execute functions and use external tools:Why Test Tool Calls?
AI agents can make mistakes: ❌ Wrong tool: Callsdelete_event
instead of update_event
❌ Wrong order: Creates event before checking availability
❌ Wrong arguments: Books meeting at wrong time
❌ Missing tools: Forgets to send confirmation email
❌ Dangerous tools: Calls drop_database
unintentionally
ValidateTools catches these issues.
Tool Call Format
AI providers return tool calls in similar formats:- OpenAI
- Anthropic
- Vercel AI SDK
Basic Validation
Check Expected Tools
Verify AI called the right tools:Validation Options
1. Expected Tools
Tools that must be called:2. Forbidden Tools
Tools that must not be called:3. Tool Count
Validate number of tools called:- Ensure agent doesn’t get stuck (minTools: 1)
- Prevent excessive tool calling (maxTools: 5)
4. Tool Order
Validate sequence of tool calls:5. Tool Arguments
Validate what data is passed to tools:Combined Validation
Use multiple validation types together:Real-World Examples
1. Calendar Agent
Test an AI agent that manages calendar events:2. Customer Service Agent (Safety First)
Prevent dangerous actions:3. Database Agent (Order Matters)
Ensure proper authentication and query order:4. Multi-Step API Agent
Test complex workflows:Validation Output
ValidateTools returns detailed validation results:Combining with LLMJudge
Use ValidateTools for structure, LLMJudge for semantics:Best Practices
1. Always Use Forbidden List for Dangerous Tools
1. Always Use Forbidden List for Dangerous Tools
2. Validate Order for Multi-Step Workflows
2. Validate Order for Multi-Step Workflows
3. Check Tool Arguments for Critical Operations
3. Check Tool Arguments for Critical Operations
validateArgs only supports exact value matching, not operators like
lte
, gte
, etc. For complex validations, use assertions on the actual values after extraction.4. Set Tool Count Limits
4. Set Tool Count Limits
5. Test Edge Cases
5. Test Edge Cases
Test what happens when:
- Tools fail or timeout
- Required tools are unavailable
- User gives ambiguous instructions
- Multiple valid tool sequences exist
- Agent receives conflicting requirements
Debugging Failed Tool Calls
Problem: validation.passed is false
Step 1: Check actualToolsCommon Issues
Issue | Cause | Solution |
---|---|---|
Missing tools | AI didn’t call expected tool | Improve prompt, check tool descriptions |
Wrong order | AI called tools out of sequence | Add order config, improve instructions |
Forbidden tool used | AI called dangerous tool | Check forbidden list, improve safety prompts |
Too many tools | Agent over-complicating | Set maxTools , simplify task |
Wrong arguments | AI passed incorrect data | Add validateArgs , improve parameter descriptions |