Testing
Evals
Score LLM step 1 and the review rule on ten sample intakes with known answers, then change a prompt and run them again.
By the end of this page one command runs LLM step 1 on the ten sample intakes. It scores the contract type, the client, the email, the price, the start date, and whether the review rule fired, against the answers in each file.
The Python checks only prove that a price appears somewhere in the notes. Whether the model picked the right number, type, and date can only be measured on examples with known answers. Without evals, every prompt change is a guess.
Look at the expected answers
The expected answers live in one file, samples/expected.json, keyed by the file name of each sample. The app never reads it, and the samples themselves are plain notes. This is the first entry:
{
"01-dental-phone-receptionist.md": {
"title": "Dental group: AI phone receptionist",
"type": "fixed_price",
"client": "Harborview Dental Group",
"email": "dana.whitfield@harborviewdental.example.com",
"price": 18500,
"currency": "USD",
"start_date": "2027-03-15",
"trap": "A budget range of $15,000 to $20,000 comes first; the agreed price is $18,500."
},
...
}Each sample hides a trap that a careless extraction falls for.
| Sample | Type | What to watch for |
|---|---|---|
01 | fixed_price | A budget range first, then the agreed $18,500 |
02 | discovery | A future build budget next to the $4,500 audit |
03 | retainer | $150 an hour next to the $4,500 monthly fee |
04 | fixed_price | Three $8,000 milestones, $24,000 in total |
05 | fixed_price | The price only as "22k", with a Zapier bill as a decoy |
06 | retainer | No price agreed, so it must go to review |
07 | none | A full-time job offer, not a contract |
08 | fixed_price | A kickoff date and a go-live date |
09 | retainer | "6k/mo" and "first Monday of March 2027" |
10 | discovery | The price once in passing, and two email addresses |
Write the eval runner
Create the folder backend/evals.
"""Score LLM step 1 and the review rule on the ten sample intakes.
samples/expected.json holds the expected answers per file; the model only sees the notes.
Run: uv run --locked --no-sync python -m evals.run_evals (about ten model calls)
"""
import json
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from app.ai import extract, review_reasons
SAMPLES = Path(__file__).parents[2] / "samples"
EXPECTED = json.loads((SAMPLES / "expected.json").read_text())
def score(name: str) -> dict[str, bool]:
expected = EXPECTED[name]
notes = (SAMPLES / "intakes" / name).read_text()
got = extract(notes)
no_deal = expected["price"] is None or expected["type"] == "none"
return {
"type": got.contract_type == expected["type"],
"client": (got.client_company or "").lower() == expected["client"].lower(),
"email": got.contact_email == expected["email"],
"price": got.price == expected["price"],
"start": (got.start_date and str(got.start_date)) == expected["start_date"],
# A missing price or no contract type must go to a person, never get invented.
"review": bool(review_reasons(got, notes)) == no_deal,
}
if __name__ == "__main__":
names = sorted(EXPECTED)
with ThreadPoolExecutor(4) as pool:
results = list(pool.map(score, names))
checks = list(results[0])
print(f"{'sample':42}" + "".join(f"{check:>8}" for check in checks))
for name, result in zip(names, results, strict=True):
print(f"{name:42}" + "".join(f"{'ok' if result[c] else 'FAIL':>8}" for c in checks))
print(f"{'accuracy':42}" + "".join(f"{sum(r[c] for r in results) / len(results):>8.0%}"
for c in checks))The evals call extract and review_reasons directly, with no database and no API. Four samples run at the same time.
EXPECTED loads the answers once. score() reads the notes of one sample, runs the extraction, and compares each field. The start date stays a plain string in JSON, so it compares directly with the date the model returns.
The review check passes when a sample without a price, or of type none, goes to review, and every other sample does not.
Run them
cd backend
uv run --locked --no-sync python -m evals.run_evalsThat is ten model calls. The output is a table with one row per sample and one column per check, each ok or FAIL, and an accuracy line at the bottom. With AI_MODEL=test it runs, but most checks fail.
Fix a prompt and run again
Find a FAIL, run that sample with python -m app.ai to see the full extraction, and read its reason. Change one thing, usually the instructions in backend/app/ai.py, and run the whole set again.
If you ask a coding agent to fix a failing sample, tell it to find the general rule and not to copy the sample into the prompt. A rule that names the exact client only passes that one intake. That is overfitting, and the next real intake gets the old mistake.
Check
All ten rows pass, or you know why a sample fails and decided to accept it. Run the evals after every prompt change.
Model output varies
The same sample can pass on one run and fail on the next. A sample that flips often points at a rule that is unclear in the instructions. Make that rule more specific.
Signing and the PDF
Add the public signing page with consent, initials, and a typed signature, render the signed PDF with @react-pdf/renderer in Next.js, store it in Postgres, and email it.
Server setup
Create a Hostinger VPS with Docker, allow SSH only from your IP and the web port from anywhere, add a non-root user, and turn off password and root logins.