ory/kratos · error

unexpected node type

Error message

unexpected node type: %s

What it means

During node JSON deserialization (UnmarshalJSON in ui/node/node.go), the "type" discriminator is matched against known node types (e.g. Division, Script) to select the right Attributes struct. An unknown type string means the JSON carries a node type this version of the library does not implement, so it cannot build the corresponding attributes struct.

Solutions

  1. Upgrade the Ory client/SDK to a version matching (or newer than) the server that produced the payload.
  2. Log the reported node type and check the library's NodeType enum for the closest supported value.
  3. Fix typos in hand-written JSON fixtures so the type matches the enum exactly.
  4. As a stopgap, strip unknown nodes from the raw JSON before unmarshaling.

Example fix

// before (older SDK)
resp, _, _ := api.FrontendApi.GetRegistrationFlow(ctx, id) // node type "captcha" unknown
// after
// go get github.com/ory/kratos-client-go@latest  (supports the new node type)
Defensive patterns

Strategy: try-catch

Validate before calling

// Check the payload's node types against the SDK enum before unmarshaling:
var probe struct{ Nodes []struct{ Type string `json:"type"` } `json:"nodes"` }
_ = json.Unmarshal(raw, &probe)
for _, n := range probe.Nodes {
    if !isKnownNodeType(n.Type) { /* skip or upgrade SDK */ }
}

Type guard

func isKnownNodeType(t string) bool {
    switch ui.NodeType(t) {
    case ui.Text, ui.Image, ui.Input, ui.Anchor, ui.Script, ui.Division:
        return true
    }
    return false
}

Try / catch

if err := json.Unmarshal(data, &flow); err != nil {
    if strings.Contains(err.Error(), "unexpected node type") {
        log.Warn("server sent unknown UI node type; upgrade SDK", "err", err)
        // fall back to raw JSON handling or skip nodes
    }
}

Prevention

When it happens

Trigger: Unmarshaling a message/flow payload whose nodes contain a "type" value that this library version does not recognize — typically produced by a newer Ory server (new UI node types like text, image, input variants) while the client SDK is older.

Common situations: SDK version lagging behind the Kratos server version after an upgrade; hand-edited or fixture JSON with a typo in the node type; custom node types injected by an Ory Network update.

Related errors


AI-assisted analysis of ory/kratos@b86338da04 (2026-09-07). Data as JSON: /api/errors/f65d1d5cef451c13. Report an issue: GitHub.

Appendix: source

Thrown at ui/node/node.go:521

		}
	case Anchor:
		attr = &AnchorAttributes{
			NodeType: Anchor,
		}
	case Image:
		attr = &ImageAttributes{
			NodeType: Image,
		}
	case Script:
		attr = &ScriptAttributes{
			NodeType: Script,
		}
	case Division:
		attr = &DivisionAttributes{
			NodeType: Division,
		}
	default:
		return fmt.Errorf("unexpected node type: %s", t)
	}

	var d jsonRawNode
	d.Attributes = attr
	if err := json.NewDecoder(bytes.NewReader(data)).Decode(&d); err != nil {
		return err
	}

	*n = Node(d)

	if n.Meta == nil {
		n.Meta = new(Meta)
	}

	return nil
}

func (n *Node) MarshalJSON() ([]byte, error) {

View on GitHub (pinned to b86338da04)