Skip to content

Add required_slots to drop an object whose required slot comes out empty - #418

Merged
amc-corey-cox merged 4 commits into
mainfrom
required-slots
Dec 4, 2026
Merged

amc-corey-cox merged 4 commits into
mainfrom
required-slots

Conversation

@amc-corey-cox

Copy link
Copy Markdown
Contributor

A class derivation maps every row to an object, even when the slots that make the object meaningful come out empty. A Condition whose 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 a filter_rows that restates the slot's value_mappings keys, which goes stale silently when the mappings change.

required_slots names the slots that must have a value once derived:

Condition:
  populated_from: answers
  required_slots: [status]
  • An object is dropped when any named slot is None or an empty list. It works at the top level and on nested class derivations.
  • The check runs after derivation, so a value_if_missing / value_if_unmapped fill counts as a value, and a hidden slot can be required.
  • A parent that requires the slot holding its nested objects is dropped when none is left, which covers the blood-pressure set in Let a spec declare which slots make a record non-empty (required_slots / on_missing) #264.
  • validate-spec rejects a name that isn't one of the class derivation's slot derivations.
  • map-data warns when required_slots kept none of a class derivation's objects, as it does for filter_rows.

The on_missing option 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

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
Copilot AI balanced review requested due to automatic review settings December 3, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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_slots runtime behavior to drop derived objects when any required slot is None or an empty list, including nested/cascading suppression.
  • Add validate-spec checks to ensure required_slots references valid slot derivations, plus map-data warnings when required_slots keeps 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.

Comment thread src/linkml_map/validator.py Resolved
Copilot AI balanced review requested due to automatic review settings December 4, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI balanced review requested due to automatic review settings December 4, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Copilot AI balanced review requested due to automatic review settings December 4, 2026 22:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@amc-corey-cox
amc-corey-cox merged commit 9a8d2e3 into main Dec 4, 2026
8 checks passed
@amc-corey-cox
amc-corey-cox deleted the required-slots branch December 4, 2026 22:38
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.

2 participants