Repository navigation
Add required_slots to drop an object whose required slot comes out empty - #418
Conversation
A class derivation names the slots that must have a value once derived. An object missing any of them is not emitted, at the top level or nested, so a record kept non-empty only by its id and constants is no longer written. Part of #264
There was a problem hiding this comment.
🟡 Changes recommended
Outstanding moderate findings indicate the transformer’s required_counts tracking can conflate nested derivations that share a class name and the validator’s required_slots check can wrongly reject inherited slot derivations, risking inaccurate warnings and incorrect spec validation.
2 open issues
What changed in this PR
Adds an opt-in required_slots feature on class derivations to suppress emitting “hollow” derived objects when specified meaningful slots end up empty after derivation, preventing downstream target-schema validation failures.
Changes:
- Implement
required_slotsruntime behavior to drop derived objects when any required slot isNoneor an empty list, including nested/cascading suppression. - Add
validate-specchecks to ensurerequired_slotsreferences valid slot derivations, plusmap-datawarnings whenrequired_slotskeeps none. - Update transformer datamodel, CLI messaging, documentation, and add tests covering top-level and nested behavior.
| File | Description |
|---|---|
| tests/test_transformer/test_required_slots.py | Adds test coverage for required_slots dropping behavior (top-level and nested), cascading suppression, validation, and warning/reporting behavior. |
| src/linkml_map/validator.py | Extends semantic validation so required_slots entries are checked against the declared slot-derivation names for a class derivation. |
| src/linkml_map/transformer/transformer.py | Introduces tracking/aggregation to support end-of-run warnings when required-slot enforcement drops all objects for a derivation. |
| src/linkml_map/transformer/object_transformer.py | Implements post-derivation enforcement of required_slots to drop objects with empty required values and records counts for warning summaries. |
| src/linkml_map/datamodel/transformer_model.yaml | Adds the required_slots field to the LinkML transformer datamodel schema with documentation of its intent and semantics. |
| src/linkml_map/datamodel/transformer_model.py | Updates the generated Python/Pydantic transformer models to include the new required_slots attribute on ClassDerivation. |
| src/linkml_map/cli/cli.py | Updates CLI output to warn when required_slots filters out all objects for a class derivation, similar to existing filtering warnings. |
| docs/writing-specs.md | Documents how to use required_slots, including rationale and guidance vs. filter_rows. |
| docs/schema/slots/required_slots.md | Adds generated schema documentation for the new required_slots slot. |
| docs/schema/datamodel.md | Updates the generated datamodel documentation to include required_slots in the slot index. |
| docs/schema/classes/ClassDerivation.md | Updates generated ClassDerivation documentation to include the required_slots option and description. |
Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
There was a problem hiding this comment.
🔵 Needs a closer look
Approval is blocked because the review evidence identifies two moderate, active correctness issues in required-slots handling—one where counters are keyed too coarsely across multiple derivation instances and another where validation rejects inherited slot derivations that runtime mapping accepts.
2 open issues
Review effort: Balanced
There was a problem hiding this comment.
🟢 Approval recommended
The change adds a focused new capability (required_slots) with corresponding validation, runtime enforcement, warnings, and comprehensive tests/documentation updates, with no review evidence of unresolved issues.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🟢 Approval recommended
The change adds the required_slots feature across the spec schema, transformer/validator logic, CLI/docs, and includes comprehensive new tests for dropping, cascading, validation, and warning behavior, with no review evidence of unresolved problems.
No open issues 🎉
Review effort: Balanced

A class derivation maps every row to an object, even when the slots that make the object meaningful come out empty. A
Conditionwhose status didn't map is still written with its id and constants, and the target schema then rejects it. The only way to stop that today is afilter_rowsthat restates the slot'svalue_mappingskeys, which goes stale silently when the mappings change.required_slotsnames the slots that must have a value once derived:value_if_missing/value_if_unmappedfill counts as a value, and a hidden slot can be required.validate-specrejects a name that isn't one of the class derivation's slot derivations.map-datawarns whenrequired_slotskept none of a class derivation's objects, as it does forfilter_rows.The
on_missingoption proposed in #264 is left out: dropping the object is the only behaviour with a use so far, and setting the field is already the opt-in.Part of #264