Skip to content

lib: return the full model label space from model_output() - #1541

Open
shivamtiwari3 wants to merge 2 commits into
google:mainfrom
shivamtiwari3:align-model-content-types-with-model-labels
Open

shivamtiwari3 wants to merge 2 commits into
google:mainfrom
shivamtiwari3:align-model-content-types-with-model-labels

Conversation

@shivamtiwari3

@shivamtiwari3 shivamtiwari3 commented Oct 9, 2026 •

Copy link
Copy Markdown

Fixes #1534 (model side).

Problem

TypeInfo::model_output() — exposed as Magika.get_model_content_types() in Python via PyO3 — filtered on model_support, which the generator defines as:

model_labels.contains(label) && !model_config.overwrite_map.contains_key(label)

So it was out of sync with its own contract ("all possible output of the model"). Two kinds of labels that can appear in prediction.dl.label were missing:

  • randombytes / randomtxt: the overwrite map rewrites them, but FileType::Inferred::inferred_type reports the label before the overwrite map is applied, so the raw label is still observable.
  • undefined: reported when the model is not run (FileType::Ruled/Directory/Symlink/Unsupported).

The models' docs already state the correct set: website-ng/src/content/docs/models/standard_v3_3.md, section "List of possible model's outputs", describes itself as "all possible values for MagikaResult.prediction.dl.label" and lists randombytes, randomtxt and undefined.

Change

  • Derive model_output() from crate::model::LABELS plus undefined, ordered by label, and document the contract.
  • Clarify the Python docstring.
  • Update test_get_model_and_output_content_types, which asserted undefined was not in the model set, to match the documented behaviour.

possible_output() / get_output_content_types() (the final output.label values) are unchanged.

Testing

  • Added model_output_matches_possible_dl_labels in rust/lib/src/file.rs: one entry per model::LABELS plus undefined, ordered and unique, includes randombytes/randomtxt/undefined.
  • cargo test --no-default-features model_output passes; cargo clippy --no-default-features -- -D warnings and cargo fmt --check are clean.

TypeInfo::model_output() (exposed as get_model_content_types() in Python
and through PyO3) filtered on model_support, which the generator sets to
false for labels rewritten by the overwrite map (randombytes, randomtxt).
But those labels are exactly what FileType::Inferred::inferred_type reports
before the overwrite map is applied, so prediction.dl.label can still be
randombytes or randomtxt.

Derive model_output() from crate::model::LABELS so it matches the possible
values of the raw model label, and document that undefined is not a model
output. This is the model-side part of google#1534; whether get_model_content_types()
should also include undefined is left to the maintainers.
The models' documentation (website-ng/.../standard_v3_3.md, "List of
possible model's outputs") lists undefined alongside the raw model labels
as a possible value of prediction.dl.label, and that label is indeed set
when the model is not run (rules, directories, symlinks). Add it to
model_output() and update the Python test that asserted the opposite.

This branch has not been deployed

No deployments
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.

[python/rust] Revisit get_model_content_types() missing undefined and overwritten raw DL labels (randombytes, randomtxt)

1 participant