Skip to content

feat: replace MeaningUnitAspect enum with open-ended str#206

Open
asteier2026 wants to merge 2 commits into
mainfrom
asteier2026/feature/meaning-unit-aspect-str
Open

feat: replace MeaningUnitAspect enum with open-ended str#206
asteier2026 wants to merge 2 commits into
mainfrom
asteier2026/feature/meaning-unit-aspect-str

Conversation

@asteier2026

@asteier2026 asteier2026 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Drops the MeaningUnitAspect enum from EntityDispositionSchema and schemas/__init__.py
  • Changes MeaningUnitSchema.aspect from MeaningUnitAspect to str
  • Updates tests to use string literals instead of enum values

Motivation

The enum was causing record loss: the model returns open-ended aspect values like "goal", "symptom", "diagnosis" that can't be exhaustively enumerated. Validation errors were silently dropping records.

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 <noreply@anthropic.com>
Signed-off-by: asteier2026 <asteier@nvidia.com>
@asteier2026 asteier2026 requested a review from a team as a code owner July 2, 2026 15:51
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the closed MeaningUnitAspect enum with an open-ended str field on MeaningUnitSchema.aspect, addressing silent record loss caused by the model returning aspect values outside the fixed enum set. It also adds Field(min_length=1) to both MeaningUnitSchema.aspect and QualityQAItemSchema.aspect.

  • Drops the 16-value MeaningUnitAspect enum entirely; aspect is now a validated str with min_length=1 on both schemas.
  • Removes MeaningUnitAspect from the public __all__ export and from test stubs.
  • MeaningUnitImportance remains a 2-value closed enum (\"critical\" / \"important\") on both MeaningUnitSchema and QualityQAItemSchema, leaving the same category of silent-drop risk unaddressed for that field.

Confidence Score: 4/5

Safe to merge for the aspect fix, but the importance field on both MeaningUnitSchema and QualityQAItemSchema remains a 2-value closed enum that can still silently drop records for the same reason the PR was written.

The PR correctly opens up aspect validation, but MeaningUnitImportance is still a closed 2-value enum on both schemas. Any LLM response with an importance value outside 'critical'/'important' will cause a Pydantic validation failure and silently drop the record — the exact failure mode the PR's motivation describes.

src/anonymizer/engine/schemas/rewrite.py — the MeaningUnitImportance enum and its usage in both MeaningUnitSchema and QualityQAItemSchema warrants a second look.

Important Files Changed

Filename Overview
src/anonymizer/engine/schemas/rewrite.py Removes MeaningUnitAspect enum and changes aspect to str with min_length=1; also adds min_length=1 to QualityQAItemSchema.aspect. MeaningUnitImportance remains a 2-value closed enum on both schemas, leaving the same silent-drop risk the PR claims to fix.
src/anonymizer/engine/schemas/init.py Removes MeaningUnitAspect from imports and all; straightforward cleanup with no issues.
tests/engine/test_qa_generation.py Replaces enum references with string literals in test stubs; correctly mirrors the schema change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[LLM returns MeaningUnit JSON] --> B{aspect value}
    B -->|any non-empty string| C[✅ MeaningUnitSchema validates OK\naspect: str with min_length=1]
    B -->|empty string| D[❌ ValidationError — record dropped]

    C --> E{importance value}
    E -->|'critical' or 'important'| F[✅ MeaningUnitImportance enum matches]
    E -->|anything else e.g. 'low', 'moderate'| G[❌ ValidationError — record still silently dropped]

    F --> H[Record persisted]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[LLM returns MeaningUnit JSON] --> B{aspect value}
    B -->|any non-empty string| C[✅ MeaningUnitSchema validates OK\naspect: str with min_length=1]
    B -->|empty string| D[❌ ValidationError — record dropped]

    C --> E{importance value}
    E -->|'critical' or 'important'| F[✅ MeaningUnitImportance enum matches]
    E -->|anything else e.g. 'low', 'moderate'| G[❌ ValidationError — record still silently dropped]

    F --> H[Record persisted]
Loading

Reviews (2): Last reviewed commit: "fix: add min_length=1 to MeaningUnitSche..." | Re-trigger Greptile

Comment thread src/anonymizer/engine/schemas/rewrite.py Outdated
…hema.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 <noreply@anthropic.com>
Signed-off-by: asteier2026 <asteier@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant