slotloss
Per-grammar-role loss analysis for structured JSON output from language models.
Fine-tuning your LLM for JSON? Your aggregate metrics might be hiding per-field regressions.
pip install slotloss
What it does
slotloss is the observability layer for structured JSON output. It meets you wherever you are:
| You have | Command | Needs model? |
|---|---|---|
| Messy text with JSON | slotloss --extract --data output.txt |
No |
| JSON + schema | slotloss --validate --schema s.json --data output.jsonl |
No |
| Broken JSON + schema | slotloss --fix --schema s.json --data output.jsonl |
No |
| JSON + schema | slotloss --anatomy --schema s.json --data output.jsonl |
No |
| Two output sets | slotloss --diff --schema s.json --data a.jsonl --data2 b.jsonl |
No |
| Model + checkpoint | slotloss --checkpoint lora/ --schema s.json --data test.jsonl |
Yes |
The problem
Standard fine-tuning + grammar-constrained decoding produces valid JSON. Aggregate loss improves. But:
STRUCTURAL 5.33 -> 0.00 -100% OK
KEY 0.47 -> 0.00 -100% OK
BOOLEAN 0.46 -> 1.05 +130% !! REGRESSION
TOTAL 0.55 -> 0.17 -69%
Aggregate loss improved 69%. Boolean prediction got 130% worse. slotloss catches this.
Quick start
See QUICK_START.md for a hands-on walkthrough from messy output to full analysis.
Python API
from slotloss import analyze
report = analyze(
model_name="Qwen/Qwen2.5-0.5B-Instruct",
checkpoint="my_lora/",
schema="schema.json",
data="test.jsonl",
)
print(report)
if report.regressions:
print(f"REGRESSIONS: {[r.role for r in report.regressions]}")
Exit code is 1 if regressions are detected. Use in CI/CD.
Grammar Roles
| Role | Description | Examples |
|---|---|---|
| STRUCTURAL | JSON syntax | { } [ ] : , |
| QUOTE | String delimiters | " |
| KEY | Object key characters | city, cuisine |
| ENUM_VALUE | Categorical values | Italian, Economy |
| BOOLEAN | Boolean strings | True, False |
| NUMBER | Numeric characters | 42, 3.14 |
| FREE_TEXT | Non-categorical content | names, addresses |
| WHITESPACE | Formatting | spaces, newlines |
Links
- Quick Start Tutorial
- Fixing JSON Fine-Tuning — mitigations, services
- Paper — "Valid JSON, Wrong Answer" (2026)
License
MIT
Metadata
Release files for slotloss 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| slotloss-0.3.0.tar.gz | 29.5 kB | Without provenance | Details for slotloss-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slotloss-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for slotloss-0.3.0-py3-none-any.whl |
Total release size: 65.2 kB
Release files / slotloss-0.3.0.tar.gz
| Download URL | slotloss-0.3.0.tar.gz |
|---|---|
| Size | 29.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d256cbe47de08f1df549d8a354385240b886f960e40a22cfb3ee5223b1bd57b
|
|
BLAKE2b-256 checksum How to use checksums |
6d912f386e163071b681b1e4fc0eb80938ca38ffbbdfb1cea229e81ec1713bc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Release files / slotloss-0.3.0-py3-none-any.whl
| Download URL | slotloss-0.3.0-py3-none-any.whl |
|---|---|
| Size | 35.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9be1bcf0f6efef9f5e9b981b9ffedfe499f324ba11988b8b5a438d27a9320810
|
|
BLAKE2b-256 checksum How to use checksums |
a2b1487ce62585aa306027a9c94eedcc3d859b3b69e144cd9cb15e190ffc370f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.2
|
Security for slotloss 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.