Skip to main content

What are Tool Calls?

Tool calling (also called function calling) lets AI models execute functions and use external tools:
The AI decides which tools to call, in what order, and with what arguments.

Why Test Tool Calls?

AI agents can make mistakes: Wrong tool: Calls delete_event instead of update_eventWrong 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:
StreamParser automatically converts these to SemanticTest format:

Basic Validation

Check Expected Tools

Verify AI called the right tools:

Validation Options

1. Expected Tools

Tools that must be called:
Result:

2. Forbidden Tools

Tools that must not be called:
Critical for safety! Fails if any forbidden tool is called.

3. Tool Count

Validate number of tools called:
Use cases:
  • Ensure agent doesn’t get stuck (minTools: 1)
  • Prevent excessive tool calling (maxTools: 5)

4. Tool Order

Validate sequence of tool calls:
Example: Database agent must authenticate before querying.

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:
Important: Agent should ask for confirmation or escalate, not immediately delete.

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

Critical for production safety!
Prevents data corruption and security issues.
validateArgs only supports exact value matching, not operators like lte, gte, etc. For complex validations, use assertions on the actual values after extraction.
Catches stuck or runaway agents.
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 actualTools
Step 2: Check failures
Step 3: Check tool arguments

Common Issues

Integration with AI Providers

OpenAI Function Calling

Anthropic Tool Use

Vercel AI SDK

Then test with StreamParser:

Next Steps

Streaming Responses

Learn to parse and test SSE streams

Multi-Turn Conversations

Test conversational AI flows

ValidateTools Reference

Complete ValidateTools documentation

Calendar Agent Example

Full calendar agent test example