{"record":{"id":"d803f1c814de199a","repo":"dagger/dagger","slug":"failed-to-convert-anyof-variant-d-w","errorCode":null,"errorMessage":"failed to convert anyOf variant %d: %w","messagePattern":"failed to convert anyOf variant (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/llm_google.go","lineNumber":554,"sourceCode":"\t\tDisplaySpans:     displaySpans,\n\t\tToolCallDisplays: toolCallDisplays,\n\t}, nil\n}\n\n// TODO: this definitely needs a unit test\nfunc bbiSchemaToGenaiSchema(bbi map[string]any) (*genai.Schema, error) {\n\tschema := &genai.Schema{}\n\tfor key, param := range bbi {\n\t\tswitch key {\n\t\tcase \"anyOf\":\n\t\t\tvariants, err := toSchemaMaps(param)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to convert anyOf field: %w\", err)\n\t\t\t}\n\t\t\tfor i, variant := range variants {\n\t\t\t\tvariantSchema, err := bbiSchemaToGenaiSchema(variant)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, fmt.Errorf(\"failed to convert anyOf variant %d: %w\", i, err)\n\t\t\t\t}\n\t\t\t\tschema.AnyOf = append(schema.AnyOf, variantSchema)\n\t\t\t}\n\t\tcase \"description\":\n\t\t\tif schema.Description != \"\" {\n\t\t\t\tschema.Description += \" \"\n\t\t\t}\n\t\t\tdesc, ok := param.(string)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"description must be a string, got %T\", param)\n\t\t\t}\n\t\t\tschema.Description += desc\n\t\tcase \"properties\":\n\t\t\tprops, err := bbiPropertiesToGenaiSchemas(param)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tschema.Properties = props","sourceCodeStart":536,"sourceCodeEnd":572,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/llm_google.go#L536-L572","documentation":"While expanding an anyOf field, each variant is recursively converted with bbiSchemaToGenaiSchema. This error wraps the failure of the variant at index i, so a nested schema inside anyOf is malformed (bad description type, bad items, non-map properties, etc.).","triggerScenarios":"A tool schema with anyOf where one of the variant objects is itself invalid, e.g. anyOf:[{\"type\":\"string\"},{\"description\":123}] or a variant with items as a non-map; reached through convertToolsToGenai or nested anyOf.","commonSituations":"Deeply nested schemas composed programmatically where a generator emitted an invalid variant; copy-pasted JSON Schema fragments that Google's GenAI schema subset does not accept.","solutions":["Check the variant index %d in the message and validate that variant object","Ensure every anyOf variant is a valid map[string]any schema with string-typed description/format","Recursively validate nested schemas before registering the tool","Simplify the anyOf into separate flat schemas if the variant is complex"],"exampleFix":"// before\n\"anyOf\": [{\"type\": \"string\"}, {\"description\": 42}]\n// after\n\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"string\", \"description\": \"a string\"}]","handlingStrategy":"validation","validationCode":"func validateVariants(s map[string]any) error {\n    variants, _ := s[\"anyOf\"].([]any)\n    for i, v := range variants {\n        m, ok := v.(map[string]any)\n        if !ok { return fmt.Errorf(\"variant %d not a map\", i) }\n        if d, present := m[\"description\"]; present {\n            if _, ok := d.(string); !ok { return fmt.Errorf(\"variant %d description not a string\", i) }\n        }\n    }\n    return nil\n}","typeGuard":"func isSchemaVariant(v any) (*map[string]any, bool) {\n    m, ok := v.(map[string]any)\n    return &m, ok\n}","tryCatchPattern":"schema, err := bbiSchemaToGenaiSchema(bbi)\nif err != nil {\n    var idx int\n    if _, scan := fmt.Sscanf(err.Error(), \"failed to convert anyOf variant %d\", &idx); scan == nil {\n        return fmt.Errorf(\"invalid anyOf variant at index %d: %w\", idx, err)\n    }\n    return err\n}","preventionTips":["Validate each anyOf variant as a complete valid schema before registration","Keep variant schemas simple: type/description only where possible","Add unit tests covering nested anyOf schemas for every tool"],"tags":["schema","json-schema","anyof","tool-calling"],"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"}