Skip to content

Cratis Chronicle PII classification and encryption

Cratis Chronicle encrypts personally identifiable information (PII) when you mark the values in the event schema. Use a C# [PII] attribute, Kotlin/Java @Pii annotation, TypeScript @pii() decorator or Elixir pii macro to declare which values need subject-key protection. The kernel encrypts them on append and releases, or decrypts, them on read.

For a reusable personal value, put the declaration on its concept type. For a single field, mark the property. In .NET, a marker on a composite value object reaches its declared leaf values: the individual values inside the object, rather than the object container. Collections have a different boundary, described below.

PII declarations classify data; they do not authorize reads or establish GDPR compliance. Adding a declaration does not encrypt historical plaintext, and erasing a key cannot remove that plaintext or independently retained copies.

using Cratis.Chronicle.Compliance.GDPR;

View C# snippet source on GitHub

You may add [PII] to a property in an existing generation without introducing a new generation. The kernel accepts the added compliance metadata and logs a warning naming the event type, generation and schema property path. Adding [Encrypted] security metadata follows the same rule. Removing or changing existing protection metadata within that generation is refused.

Only subsequent appends use the new encryption policy. Earlier values remain plaintext and remain readable even after the subject’s encryption keys are erased. A schema update does not rewrite history, and introducing a new generation does not encrypt the original stored generation either.

If historical plaintext must no longer be available, redact those events. Treat the registration warning as a prompt to review the existing history, not as confirmation that it has been protected. During a rolling deployment, writers must retain protection metadata once it has been registered; an older writer without it is refused.

The marker, in each client:

// C#
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Parameter)]
public sealed class PIIAttribute(string details = "") : Attribute
// Kotlin / Java
@Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class Pii(val description: String = "")
// TypeScript
export function pii(details?: string): PropertyDecorator & ClassDecorator
// Elixir
defmacro pii(field, details \\ "")

The optional text records why the value is classified as personal. It is stored in the schema as documentation, not as an enforced retention policy or proof of a legal basis.

using Cratis.Chronicle.Compliance.GDPR;
[PII("Collected under GDPR Art. 6(1)(b) — necessary for contract performance")]
public record PiiAttrPersonName(string Value) : ConceptAs<string>(Value);

View C# snippet source on GitHub

PIIAttribute also accepts three optional named properties:

  • SpecialCategory: one GDPR Article 9 category, such as SpecialCategory.Health; defaults to SpecialCategory.None.
  • Criminal: personal data relating to criminal convictions and offenses under GDPR Article 10; defaults to false.
  • OperationalSecret: the personal value is also an operational secret; defaults to false.
using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Concepts;
[PII(SpecialCategory = SpecialCategory.Health)]
public record MedicalCondition(string Value) : ConceptAs<string>(Value);

View C# snippet source on GitHub

These properties classify only and add no protection. They are not added to schema metadata and do not change encryption or erasure. Subject encryption already covers an operational secret marked as PII; do not add [Encrypted], because Chronicle rejects combining [PII] and [Encrypted].

Target Supported Notes
ConceptAs<T> class Yes Preferred approach — marks the concept type itself as PII
Event property Yes Marks a single property of an event as PII
Value object class Yes Marks declared leaf values, within the constraints below
Property typed as a value object Yes Same effect, scoped to that one property
Collection property Yes The collection is encrypted as a whole — see Collections are encrypted as a whole
Geospatial (Point, LineString, Polygon) No Never classified inside, and marking one encrypts a value that cannot be materialized back after erasure — see Geospatial values are not looked inside
Polymorphic value or dictionary Schema-dependent Protection needs a schema for the values being stored; a dictionary can use classified additionalProperties
EventSourceId or EventSourceId<T> No Throws PIINotSupportedOnEventSourceId at runtime

The ConceptAs<T> and value-object rows describe .NET schema generation; check the generated schema for other clients. Event source identifier validation also differs:

  • Kotlin/Java throw PiiNotSupportedOnEventSourceId when @Pii is applied to a subclass of EventSourceId.
  • Elixir raises an ArgumentError at compile time when pii/0,1 is declared on a concept with event_source_id: true.
  • TypeScript throws PIINotSupportedOnEventSourceId when @pii() is applied to a property named eventSourceId, but not when an event-source identifier type is marked.

Keep identifiers non-sensitive and readable in every client, whether or not its validation catches a particular declaration.

You can mark a single property on an event record as PII. This is useful when the property type is a primitive and you cannot or do not want to introduce a dedicated concept type.

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
[EventType]
public record PiiAttrEmployeeRegistered(
[PII] string FirstName,
[PII] string LastName,
string Department);

View C# snippet source on GitHub

When this event is written, FirstName and LastName are encrypted. Department is stored as plaintext.

Mark a ConceptAs<T> type when its value is personal wherever it appears. The schema generator can then carry that classification to properties using the type without a repeated annotation. A property changed to an unmarked primitive loses that link.

using Cratis.Chronicle.Compliance.GDPR;
[PII]
public record PiiAttrConceptPersonName(string Value) : ConceptAs<string>(Value)
{
public static readonly PiiAttrConceptPersonName NotSet = new(string.Empty);
public static implicit operator string(PiiAttrConceptPersonName name) => name.Value;
public static implicit operator PiiAttrConceptPersonName(string value) => new(value);
}

View C# snippet source on GitHub

In .NET, mark a value object class when all its declared values are personal, such as the condition and clinician in a diagnosis. The schema generator applies the marker to those values wherever the type appears, without an annotation on each member.

using Cratis.Chronicle.Compliance.GDPR;
// Every value this type holds is personal, so mark the type once.
[PII]
public record PiiAttrDiagnosis(string Condition, string DiagnosedBy);
// Both Condition and DiagnosedBy are encrypted wherever a PiiAttrDiagnosis appears.
public record PiiAttrPatientRecord(string Name, PiiAttrDiagnosis Diagnosis);

View C# snippet source on GitHub

The marker reaches the individual values rather than encrypting the object as one blob. The stored Diagnosis sub-document retains its Condition and DiagnosedBy fields, each holding ciphertext. Keeping that shape allows release to restore the individual values for materialization into the value-object type.

The same happens when you mark a property whose type is a value object — the effect is identical, just scoped to that one property instead of to the type everywhere.

The marker does not have to sit at the top level. A ConceptAs<T> marked [PII] is found wherever it ends up — directly on an event, one level down inside a value object, or deeper still.

using Cratis.Chronicle.Compliance.GDPR;
[PII]
public record PiiAttrDateOfBirth(string Value) : ConceptAs<string>(Value)
{
public static implicit operator PiiAttrDateOfBirth(string value) => new(value);
}
// The concept sits one level down, inside a value object.
public record PiiAttrVerifiedDateOfBirth(PiiAttrDateOfBirth DateOfBirth, string VerifiedBy);
// Chronicle still finds it: dateOfBirth.dateOfBirth is encrypted, verifiedBy is not.
public record PiiAttrExpressVerification(string Name, PiiAttrVerifiedDateOfBirth DateOfBirth);

View C# snippet source on GitHub

Here only dateOfBirth.dateOfBirth is encrypted. verifiedBy sits beside it in the same value object and stays readable, because the concept carries the classification, not its container.

Keeping the concept type on nested properties lets the schema generator retain the classification as you compose events and read models. Check the resulting schema when converters or dynamic shapes are involved.

When a property’s schema is a $ref to a shared definition, a [PII] marker on that definition applies to the property. Chronicle uses the definition’s compliance metadata when it writes, releases and compares values.

Chronicle first resolves pointer references such as #/$defs/Name. If a reference does not resolve that way, it looks for an embedded $id resource or a $anchor in the same schema document. An anchor is scoped to the resource that declares it, so identically named anchors in different resources do not collide.

Chronicle never fetches external or remote references. A reference that does not resolve inside the document is left unresolved, and an unresolved reference is not treated as protected: only metadata on the property itself applies.

The referenced definition must have a single supported type. If it does not, Chronicle logs a warning, ignores the metadata on the definition and keeps the existing handling. It does not refuse the append.

In .NET, applying [PII] to a type that inherits from EventSourceId or EventSourceId<T> throws PIINotSupportedOnEventSourceId at runtime:

using Cratis.Chronicle.Compliance.GDPR;
using Cratis.Chronicle.Events;
// ❌ This will throw PIINotSupportedOnEventSourceId
[PII]
public record PiiAttrEmployeeId(Guid Value) : EventSourceId<Guid>(Value);

View C# snippet source on GitHub

Event source identifiers are used to look up encryption keys and group events. Encrypting them would make key lookup impossible. If the identifier itself is sensitive, use a non-sensitive surrogate (such as a random Guid) as the event source identifier and store the sensitive value in a [PII]-marked event property.

The compliance pass walks a document’s schema to find marked values, but it does not descend into the wire members of a geospatial value. Point, LineString and Polygon use GeoJSON objects with type and coordinates members; their schemas describe each as one formatted value handled by a converter.

An unmarked geospatial property remains in the clear even when a neighboring property carries [PII]. Do not assume that location data is public merely because it is unmarked. Marking the geospatial property itself is not a supported alternative for erasure: the erased value cannot be materialized back into that type. See Geospatial values alongside PII before storing personal location data.

A [PII] marker on a collection property encrypts the collection as one opaque value rather than element by element. Release restores its array shape while the key is available. After key erasure, the whole protected collection is empty, including any non-personal fields inside it. Individual elements of the stored ciphertext cannot be queried or indexed.

Choose the boundary you need before marking the collection. For a collection-wide boundary, mark the property. For member-level protection, leave the collection unmarked and classify the personal members in its item schema. When ownership belongs to separate people, consider person-scoped read models queried and composed after release.

The details parameter is a free-text description stored in the event schema. It is never used for encryption — it exists solely to record why a value is classified as PII for compliance documentation and auditing purposes.

using Cratis.Chronicle.Compliance.GDPR;
[PII("Full legal name — required for contract identification")]
public record PiiAttrLegalName(string Value) : ConceptAs<string>(Value);

View C# snippet source on GitHub

In .NET, non-empty [ComplianceDetails] text takes precedence over the text in [PII("…")]. Otherwise Chronicle uses the first non-empty PII details on the property, its matching constructor parameter, its declaring type, or its property type, in that order.

The compliance gRPC Release operation remains best-effort by default. Set ReleaseRequest.Strict to true to fail the entire release when a protected value cannot be decrypted or its subject’s key is missing without a recorded erasure. A failed strict release returns HasError = true, an empty Payload, and the failing property path in FailedProperties — never the value or a partially decrypted document. Traversal stops at the first failure, so this list is not an exhaustive inventory. Intentionally erased subjects still release to empty values without an error.

Check that ReleaseResponse.Strict is true before accepting a strict result. A server that does not support strict release ignores the request field and does not echo it; a false echo means strict release was not confirmed, even if HasError is false.

For projection storage and application query paths, continue with Read models and PII. It explains where release happens automatically and where you must request it yourself.