--- name: tt-text-judge description: Traceable LLM-as-judge evaluator for Swedish text quality against the 30 editorial writing rules of TT-språket. Computes a deterministic 0-100 score from six weighted dimensions, runs regex preflight hints, drops hallucinated citations, supports 2-5 run ensembles with dispersion reporting, and calibrates against human-scored JSONL datasets (MAE, RMSE, bias, Pearson r). --- # TT Text Judge `scripts/tt_judge.py` is a traceable **LLM-as-judge evaluator** for Swedish editorial text based on the writing rules in [TT-språket](https://tt-spraket.tt.se/category/skrivregler/) (standalone repository: [BirgerMoell/tt-text-judge](https://github.com/BirgerMoell/tt-text-judge)). Standard library only (Python 3.9+, zero third-party dependencies). Requires `OPENAI_API_KEY` (or a compatible OpenAI Responses API endpoint via `--endpoint` / `TT_JUDGE_ENDPOINT`). API calls use `store: false`. Run it from this skill's folder: ```bash # Score a Swedish text file and emit a Markdown report python3 scripts/tt_judge.py score artikel.txt # Score stdin with a 3-run ensemble (reports dispersion and per-issue run support) printf '%s' 'Andelen ökade med 25%.' | python3 scripts/tt_judge.py score --runs 3 # Score inline text and emit machine-readable JSON python3 scripts/tt_judge.py score --text 'Mötet börjar 18:30 och ca. 25% deltar.' --runs 3 --json -o bedomning.json # Calibrate the judge against human 0-100 scores (reports MAE, RMSE, mean bias, Pearson r) python3 scripts/tt_judge.py calibrate examples/calibration.example.jsonl --runs 3 -o calibration.json # Run unit tests offline (no API key required) PYTHONPATH=scripts python3 -m unittest discover -s tests -v ``` Default model is `gpt-5.6-luna` (Responses API with Structured Outputs). Override with `--model` or `TT_JUDGE_MODEL`. ## Scoring rubric (6 weighted dimensions, 30 rules) The model never assigns the overall score directly. It scores each dimension on an anchored **0–4** scale, and the script deterministically computes the **0–100** total from versioned weights: | Dimension | Weight | Scope | |---|---:|---| | Allmän stil och tydlighet | 28 % | Clarity, active voice, conciseness, editorial tone | | Siffror, datum och tid | 18 % | Numbers, percentages (`25 %`), thousands separators, dates, clock times (`18.30`) | | Skiljetecken | 17 % | Commas, dashes, quotation marks, colons, sentence punctuation | | Sammanskrivning och särskrivning | 13 % | Swedish compound words vs. split compounds | | Förkortningar | 12 % | Standard TT abbreviations without unnecessary periods (`ca`, `bl a`) | | Böjning och genitiv | 12 % | Tricky Swedish inflections, agreement, and genitive forms | The machine-readable rubric with all 30 rules, conditions, examples, and source URLs lives in `scripts/tt_text_judge/data/rules.json`. ## Guardrails & traceability - **Regex preflight as hints only:** deterministic regex checks flag high-signal candidates (`25%`, `1.000`, `18:30`, `mellan 9–17`, dotted abbreviations, compound candidates) and pass them to the judge as hints — never automatic penalties, reducing false positives in tables, quotes, and technical identifiers. - **Verbatim evidence verification:** every reported issue must cite an exact quote from the input text. Issues whose quote does not appear verbatim in the input are automatically dropped. - **Multi-run ensembles (`--runs 2` to `5`):** runs independent judgments and reports score standard deviation alongside how many runs supported each flagged issue. - **Human calibration (`calibrate`):** evaluates a JSONL file (`id`, `text`, `human_score` in 0–100) and outputs MAE, RMSE, mean bias (`judge - human`), Pearson correlation, and per-item errors. For production use, calibrate on at least 100 representative texts with two independent human raters. ## Agent instructions When asked to evaluate Swedish text quality or calibrate a Swedish writing judge: 1. **Score with multi-run ensembles** (`--runs 3`) for anything beyond a quick smoke test so dispersion and issue support are visible. 2. **Use the JSON output** (`--json`) when aggregating across models or datasets, and inspect dropped/low-support issues before acting on them. 3. **Respect genre boundaries:** TT-språket measures Swedish news/editorial style — not factual accuracy, legal compliance, or plain-language agency guidelines (*Myndigheternas skrivregler* / *klarspråk*). For non-editorial domains, fork `scripts/tt_text_judge/data/rules.json` with domain-appropriate rules and weights. 4. **Always calibrate before trusting scores:** run `calibrate` against human ratings before using scores as a benchmark or reward signal. ## Primary sources - [TT-språket: Allmänna skrivregler](https://tt-spraket.tt.se/allmanna-skrivregler/) - [TT-språket: Förkortningar](https://tt-spraket.tt.se/forkortningar/) - [TT-språket: Sammanskrivning och särskrivning](https://tt-spraket.tt.se/sammanskrivning-och-sarskrivning/) - [TT-språket: Knepiga böjningar](https://tt-spraket.tt.se/bojningar/) - [TT-språket: Siffror](https://tt-spraket.tt.se/siffror/) - [TT-språket: Skiljetecken](https://tt-spraket.tt.se/skiljetecken/)