Skip to content

Conversation

@wiebe-vandendriessche
Copy link

@wiebe-vandendriessche wiebe-vandendriessche commented Nov 18, 2025

feat: Add support for Component modelCard field

Summary

Linked Issues

Closes: #912
Part of [TRACKING] Complete support for CycloneDX v1.5: #578
Follow-up: #913

Changes

  • Model types: ModelCard, ModelParameters, QuantitativeAnalysis, PerformanceMetric, GraphicsCollection, ConfidenceInterval.
  • Considerations: Considerations, EthicalConsideration, FairnessAssessment.
  • Environmental (1.6+): EnvironmentalConsiderations, EnergyConsumption, EnergyProvider, EnergyMeasure, Co2Measure, enums EnergyActivity, EnergySource.
  • Component integration: Component.model_card (1.5+).
  • Datasets gating:

Schema Compatibility

  • 1.5: modelCard with modelParameters, quantitativeAnalysis, considerations.
  • 1.6–1.7: adds environmentalConsiderations and energy/CO2/provider types.

Tests

  • New test_model_model_card.py:
    • Basic 1.5 JSON/XML serialization.
    • 1.6 environmental considerations JSON/XML.
    • Full 1.7 “rich” card including providers with bom-ref.
    • Ordering/equality for approaches, IO params, providers, consumptions.
  • All tests pass locally.

Follow-ups

Breaking Changes

  • None in existing APIs. A NotImplementedError is raised only if modelParameters.datasets is supplied, intentionally preventing invalid output.

Validate modelCard locally

poetry run pytest -q tests/test_model_model_card.py

…formance metrics

Signed-off-by: Wiebe Vandendriessche <[email protected]>
…al considerations (`modelParameters.datasets` remains a staged placeholder until CycloneDX#913)

Signed-off-by: Wiebe Vandendriessche <[email protected]>
@wiebe-vandendriessche wiebe-vandendriessche requested a review from a team as a code owner November 18, 2025 14:24
@jkowalleck jkowalleck added enhancement New feature or request schema 1.5 labels Nov 20, 2025
Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

@jkowalleck jkowalleck requested a review from Copilot November 20, 2025 13:10
Copilot finished reviewing on behalf of jkowalleck November 20, 2025 13:12
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive support for the modelCard field on CycloneDX components, enabling machine learning model documentation including parameters, performance metrics, ethical considerations, and environmental impact tracking.

Key changes:

  • Introduces complete ModelCard type hierarchy including parameters, quantitative analysis, and considerations
  • Adds environmental impact tracking with energy consumption and CO2 measurements (v1.6+)
  • Temporarily gates modelParameters.datasets field with validation that raises NotImplementedError until shared component data support (#913) is implemented

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 18 comments.

File Description
cyclonedx/model/model_card.py Defines comprehensive ModelCard type system including 20+ classes for ML model documentation, energy tracking, and ethical considerations with proper schema versioning (1.5-1.7)
cyclonedx/model/component.py Integrates model_card property into Component class with proper serialization annotations and comparable tuple support
tests/test_model_model_card.py Provides extensive test coverage including schema validation for v1.5-1.7, sorting behavior, equality checks, and version-specific feature gating

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wiebe-vandendriessche
Copy link
Author

Please also add a sufficient data model to https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/tests/_data/models.py

Is there documentation on how this works?

@jkowalleck
Copy link
Member

jkowalleck commented Nov 21, 2025

Please also add a sufficient data model to https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/tests/_data/models.py

Is there documentation on how this works?

not yet. We would be happy to see a dedicated pull-request that improves the documentation.

in your case, you would create a BOM with just one bare component and a complete modelCard with every property filled.

the system works like this:

@wiebe-vandendriessche
Copy link
Author

Please also add a sufficient data model to https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/tests/_data/models.py

Is there documentation on how this works?

not yet. We would be happy to see a dedicated pull-request that improves the documentation.
...

Ok, i'll take a look for this!

In the meantime i have encountered an issue regarding ModelCard.properties.

It seems like ModelCard.properties validates in JSON but is rejected by XML.

I tried to add top-level properties to ModelCard:

properties=[
    Property(name='release', value='2024-01-01'),
    Property(name='stability', value='experimental'),
]

JSON (1.7) validates successfully.
XML (1.7) fails schema validation with “Element … properties is not expected” under .

Can you confirm the XML spec indeed does not have ModelCard.properties?
And if so, is the JSON/XML asymmetry for modelCard.properties intentional in 1.5–1.7?

How should we handle this in the code? Because right now it's not possible to add custom properties in a ModelCard.

(however other classes inside the modelCard also have a "properties" field e.g. EnvironmentalConsiderations, and this does fully work)

@jkowalleck
Copy link
Member

Can you confirm the XML spec indeed does not have ModelCard.properties?

can confirm.

JSON: https://cyclonedx.org/docs/1.7/json/#components_items_modelCard_properties
XML: https://cyclonedx.org/docs/1.7/xml/#type_modelCardType

And if so, is the JSON/XML asymmetry for modelCard.properties intentional in 1.5–1.7?

nope. it a bug. thanks for reporting - caused CycloneDX/specification#726

@wiebe-vandendriessche
Copy link
Author

Can you confirm the XML spec indeed does not have ModelCard.properties?

can confirm.

JSON: https://cyclonedx.org/docs/1.7/json/#components_items_modelCard_properties XML: https://cyclonedx.org/docs/1.7/xml/#type_modelCardType

And if so, is the JSON/XML asymmetry for modelCard.properties intentional in 1.5–1.7?

nope. it a bug. thanks for reporting - caused CycloneDX/specification#726

Good to know! What should I do in the meantime? Should we merge this pull request with a temporary solution that just disables ModelCard.properties (both json and xml) untill that issue in the spec is resolved (because I guess this will take long)?

@jkowalleck
Copy link
Member

How should we handle this in the code? Because right now it's not possible to add custom properties in a ModelCard.

(however other classes inside the modelCard also have a "properties" field e.g. EnvironmentalConsiderations, and this does fully work)

looking into this. give me some time.
I will find a way to omit the property for XML only.

@wiebe-vandendriessche
Copy link
Author

looking into this. give me some time. I will find a way to omit the property for XML only.

Thanks, sounds good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request schema 1.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Add support for Component modelCard field

2 participants