> Agent-ready spec from Diff of the Day (2026-11-30, idea 3). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: Probability scores from a small local model for one check

## Problem Statement
Teams send the same yes or no question to a large hosted model thousands of times and get back a bare answer. Canva describes a 4B vision-language model that returns a probability for each of 30+ checks, which lets the team set a threshold per check and trade missed violations against false alarms. The first question for a small team is whether an open model gives usable probabilities on its own check at all, before any fine-tuning.

## Goals
- For one check and 100 labelled examples, produce a probability per example from a small open model.
- Report precision and recall at a threshold chosen on a separate half of the data.
- Compare cost and latency per example with the hosted model you use today.

## Non-Goals
- Fine-tuning: this spike measures the untrained baseline that fine-tuning would have to beat.
- More than one check: one check keeps the result readable.
- Production serving: no queue, no autoscaling, one script.

## User Stories
- As an engineer, I want a probability for each answer so that I can choose my own threshold.
- As an engineer, I want the answer format enforced so that parsing never fails.
- As a team lead, I want cost and latency next to accuracy so that I can decide whether training is worth it.
- Edge case: as an engineer, I want examples where the model's format breaks counted as failures, not skipped.

## Requirements
### P0 (must have)
- **Fixed answer format**
  - [ ] The model answers with a JSON object that has one boolean field for the check
  - [ ] Decoding is constrained so that only true or false can follow the field name
- **Probability per example**
  - [ ] For each example the script records the probability of the true token at the decision position
  - [ ] Results are written to scores.csv with the label and the probability
- **Threshold and score**
  - [ ] A threshold is chosen on 50 examples and reported with precision and recall on the other 50
  - [ ] The report shows the hosted model's precision and recall on the same 50
### P1 (nice to have)
- **Calibration plot**
  - [ ] A reliability plot shows predicted probability against observed frequency in five bins
- **Cost and latency table**
  - [ ] The report states seconds and estimated cost per 1,000 examples for both models
### P2 (later)
- LoRA fine-tuning on the labelled examples.
- Several checks in one response, as in the Canva post.

## Success Metrics
- Leading: all 100 examples produce a parseable answer and a probability.
- Leading: the report states one clear result, either the small model is within 5 points of the hosted model or it is not.
- Lagging: a decision to fine-tune or to stay hosted, made with these numbers.

## Open Questions
- Which check, and who labelled the examples? (you)
- Text or image inputs? An image check needs a vision-language model and more memory. (you)

## Timeline
A weekend: one day for the pipeline, one for scoring and the write-up.

## Agent Instructions
- **Suggested stack**: Python 3.12 with transformers or a local server that exposes token probabilities, and a small open model that fits your GPU or laptop.
- **Build order**: load the model and one example, then the constrained answer, then the probability read-out with a unit test on a known case, then the batch run, then the threshold and report.
- **Safety**: keep the labelled data local and send none of it to a third party; do not download model files from unknown publishers.
- **Done when**: scores.csv and report.md exist and the report states precision, recall, cost and latency for both models.

## Sources
- Training and Serving Multimodal LLMs in Production (Canva Engineering): https://www.canva.dev/blog/engineering/local-jev-multimodal-llms-in-production/
