# Where to Find Confidence Thresholds for Each Content Type in Magika

> Find Magika confidence thresholds for content types in model configuration JSON files. Access specific thresholds like config min JSON to improve your Magika model.

- Repository: [Google/magika](https://github.com/google/magika)
- Tags: api-reference
- Published: 2026-04-16

---

**Magika stores per-content-type confidence thresholds in the model-configuration JSON files (specifically [`config.min.json`](https://github.com/google/magika/blob/main/config.min.json) within `assets/models/`), which are loaded at runtime by language-specific bindings into `ModelConfig` objects.**

Magika is Google's open-source machine learning library for detecting file content types with high accuracy. The tool relies on **confidence thresholds** defined for each content type to determine whether a prediction should be treated as high confidence or overridden by fallback logic. These thresholds are stored in JSON configuration files bundled with each model release and parsed by the various language implementations including Python, Rust, Go, and JavaScript.

## Location of Confidence Thresholds in the Source Code

### Model Configuration JSON Files

The definitive source for confidence thresholds resides in the **model configuration files** distributed with every Magika release. Each model version includes a [`config.min.json`](https://github.com/google/magika/blob/main/config.min.json) file located under `assets/models/<model_name>/`, such as [`assets/models/standard_v3_3/config.min.json`](https://github.com/google/magika/blob/main/assets/models/standard_v3_3/config.min.json) for the current standard model.

These JSON files contain a top-level `thresholds` object where keys represent content type labels (e.g., `pdf`, `javascript`, `python`) and values specify the floating-point confidence scores (typically between 0.0 and 1.0) required to classify a prediction as high confidence. For example, the standard v3.3 model defines thresholds such as `0.99` for PDF documents and `0.95` for JavaScript files.

### Python Implementation

In the Python binding, the `Magika` class located in [`python/src/magika/magika.py`](https://github.com/google/magika/blob/main/python/src/magika/magika.py) reads the model's [`config.min.json`](https://github.com/google/magika/blob/main/config.min.json) at initialization and constructs a `ModelConfig` object. The thresholds are exposed via the `thresholds` attribute of this configuration object, defined in [`python/src/magika/types/model.py`](https://github.com/google/magika/blob/main/python/src/magika/types/model.py) as a dictionary mapping `ContentTypeLabel` enums to float values.

### Rust Implementation

The Rust implementation processes the same JSON files during compilation and runtime. The [`config.rs`](https://github.com/google/magika/blob/main/config.rs) file in [`rust/lib/src/config.rs`](https://github.com/google/magika/blob/main/rust/lib/src/config.rs) handles parsing the configuration, while [`rust/lib/src/model.rs`](https://github.com/google/magika/blob/main/rust/lib/src/model.rs) stores the thresholds in a generated static `THRESHOLDS` array. At runtime, the `Model` struct provides access to these values through the `thresholds()` method.

### Other Language Bindings

The Go and JavaScript implementations follow an identical pattern. The Go binding reads thresholds in [`go/magika/config.go`](https://github.com/google/magika/blob/main/go/magika/config.go), while the JavaScript/TypeScript implementation manages them in [`js/src/model-config.ts`](https://github.com/google/magika/blob/main/js/src/model-config.ts). Both languages populate in-memory maps from the same underlying JSON source.

## How Confidence Thresholds Work in Magika

When Magika analyzes a file, it returns a confidence **score** between 0.0 and 1.0 alongside the predicted content type. The inference engine compares this score against two critical bounds to determine the final output:

1. **Global medium confidence threshold**: A default value of `0.5` that serves as the baseline for low-confidence handling.
2. **Per-type threshold**: The specific value retrieved from the `thresholds` map for the predicted content type.

If the prediction score is greater than or equal to the per-type threshold, Magika treats the result as high confidence and does not apply fallback logic. You can see this comparison in the Python source at approximately line 600 of [`magika.py`](https://github.com/google/magika/blob/main/magika.py):

```python
if score >= self._model_config.thresholds.get(dl_label, self._model_config.medium_confidence_threshold):
    # high-confidence – keep the model's prediction

    ...

```

(Full implementation: [[`python/src/magika/magika.py`](https://github.com/google/magika/blob/main/python/src/magika/magika.py), lines 590-610](https://github.com/google/magika/blob/main/python/src/magika/magika.py#L590-L610))

## Practical Code Examples

### Python – Print All Thresholds for the Default Model

```python
from magika import Magika

magika = Magika()

# `_model_config` holds the parsed config for the loaded model

for ct_label, th in magika._model_config.thresholds.items():
    print(f"{ct_label.value:20} → {th:.2f}")

```

This outputs the content type labels aligned with their respective thresholds, such as:

```

pdf                  → 0.99
javascript           → 0.95
python               → 0.92

```

### Python – Access a Specific Threshold

```python
pdf_threshold = magika._model_config.thresholds.get(
    magika.types.ContentTypeLabel.PDF,  # enum value

    magika._model_config.medium_confidence_threshold
)
print(f"PDF high-confidence threshold: {pdf_threshold:.2f}")

```

### Rust – Retrieve Thresholds at Runtime

```rust
use magika::model::Model;

fn main() {
    // Load the standard model (bundled at compile-time)
    let model = Model::load_default();
    // `thresholds` is a slice indexed by ContentType::ordinal()
    let pdf_idx = magika::content_type::ContentType::Pdf as usize;
    let pdf_thr = model.thresholds()[pdf_idx];
    println!("PDF threshold = {:.2}", pdf_thr);
}

```

(See the generation of `THRESHOLDS` in [`rust/lib/src/model.rs`](https://github.com/google/magika/blob/main/rust/lib/src/model.rs).)

### CLI – Display Thresholds via Command Line

```bash
magika --list-thresholds

```

This command prints the complete thresholds map that the library uses internally for inference decisions.

## Summary

- Confidence thresholds for each content type in Magika are stored in [`config.min.json`](https://github.com/google/magika/blob/main/config.min.json) files within `assets/models/<model_version>/`.
- The Python implementation loads these into a `ModelConfig` object via [`python/src/magika/magika.py`](https://github.com/google/magika/blob/main/python/src/magika/magika.py) and [`python/src/magika/types/model.py`](https://github.com/google/magika/blob/main/python/src/magika/types/model.py).
- Rust compiles the thresholds into a static array in [`rust/lib/src/model.rs`](https://github.com/google/magika/blob/main/rust/lib/src/model.rs) after parsing [`rust/lib/src/config.rs`](https://github.com/google/magika/blob/main/rust/lib/src/config.rs).
- At inference time, scores are compared against per-type thresholds to determine high-confidence predictions, falling back to a global default of `0.5` if unspecified.

## Frequently Asked Questions

### What file contains the confidence thresholds for Magika's standard model?

The definitive thresholds for the standard v3.3 model are located in [[`assets/models/standard_v3_3/config.min.json`](https://github.com/google/magika/blob/main/assets/models/standard_v3_3/config.min.json)](https://github.com/google/magika/blob/main/assets/models/standard_v3_3/config.min.json). This JSON file contains a `thresholds` object mapping content type labels to their respective confidence scores.

### How does Magika use confidence thresholds during file type detection?

Magika compares the model's output confidence score against the specific threshold defined for the predicted content type. If the score meets or exceeds this per-type threshold (e.g., `0.99` for PDF), the prediction is considered high confidence; otherwise, it may be overridden by the medium confidence default of `0.5` or other fallback logic.

### Can I modify the confidence thresholds for specific content types?

While you can edit the [`config.min.json`](https://github.com/google/magika/blob/main/config.min.json) files directly, any modifications would require reloading the model configuration in your application code. The thresholds are loaded at initialization time in Python (via `ModelConfig`) and compile-time in Rust, so changes to the JSON must be accompanied by a restart or recompilation depending on the language binding.

### What is the default medium confidence threshold in Magika?

The global **medium confidence threshold** is `0.5`. This value serves as a fallback when a specific content type threshold is not defined in the configuration, and it represents the boundary below which predictions are considered low confidence.