github/copilot-sdk · error

marshal elicitation schema property

Error message

marshal elicitation schema property %q: %w

What it means

For non-rpc property definitions, toRPCUIElicitationSchemaProperty json.Marshal's the property value before wrapping it in an object schema. If the value cannot be marshaled (e.g. contains channels, funcs, or cyclic references), the library returns this error naming the property. It indicates the caller supplied a property definition that is not JSON-representable.

Solutions

  1. Remove non-JSON-serializable values (funcs, channels, cycles) from the property definition
  2. Use plain map[string]any / tagged structs for property definitions
  3. Convert the property to rpc.UIElicitationSchemaProperty directly to bypass marshaling
  4. Test json.Marshal on your schema before invoking the UI method

Example fix

// before
props := map[string]any{"cb": func() {}} // unmarshalable
// after
props := map[string]any{"cb": map[string]any{"type": "string"}}
Defensive patterns

Strategy: validation

Validate before calling

for name, p := range schema.Properties {
    if _, err := json.Marshal(p); err != nil {
        return fmt.Errorf("property %q not JSON-encodable: %w", name, err)
    }
}

Try / catch

res, err := ui.Elicitation(ctx, msg, schema)
if err != nil && strings.Contains(err.Error(), "marshal elicitation schema property") {
    return fmt.Errorf("property is not JSON-serializable: %w", err)
}

Prevention

When it happens

Trigger: Passing an ElicitationSchema property whose value contains unmarshalable Go values (func, chan, cyclic pointer) instead of a plain map/struct or rpc.UIElicitationSchemaProperty.

Common situations: Embedding closures or callbacks in schema definitions by mistake; cyclic data structures built for defaults; using custom types without JSON tags in ways that fail encoding.

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/87fce6b79e84a28b. Report an issue: GitHub.

Appendix: source

Thrown at go/session.go:1219

	return rpc.UIElicitationSchema{
		Properties: properties,
		Required:   append([]string(nil), schema.Required...),
		Type:       rpc.UIElicitationSchemaTypeObject,
	}, nil
}

func toRPCUIElicitationSchemaProperty(name string, property any) (rpc.UIElicitationSchemaProperty, error) {
	if property == nil {
		return nil, fmt.Errorf("elicitation schema property %q is nil", name)
	}
	if rpcProperty, ok := property.(rpc.UIElicitationSchemaProperty); ok {
		return rpcProperty, nil
	}

	data, err := json.Marshal(property)
	if err != nil {
		return nil, fmt.Errorf("marshal elicitation schema property %q: %w", name, err)
	}
	wrapperData, err := json.Marshal(struct {
		Properties map[string]json.RawMessage  `json:"properties"`
		Type       rpc.UIElicitationSchemaType `json:"type"`
	}{
		Properties: map[string]json.RawMessage{name: data},
		Type:       rpc.UIElicitationSchemaTypeObject,
	})
	if err != nil {
		return nil, fmt.Errorf("marshal elicitation schema wrapper for property %q: %w", name, err)
	}

	var rpcSchema rpc.UIElicitationSchema
	if err := json.Unmarshal(wrapperData, &rpcSchema); err != nil {
		return nil, fmt.Errorf("decode elicitation schema property %q: %w", name, err)
	}
	rpcProperty, ok := rpcSchema.Properties[name]
	if !ok {

View on GitHub (pinned to cd8cf15dc3)