validateToolCalls static method
Validate multiple tool calls against their definitions
toolCalls
- List of tool calls to validate
availableTools
- List of available tool definitions
Returns a map of tool call ID to validation errors (empty map if all valid)
Implementation
static Map<String, List<String>> validateToolCalls(
List<ToolCall> toolCalls,
List<Tool> availableTools,
) {
final errors = <String, List<String>>{};
for (final toolCall in toolCalls) {
final tool = findTool(toolCall.function.name, availableTools);
if (tool == null) {
errors[toolCall.id] = ['Tool not found: ${toolCall.function.name}'];
continue;
}
try {
validateToolCall(toolCall, tool);
} catch (e) {
if (e is ToolValidationError) {
errors[toolCall.id] = [e.message];
} else {
errors[toolCall.id] = ['Validation error: $e'];
}
}
}
return errors;
}