wavetermdev/waveterm · error
values must be an array
Error message
values must be an array
What it means
The "values" key exists but its value is not a JSON array ([]any). The callback type-asserts valuesInterface.([]any) and returns this error on failure. Note an empty array is explicitly allowed (returns sum 0), so this error is strictly about the wrong type, not emptiness.
Source
Thrown at pkg/aiusechat/tools.go:299
},
},
"required": []string{"values"},
"additionalProperties": false,
},
ToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {
inputMap, ok := input.(map[string]any)
if !ok {
return nil, fmt.Errorf("invalid input format")
}
valuesInterface, ok := inputMap["values"]
if !ok {
return nil, fmt.Errorf("missing values parameter")
}
valuesSlice, ok := valuesInterface.([]any)
if !ok {
return nil, fmt.Errorf("values must be an array")
}
if len(valuesSlice) == 0 {
return 0, nil
}
sum := 0
for i, val := range valuesSlice {
floatVal, ok := val.(float64)
if !ok {
return nil, fmt.Errorf("value at index %d is not a number", i)
}
sum += int(floatVal)
}
return sum, nil
},
}View on GitHub (pinned to a4447c1563)
Solutions
- Pass values as a JSON array: {"values": [1, 2, 3]} — not a string, number, or object
- If the model keeps sending strings, strengthen the tool description with an explicit example showing an array literal
- Validate client-side before invoking: check Array.isArray(values) / reflect.Kind Slice before calling the tool
Example fix
// before
anySum({"values": "1,2,3"})
// after
anySum({"values": [1, 2, 3]}) Defensive patterns
Strategy: type-guard
Validate before calling
raw, ok := m["values"]; if !ok { return errors.New("values required") }; if _, ok := raw.([]any); !ok { return errors.New("values must be a JSON array") } Type guard
func isAnySlice(v any) ([]any, bool) { s, ok := v.([]any); return s, ok } Try / catch
out, err := tool.Call(input); if err != nil && strings.Contains(err.Error(), "values must be an array") { return fmt.Errorf("bad tool args: %w", err) } Prevention
- Never quote the array or pass a single scalar; always [1,2,3]
- Include an array example in the tool description for the model
- Coerce strings like "1,2,3" into arrays before calling
When it happens
Trigger: Tool called with values as a non-array: e.g. {"values": 5}, {"values": "1,2,3"}, {"values": {"0":1}}, or null.
Common situations: Model passing a comma-separated string instead of an array; passing a single number instead of a one-element array; passing an object keyed by indices; client SDK serializing variadic args as scalars.
Related errors
- value at index %d is not a number
- invalid input format
- invalid input format: %w
- Invalid path part: ${pathPart}
- convertFileUIMessagePart expects 'file' type, got '%s'
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/e4297eb398e9dcdd.
Report an issue: GitHub.