Interpret Magika prediction output
mainMagika provides consistent prediction data across the CLI and language bindings (Python, Rust, JavaScript). When scanning files, the output contains metadata about the file path, the scan status, and the prediction details.
Core Fields
path: The file path being predicted (useful when scanning multiple files).result.status: Indicates if the scan was successful. A value ofokmeans thevaluefield is present. If the status is notok, thevaluefield will be absent.value.score: A float representing the model's confidence in the prediction.value.dl: The raw prediction from the deep learning model.value.output: The final prediction from "Magika the tool." This is the recommended field for most applications as it synthesizes the deep learning model's prediction, the confidence score, and the selected prediction mode.
Metadata Fields
Both the dl and output blocks contain the following metadata for the predicted content type:
label: A machine-readable content type label (e.g.,javascript). Note: For most applications, you should useoutput.label.description: A human-readable description of the type.mime_type: The corresponding MIME type.group: A high-level category (e.g.,code,document,media).is_text: A boolean indicating if the content is textual.extensions: A list of common file extensions associated with the type.
Special Cases
- Empty Files/No Model Use: If the deep learning model is not used (e.g., for empty files),
dl.labelwill beundefined, and theoutputblock will contain a generic content type liketxtorunknown.
$ magika tests_data/basic/javascript/code.js --json
[
{
"path": "tests_data/basic/javascript/code.js",
"result": {
"status": "ok",
"value": {
"dl": {
"description": "JavaScript source",
"extensions": [
"js",
"mjs",
"cjs"
],
"group": "code",
"is_text": true,
"label": "javascript",
"mime_type": "application/javascript"
},
"output": {
"description": "JavaScript source",
"extensions": [
"js",
"mjs",
"cjs"
],
"group": "code",
"is_text": true,
"label": "javascript",
"mime_type": "application/javascript"
},
"score": 0.9710000157356262
}
}
}
]