{"record":{"id":"a9a3adc1e807dfdf","repo":"github/copilot-sdk","slug":"failed-to-marshal-schema-for-type-v-v","errorCode":null,"errorMessage":"failed to marshal schema for type %v: %v","messagePattern":"failed to marshal schema for type (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/definetool.go","lineNumber":223,"sourceCode":"\tif t == nil {\n\t\treturn nil\n\t}\n\n\t// Handle pointer types\n\tif t.Kind() == reflect.Pointer {\n\t\tt = t.Elem()\n\t}\n\n\t// Use google/jsonschema-go to generate the schema\n\tschema, err := jsonschema.ForType(t, nil)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to generate schema for type %v: %v\", t, err))\n\t}\n\n\t// Convert schema to map[string]any\n\tschemaBytes, err := json.Marshal(schema)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to marshal schema for type %v: %v\", t, err))\n\t}\n\n\tvar schemaMap map[string]any\n\tif err := json.Unmarshal(schemaBytes, &schemaMap); err != nil {\n\t\tpanic(fmt.Sprintf(\"failed to unmarshal schema for type %v: %v\", t, err))\n\t}\n\n\treturn schemaMap\n}\n","sourceCodeStart":205,"sourceCodeEnd":233,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/definetool.go#L205-L233","documentation":"After jsonschema.ForType succeeds, generateSchemaForType marshals the resulting schema to JSON with encoding/json. A marshal failure panics with the type and error. Because the schema value comes from the jsonschema library, this is rare and indicates the schema object itself is not JSON-serializable.","triggerScenarios":"json.Marshal failing on the schema returned by jsonschema.ForType — e.g. a schema containing values that encoding/json cannot serialize (channels, funcs, NaN/Inf floats) possibly due to a custom schema field or library version change.","commonSituations":"Pinned/incompatible versions of google/jsonschema-go producing schema objects with unsupported member types; custom types with MarshalJSON methods that return invalid values; tool input structs with unusual field types.","solutions":["Check the wrapped marshal error to identify the offending schema member","Upgrade or pin a compatible version of google/jsonschema-go","Simplify the tool input type so the generated schema stays plain","Marshal the schema yourself in a test to reproduce and isolate the failing field"],"exampleFix":"// before\nschema, err := jsonschema.ForType(reflect.TypeOf(In{}), nil)\n// after — test the schema round-trips\nvar check map[string]any\nb, _ := json.Marshal(schema)\nif err := json.Unmarshal(b, &check); err != nil { /* simplify type */ }","handlingStrategy":"validation","validationCode":"schema, err := jsonschema.ForType(t, nil)\nif err == nil {\n\tif _, err := json.Marshal(schema); err != nil {\n\t\treturn fmt.Errorf(\"schema for %v not serializable: %w\", t, err)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Round-trip marshal/unmarshal generated schemas in tests","Avoid custom MarshalJSON on schema-affecting types returning exotic values","Pin a known-good google/jsonschema-go version","Keep tool input types plain"],"tags":["go","json","marshal","panic"],"backgroundTag":"json-marshal-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}