Testing Tool Arguments
Tool argument tests verify that the agent generates correct, complete, and valid arguments for each tool call.
6 min•By Priygop Team•Updated 2026
Argument Quality Checks
- Completeness: all required arguments are present
- Type correctness: arguments are the right data type (string, int, list)
- Format correctness: dates, emails, IDs follow the expected format
- Value ranges: numeric arguments are within valid ranges
- Relevance: the argument values are appropriate for the stated goal
- No hallucination: the agent does not invent values that were not provided in context
Argument Test Example
Argument Test Example
# Test that agent generates valid arguments for a tool call
from datetime import datetime
def evaluate_refund_args(agent_fn, test_cases: list) -> dict:
"""Test that the agent generates valid refund tool arguments."""
results = {"passed": 0, "failed": 0}
for case in test_cases:
args = agent_fn(case["input"]) # Agent generates args from natural language
errors = []
# Check required fields
for field in ["order_id", "amount", "reason"]:
if field not in args or not args[field]:
errors.append(f"Missing: {field}")
# Check order_id format
if "order_id" in args and not str(args["order_id"]).startswith("ORD-"):
errors.append(f"Invalid order_id format: {args['order_id']}")
# Check amount is positive
if "amount" in args:
if not isinstance(args["amount"], (int, float)) or args["amount"] <= 0:
errors.append(f"Amount must be positive: {args['amount']}")
# Check amount matches what was stated in the input
expected_amount = case.get("expected_amount")
if expected_amount and abs(args.get("amount", 0) - expected_amount) > 0.01:
errors.append(f"Amount mismatch: got {args.get('amount')}, expected {expected_amount}")
passed = len(errors) == 0
results["passed" if passed else "failed"] += 1
status = "✓" if passed else f"✗ ({'; '.join(errors)})"
print(f" {status} Input: '{case['input'][:40]}'")
return results
# Mock agent that generates arguments from natural language
def mock_agent(user_input: str) -> dict:
if "ORD-123" in user_input and "49.99" in user_input:
return {"order_id": "ORD-123", "amount": 49.99, "reason": "product damaged"}
return {"order_id": "BAD", "amount": -10, "reason": ""} # Intentionally bad
test_cases = [
{"input": "Refund order ORD-123 for $49.99, product damaged", "expected_amount": 49.99},
{"input": "Process the refund", # Vague — agent must guess
"expected_amount": None},
]
results = evaluate_refund_args(mock_agent, test_cases)
print(f"\nPassed: {results['passed']}, Failed: {results['failed']}")Key Takeaways
- Tool argument tests verify that the agent generates correct, complete, and valid arguments for each tool call.
- Completeness: all required arguments are present
- Type correctness: arguments are the right data type (string, int, list)
- Format correctness: dates, emails, IDs follow the expected format