wavetermdev/waveterm · error
invalid input format
Error message
invalid input format
What it means
This error comes from the ToolAnyCallback of a sum-style AI tool in tools.go. The callback type-asserts its raw `input any` argument to map[string]any; if the runtime input is not a JSON object (map), the assertion fails and this error is returned to the LLM caller. It guards against malformed tool invocations before any parameter extraction.
Source
Thrown at pkg/aiusechat/tools.go:289
Strict: true,
InputSchema: map[string]any{
"type": "object",
"properties": map[string]any{
"values": map[string]any{
"type": "array",
"items": map[string]any{
"type": "integer",
},
"description": "Array of numbers to add together",
},
},
"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 {View on GitHub (pinned to a4447c1563)
Solutions
- Ensure the tool call arguments are a JSON object wrapping the array, e.g. {"values": [1,2,3]} instead of [1,2,3]
- Check the model/SDK version; newer models with strict tool-calling honor the declared schema's additionalProperties/type constraints better
- If invoking programmatically, pass a map[string]any (or object that re-marshals to a JSON object), not a slice or scalar
Example fix
// before
anySum([1, 2, 3])
// after
anySum({"values": [1, 2, 3]}) Defensive patterns
Strategy: type-guard
Validate before calling
if v, ok := raw.(map[string]any); !ok { return fmt.Errorf("tool input must be a JSON object") }; if _, ok := v["values"]; !ok { return fmt.Errorf("missing values") }; if _, ok := v["values"].([]any); !ok { return fmt.Errorf("values must be an array") } Type guard
func asObjectMap(input any) (map[string]any, bool) { m, ok := input.(map[string]any); return m, ok } Try / catch
result, err := tool.Call(input); if err != nil { if strings.Contains(err.Error(), "invalid input format") { /* re-invoke model with corrected schema example */ } return err } Prevention
- Always send tool arguments as a JSON object, never a bare array or scalar
- Declare the JSON schema with type:object and required:["values"] in the tool definition
- Log raw tool-call arguments to catch models emitting wrong shapes
When it happens
Trigger: The AI/LLM invokes the tool with input that is not a JSON object — e.g. a bare array, string, number, or nil is passed as the tool arguments instead of an object like {"values":[1,2,3]}.
Common situations: Model-generated tool call arguments that are JSON arrays or strings instead of objects; older model versions ignoring the JSON schema's type:object constraint; a caller invoking the tool programmatically passing a non-map value; JSON deserialization layers that hand raw scalars through.
Related errors
- missing values parameter
- values must be an array
- value at index %d is not a number
- invalid input format: %w
- Invalid path part: ${pathPart}
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/b65232e2a2bbcf9a.
Report an issue: GitHub.