{"record":{"id":"1425466ba9273a06","repo":"dagger/dagger","slug":"array-element-must-be-string-got-t","errorCode":null,"errorMessage":"array element must be string, got %T","messagePattern":"array element must be string, got %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/llm_google.go","lineNumber":682,"sourceCode":"\t\t}\n\t\treturn res, nil\n\tcase []map[string]any:\n\t\treturn x, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"value must be []map[string]any or []any, got %T\", x)\n\t}\n}\n\nfunc toStringSlice(val any) ([]string, error) {\n\tvar res []string\n\tswitch x := val.(type) {\n\tcase []any:\n\t\tfor _, v := range x {\n\t\t\tswitch y := v.(type) {\n\t\t\tcase string:\n\t\t\t\tres = append(res, y)\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"array element must be string, got %T\", y)\n\t\t\t}\n\t\t}\n\tcase []string:\n\t\tres = x\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"value must be []string or []any, got %T\", x)\n\t}\n\treturn res, nil\n}\n\nfunc bbiTypeToGenaiType(bbi string) genai.Type {\n\tswitch bbi {\n\tcase \"integer\":\n\t\treturn genai.TypeInteger\n\tcase \"number\":\n\t\treturn genai.TypeNumber\n\tcase \"string\":\n\t\treturn genai.TypeString","sourceCodeStart":664,"sourceCodeEnd":700,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/llm_google.go#L664-L700","documentation":"toStringSlice converts a schema value expected to be a list of strings (e.g. 'required' or 'enum') into []string. When the value is []any, every element must be a string. This error is thrown when one element is a different JSON type (number, bool, object, null), since Google's genai schema requires string-only lists for these fields.","triggerScenarios":"'enum' containing non-string values (e.g. enum: [1,2,3] or [\"a\", null]) or 'required' containing non-string entries (e.g. required: [true]) while converting a tool schema for the Google provider.","commonSituations":"Enums defined with numeric values; required lists accidentally containing objects/booleans from bad schema generation.","solutions":["Make every element of the array a string; for numeric enums, express values as strings or restructure the schema.","For numeric enums, note genai only supports string Enum; convert values with fmt.Sprintf or use description text instead.","Validate enum/required arrays are all-strings before registering the tool."],"exampleFix":"// before\n\"enum\": [1, 2, 3]\n// after\n\"enum\": [\"1\", \"2\", \"3\"]","handlingStrategy":"type-guard","validationCode":"func validateStringSlice(v any) error {\n    arr, ok := v.([]any)\n    if !ok { return nil }\n    for i, el := range arr {\n        if _, ok := el.(string); !ok {\n            return fmt.Errorf(\"element %d is not a string\", i)\n        }\n    }\n    return nil\n}","typeGuard":"func allStrings(v any) bool {\n    switch x := v.(type) {\n    case []string:\n        return true\n    case []any:\n        for _, e := range x {\n            if _, ok := e.(string); !ok { return false }\n        }\n        return true\n    }\n    return false\n}","tryCatchPattern":"if err := registerTool(schema); err != nil {\n    if strings.Contains(err.Error(), \"array element must be string\") {\n        // coerce or report enum/required elements\n    }\n}","preventionTips":["Keep enum values as strings; genai supports only string enums.","Keep required as an array of property-name strings.","Convert numbers/bools to strings explicitly if they must appear in enums."],"tags":["schema","google","tool-calling","enum","type-mismatch"],"backgroundTag":"schema-validation-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}