﻿# Unicode comparison keys need a chosen equivalence rule

An API comparison key needs an explicit Unicode equivalence rule; NFC, compatibility folding, visual confusability and canonical JSON serialization solve different problems.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-unicode-api-comparison-key/
Language: en

## Choose what equality means for the API field

A collection API accepts a user-visible label and later uses it to locate an existing collection. Text with a precomposed accented letter can be canonically equivalent to text using a base letter and combining mark. [Unicode normalization guidance](https://unicode.org/reports/tr15/) defines transformations for comparing such sequences. Decide whether this field's equality follows canonical equivalence, exact original code points or another documented identifier policy before using it as a lookup key.

## Separate canonical and compatibility equivalence

NFC preserves distinctions that compatibility normalization can fold, such as certain presentation variants. NFKC can be useful in a deliberately restricted identifier system, but it can also remove distinctions relevant to ordinary text. Do not silently adopt the broader equivalence because it appears to fix more mismatches. The chosen relation determines which previously different labels can collide and whether changing the policy requires migration of existing collection keys.

## Keep display text and comparison keys distinct

Preserve the original label when its spelling or presentation matters, and derive a comparison key through the documented normalization policy. Apply that policy consistently when registering a collection and resolving a later request. If storage compares one form while an API gateway compares another, a successful local lookup does not establish consistent identity across the application. [Progressive reading](/journal/learn-codex-progressive-reading/) helps trace where those keys are actually constructed and compared.

## Do not equate appearance with normalization

[Unicode security guidance](https://unicode.org/reports/tr39/) treats visually confusable identifiers as a separate concern. Normalization is not a universal rule that makes every similar-looking label identical, nor does equivalent normalization prove an identifier is appropriate for a particular security context. Specify any additional script or confusable policy independently. That keeps ordinary equality decisions from acquiring undocumented assumptions about visual appearance or the caller's intended collection.

## Preserve protocol-specific serialization boundaries

The [JSON canonicalization specification](https://www.rfc-editor.org/rfc/rfc8785.html) requires string data to remain as-is rather than perform Unicode normalization implicitly. An application comparison key should not be confused with the bytes or strings a signing protocol requires preserved. [Task contracts](/journal/learn-codex-task-contract/) can name both values and their purpose. A clear implementation explains which original value was received, which key was compared and which representation was serialized, avoiding a blanket transformation that changes identity and protocol behavior together.
