{"record":{"id":"b65232e2a2bbcf9a","repo":"wavetermdev/waveterm","slug":"invalid-input-format","errorCode":null,"errorMessage":"invalid input format","messagePattern":"invalid input format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools.go","lineNumber":289,"sourceCode":"\t\tStrict:      true,\n\t\tInputSchema: map[string]any{\n\t\t\t\"type\": \"object\",\n\t\t\t\"properties\": map[string]any{\n\t\t\t\t\"values\": map[string]any{\n\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\"items\": map[string]any{\n\t\t\t\t\t\t\"type\": \"integer\",\n\t\t\t\t\t},\n\t\t\t\t\t\"description\": \"Array of numbers to add together\",\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"required\":             []string{\"values\"},\n\t\t\t\"additionalProperties\": false,\n\t\t},\n\t\tToolAnyCallback: func(input any, toolUseData *uctypes.UIMessageDataToolUse) (any, error) {\n\t\t\tinputMap, ok := input.(map[string]any)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid input format\")\n\t\t\t}\n\n\t\t\tvaluesInterface, ok := inputMap[\"values\"]\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"missing values parameter\")\n\t\t\t}\n\n\t\t\tvaluesSlice, ok := valuesInterface.([]any)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"values must be an array\")\n\t\t\t}\n\n\t\t\tif len(valuesSlice) == 0 {\n\t\t\t\treturn 0, nil\n\t\t\t}\n\n\t\t\tsum := 0\n\t\t\tfor i, val := range valuesSlice {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools.go#L271-L307","documentation":"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.","triggerScenarios":"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]}.","commonSituations":"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.","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"],"exampleFix":"// before\nanySum([1, 2, 3])\n// after\nanySum({\"values\": [1, 2, 3]})","handlingStrategy":"type-guard","validationCode":"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\") }","typeGuard":"func asObjectMap(input any) (map[string]any, bool) { m, ok := input.(map[string]any); return m, ok }","tryCatchPattern":"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 }","preventionTips":["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"],"tags":["tool-input","type-mismatch","ai-tools"],"backgroundTag":"tool-input-not-an-object","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}