{"record":{"id":"839ac647aa484de9","repo":"wavetermdev/waveterm","slug":"invalid-input-format-w","errorCode":null,"errorMessage":"invalid input format: %w","messagePattern":"invalid input format: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools_builder.go","lineNumber":67,"sourceCode":"\t\t}\n\t}\n\n\treturn map[string]any{\n\t\t\"build_success\": result.Success,\n\t\t\"build_error\":   result.ErrorMessage,\n\t\t\"build_output\":  result.BuildOutput,\n\t}\n}\n\nfunc parseBuilderWriteAppFileInput(input any) (*builderWriteAppFileParams, error) {\n\tresult := &builderWriteAppFileParams{}\n\n\tif input == nil {\n\t\treturn nil, fmt.Errorf(\"input is required\")\n\t}\n\n\tif err := utilfn.ReUnmarshal(result, input); err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid input format: %w\", err)\n\t}\n\n\tif result.Contents == \"\" {\n\t\treturn nil, fmt.Errorf(\"missing contents parameter\")\n\t}\n\n\treturn result, nil\n}\n\nfunc GetBuilderWriteAppFileToolDefinition(appId string, builderId string) uctypes.ToolDefinition {\n\treturn uctypes.ToolDefinition{\n\t\tName:        \"builder_write_app_file\",\n\t\tDisplayName: \"Write App File\",\n\t\tDescription: fmt.Sprintf(\"Write the app.go file for app %s\", appId),\n\t\tToolLogName: \"builder:write_app\",\n\t\tStrict:      false,\n\t\tInputSchema: map[string]any{\n\t\t\t\"type\": \"object\",","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools_builder.go#L49-L85","documentation":"After the nil check, input is converted to builderWriteAppFileParams via utilfn.ReUnmarshal (marshal then unmarshal round-trip). Any shape mismatch — wrong types for fields, incompatible structures — surfaces here wrapped as \"invalid input format: <underlying error>\".","triggerScenarios":"Tool invoked with an object whose fields don't match builderWriteAppFileParams (e.g. \"contents\": 123, or nested structures that can't round-trip through JSON), causing ReUnmarshal to fail.","commonSituations":"Model emitting wrong-typed fields (number where string expected); inputs containing values unrepresentable in JSON (channels, funcs) when called from Go code; schema drift between client and library versions.","solutions":["Read the wrapped %w cause to see the exact field/type mismatch and correct the tool arguments accordingly","Ensure contents is a string (and any other params match their declared types)","Verify client and library versions agree on the tool schema; update the SDK/model prompts if the schema changed"],"exampleFix":"// before\nparseBuilderWriteAppFileInput(map[string]any{\"contents\": 12345})\n// after\nparseBuilderWriteAppFileInput(map[string]any{\"contents\": \"file body text\"})","handlingStrategy":"type-guard","validationCode":"b, err := json.Marshal(input); if err != nil { return err }; var probe builderWriteAppFileParams; if err := json.Unmarshal(b, &probe); err != nil { return fmt.Errorf(\"invalid input format: %w\", err) }","typeGuard":"func canUnmarshalWriteAppFile(input any) bool { var p builderWriteAppFileParams; return utilfn.ReUnmarshal(&p, input) == nil }","tryCatchPattern":"params, err := parseBuilderWriteAppFileInput(input); if err != nil && strings.HasPrefix(err.Error(), \"invalid input format\") { log.Printf(\"bad args: %v\", err); return retryWithSchema(err) }","preventionTips":["Match field names and JSON types of builderWriteAppFileParams exactly","Only pass JSON-representable values (no channels/funcs) from Go callers","Keep tool schema docs in sync with the struct across versions"],"tags":["tool-input","unmarshal","type-mismatch","builder-tools"],"backgroundTag":"schema-validation-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}