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;import io.cratis.chronicle.compliance.Piiimport io.cratis.chronicle.compliance.Pii;# No explicit import is required. `pii/1,2` becomes available automatically# from `use Cratis.Chronicle.Events.EventType` or `use Cratis.Chronicle.ReadModels.ReadModel`,# and `pii/0,1` becomes available automatically from `use Cratis.Chronicle.Concept`.import { pii } from '@cratis/chronicle';Adding PII to an existing event type
Section titled “Adding PII to an existing event type”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.
Marker signatures
Section titled “Marker signatures”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 = "")
// TypeScriptexport function pii(details?: string): PropertyDecorator & ClassDecorator
// Elixirdefmacro 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);import io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAs
@Pii(description = "Collected under GDPR Art. 6(1)(b) — necessary for contract performance")data class PiiAttrPersonName(val value: String) : ConceptAs<String> { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;
@Pii(description = "Collected under GDPR Art. 6(1)(b) — necessary for contract performance")record PiiAttrPersonName(String value) implements ConceptAs<String> {}defmodule MyApp.Compliance.Pii.PersonNameWithDetails do use Cratis.Chronicle.Concept, type: :string pii("Collected under GDPR Art. 6(1)(b) — necessary for contract performance")endimport { pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii('Collected under GDPR Art. 6(1)(b) — necessary for contract performance')class PiiAttrPersonName extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}C# classification properties
Section titled “C# classification properties”PIIAttribute also accepts three optional named properties:
SpecialCategory: one GDPR Article 9 category, such asSpecialCategory.Health; defaults toSpecialCategory.None.Criminal: personal data relating to criminal convictions and offenses under GDPR Article 10; defaults tofalse.OperationalSecret: the personal value is also an operational secret; defaults tofalse.
using Cratis.Chronicle.Compliance.GDPR;using Cratis.Concepts;
[PII(SpecialCategory = SpecialCategory.Health)]public record MedicalCondition(string Value) : ConceptAs<string>(Value);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].
Where you can mark PII
Section titled “Where you can mark PII”| 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
PiiNotSupportedOnEventSourceIdwhen@Piiis applied to a subclass ofEventSourceId. - Elixir raises an
ArgumentErrorat compile time whenpii/0,1is declared on a concept withevent_source_id: true. - TypeScript throws
PIINotSupportedOnEventSourceIdwhen@pii()is applied to a property namedeventSourceId, 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.
Applying to an event property
Section titled “Applying to an event property”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.chronicle.events.EventType
@EventTypedata class PiiAttrEmployeeRegistered( @Pii val firstName: String, @Pii val lastName: String, val department: String)import io.cratis.chronicle.compliance.Pii;import io.cratis.chronicle.events.EventType;
@EventTyperecord PiiAttrEmployeeRegistered( @Pii String firstName, @Pii String lastName, String department) {}defmodule MyApp.Events.PiiAttrEmployeeRegistered do use Cratis.Chronicle.Events.EventType, id: "pii-attr-employee-registered"
defstruct [:first_name, :last_name, :department]
pii(:first_name) pii(:last_name)endimport { eventType, pii } from '@cratis/chronicle';
@eventType()class PiiAttrEmployeeRegistered { @pii() firstName = ''; @pii() lastName = ''; department = '';}When this event is written, FirstName and LastName are encrypted. Department is stored as plaintext.
Applying to a ConceptAs type
Section titled “Applying to a ConceptAs type”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);}import io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAs
@Piidata class PiiAttrConceptPersonName(val value: String) : ConceptAs<String> { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;
@Piirecord PiiAttrConceptPersonName(String value) implements ConceptAs<String> {}defmodule MyApp.Compliance.Pii.PersonName do use Cratis.Chronicle.Concept, type: :string pii()endimport { pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii()class PiiAttrConceptPersonName extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}Applying to a value object
Section titled “Applying to a value object”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);import io.cratis.chronicle.compliance.Pii
// Every value this type holds is personal, so mark the type once.@Piidata class PiiAttrDiagnosis(val condition: String, val diagnosedBy: String)
// Both condition and diagnosedBy are encrypted wherever a PiiAttrDiagnosis appears.data class PiiAttrPatientRecord(val name: String, val diagnosis: PiiAttrDiagnosis)import io.cratis.chronicle.compliance.Pii;
// Every value this type holds is personal, so mark the type once.@Piirecord PiiAttrDiagnosis(String condition, String diagnosedBy) {}
// Both condition and diagnosedBy are encrypted wherever a PiiAttrDiagnosis appears.record PiiAttrPatientRecord(String name, PiiAttrDiagnosis diagnosis) {}Elixir does not support this workflow yet.import { pii } from '@cratis/chronicle';
// Every value this type holds is personal, so mark the type once.@pii()class PiiAttrDiagnosis { condition = ''; diagnosedBy = '';}
// Both condition and diagnosedBy are encrypted wherever a PiiAttrDiagnosis appears.class PiiAttrPatientRecord { name = ''; diagnosis: PiiAttrDiagnosis = new PiiAttrDiagnosis();}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.
Nesting
Section titled “Nesting”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAs
@Piidata class PiiAttrDateOfBirth(val value: String) : ConceptAs<String> { override fun value(): String = value}
// The concept sits one level down, inside a value object.data class PiiAttrVerifiedDateOfBirth(val dateOfBirth: PiiAttrDateOfBirth, val verifiedBy: String)
// Chronicle still finds it: dateOfBirth.dateOfBirth is encrypted, verifiedBy is not.data class PiiAttrExpressVerification(val name: String, val dateOfBirth: PiiAttrVerifiedDateOfBirth)import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;
@Piirecord PiiAttrDateOfBirth(String value) implements ConceptAs<String> {}
// The concept sits one level down, inside a value object.record PiiAttrVerifiedDateOfBirth(PiiAttrDateOfBirth dateOfBirth, String verifiedBy) {}
// Chronicle still finds it: dateOfBirth.dateOfBirth is encrypted, verifiedBy is not.record PiiAttrExpressVerification(String name, PiiAttrVerifiedDateOfBirth dateOfBirth) {}defmodule MyApp.Compliance.Pii.DateOfBirth do use Cratis.Chronicle.Concept, type: :string pii()end
# The concept sits one level down, inside a plain (non-concept) value object.defmodule MyApp.Compliance.Pii.VerifiedDateOfBirth do defstruct date_of_birth: %MyApp.Compliance.Pii.DateOfBirth{}, verified_by: ""end
# Chronicle still finds it: dateOfBirth.dateOfBirth is encrypted, verifiedBy is not.defmodule MyApp.Compliance.Pii.ExpressVerification do use Cratis.Chronicle.Events.EventType, id: "pii-express-verification" defstruct name: "", date_of_birth: %MyApp.Compliance.Pii.VerifiedDateOfBirth{}endimport { pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii()class PiiAttrDateOfBirth extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}
// The concept sits one level down, inside a value object.class PiiAttrVerifiedDateOfBirth { dateOfBirth: PiiAttrDateOfBirth = new PiiAttrDateOfBirth(''); verifiedBy = '';}
// Chronicle still finds it: dateOfBirth.dateOfBirth is encrypted, verifiedBy is not.class PiiAttrExpressVerification { name = ''; dateOfBirth: PiiAttrVerifiedDateOfBirth = new PiiAttrVerifiedDateOfBirth();}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.
PII on referenced schema definitions
Section titled “PII on referenced schema definitions”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.
Constraints
Section titled “Constraints”EventSourceId is not supported
Section titled “EventSourceId is not supported”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.chronicle.concepts.EventSourceId
// This will throw PiiNotSupportedOnEventSourceId@Piidata class PiiAttrEmployeeId(val value: String) : EventSourceId { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.chronicle.concepts.EventSourceId;
// This will throw PiiNotSupportedOnEventSourceId@Piirecord PiiAttrEmployeeId(String value) implements EventSourceId {}# Raises ArgumentError at compile time — PII is not supported on a# Cratis.Chronicle.Concept declared with event_source_id: true.## defmodule MyApp.Compliance.Pii.EmployeeId do# use Cratis.Chronicle.Concept, type: :uuid, event_source_id: true# pii()# endimport { pii } from '@cratis/chronicle';
// TypeScript has no dedicated EventSourceId<T> type - the event source identifier is always// the conventional 'eventSourceId' property. Marking it @pii() throws// PIINotSupportedOnEventSourceId at decoration time, for the same reason C# forbids [PII] on// EventSourceId<T>: encrypting it would make its own decryption key unfindable.class PiiAttrEmployeeId { @pii() eventSourceId = '';}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.
Geospatial values are not looked inside
Section titled “Geospatial values are not looked inside”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.
Collections are encrypted as a whole
Section titled “Collections are encrypted as a whole”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.
Details parameter
Section titled “Details parameter”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);import io.cratis.chronicle.compliance.Piiimport io.cratis.fundamentals.concepts.ConceptAs
@Pii(description = "Full legal name — required for contract identification")data class PiiAttrLegalName(val value: String) : ConceptAs<String> { override fun value(): String = value}import io.cratis.chronicle.compliance.Pii;import io.cratis.fundamentals.concepts.ConceptAs;
@Pii(description = "Full legal name — required for contract identification")record PiiAttrLegalName(String value) implements ConceptAs<String> {}defmodule MyApp.Compliance.Pii.LegalName do use Cratis.Chronicle.Concept, type: :string pii("Full legal name — required for contract identification")endimport { pii } from '@cratis/chronicle';import { ConceptAs } from '@cratis/fundamentals';
@pii('Full legal name — required for contract identification')class PiiAttrLegalName extends ConceptAs<string> { static readonly valueType = String;
constructor(value: string) { super(value); }}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.
Strict compliance release
Section titled “Strict compliance release”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.