From f6131bd3b8f649c518b2e0ccdb2c819c67a73cd7 Mon Sep 17 00:00:00 2001 From: asteier2026 Date: Thu, 2 Jul 2026 08:44:08 -0700 Subject: [PATCH 1/2] feat: replace MeaningUnitAspect enum with open-ended str The enum was causing record loss when the model returned values like "goal" or "symptom" that weren't enumerated. Aspect is now an unvalidated str to accommodate open-ended LLM output. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: asteier2026 --- src/anonymizer/engine/schemas/__init__.py | 2 -- src/anonymizer/engine/schemas/rewrite.py | 23 ++--------------------- tests/engine/test_qa_generation.py | 5 ++--- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/anonymizer/engine/schemas/__init__.py b/src/anonymizer/engine/schemas/__init__.py index 96607d66..bc99215d 100644 --- a/src/anonymizer/engine/schemas/__init__.py +++ b/src/anonymizer/engine/schemas/__init__.py @@ -34,7 +34,6 @@ EntityCategory, EntityDispositionSchema, EntitySource, - MeaningUnitAspect, MeaningUnitImportance, MeaningUnitSchema, MeaningUnitsSchema, @@ -90,7 +89,6 @@ "EntityCategory", "EntityDispositionSchema", "EntitySource", - "MeaningUnitAspect", "MeaningUnitImportance", "MeaningUnitSchema", "MeaningUnitsSchema", diff --git a/src/anonymizer/engine/schemas/rewrite.py b/src/anonymizer/engine/schemas/rewrite.py index 912281dd..646a630f 100644 --- a/src/anonymizer/engine/schemas/rewrite.py +++ b/src/anonymizer/engine/schemas/rewrite.py @@ -33,7 +33,7 @@ Uses LLMJudgeColumnConfig with Score rubrics (no custom schema needed) Supporting enums: Domain, EntitySource, EntityCategory, SensitivityLevel, - ProtectionMethod, CombinedRiskLevel, MeaningUnitAspect, PrivacyAnswer + ProtectionMethod, CombinedRiskLevel, PrivacyAnswer """ from __future__ import annotations @@ -249,25 +249,6 @@ class StrictSensitivityDispositionSchema(SensitivityDispositionSchema): # --------------------------------------------------------------------------- -class MeaningUnitAspect(str, Enum): - ROLE = "role" - PROCESS = "process" - RELATIONSHIP = "relationship" - ENVIRONMENT = "environment" - ROUTINE = "routine" - CREATIVE_OUTPUT = "creative_output" - VALUE = "value" - MOTIVATION = "motivation" - INFLUENCE = "influence" - AUDIENCE = "audience" - LEGAL_BASIS = "legal_basis" - INSTITUTION = "institution" - JUSTIFICATION = "justification" - PROCEDURAL_STATUS = "procedural_status" - TEMPORAL_SEQUENCE = "temporal_sequence" - RIGHTS_IMPACT = "rights_impact" - - class MeaningUnitImportance(str, Enum): critical = "critical" important = "important" @@ -275,7 +256,7 @@ class MeaningUnitImportance(str, Enum): class MeaningUnitSchema(BaseModel): id: int = Field(ge=1) - aspect: MeaningUnitAspect + aspect: str unit: str = Field(min_length=1) importance: MeaningUnitImportance diff --git a/tests/engine/test_qa_generation.py b/tests/engine/test_qa_generation.py index 74831f9d..da2cc5a5 100644 --- a/tests/engine/test_qa_generation.py +++ b/tests/engine/test_qa_generation.py @@ -34,7 +34,6 @@ EntityCategory, EntityDispositionSchema, EntitySource, - MeaningUnitAspect, MeaningUnitImportance, MeaningUnitSchema, MeaningUnitsSchema, @@ -75,13 +74,13 @@ units=[ MeaningUnitSchema( id=1, - aspect=MeaningUnitAspect.ROLE, + aspect="role", unit="An individual works as a software engineer.", importance=MeaningUnitImportance.critical, ), MeaningUnitSchema( id=2, - aspect=MeaningUnitAspect.ENVIRONMENT, + aspect="environment", unit="The individual works remotely.", importance=MeaningUnitImportance.important, ), From 212a478a966b81e639f3fc13e9a71bb4d254ba11 Mon Sep 17 00:00:00 2001 From: asteier2026 Date: Thu, 2 Jul 2026 08:57:13 -0700 Subject: [PATCH 2/2] fix: add min_length=1 to MeaningUnitSchema.aspect and QualityQAItemSchema.aspect Empty strings are structurally valid but semantically meaningless; guard against them consistently with the other non-id string fields in these schemas. Co-Authored-By: Claude Sonnet 4.6 Signed-off-by: asteier2026 --- src/anonymizer/engine/schemas/rewrite.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/anonymizer/engine/schemas/rewrite.py b/src/anonymizer/engine/schemas/rewrite.py index 646a630f..770d0c93 100644 --- a/src/anonymizer/engine/schemas/rewrite.py +++ b/src/anonymizer/engine/schemas/rewrite.py @@ -256,7 +256,7 @@ class MeaningUnitImportance(str, Enum): class MeaningUnitSchema(BaseModel): id: int = Field(ge=1) - aspect: str + aspect: str = Field(min_length=1) unit: str = Field(min_length=1) importance: MeaningUnitImportance @@ -275,7 +275,7 @@ class MeaningUnitsSchema(BaseModel): class QualityQAItemSchema(BaseModel): id: int - aspect: str + aspect: str = Field(min_length=1) importance: MeaningUnitImportance question: str reference_answer: str