Erik Lyngved

2026-11-07 · JevGym

I'm building a prompt optimizer to learn statistics

Taking something already good, making it production-ready, and proving it's actually working.

I’m building JevGym💪, an open-source prompt optimizer for Jev.

The question I want to answer: can an optimizer that rewrites a prompt over and over beat one good pass from an LLM? And if it does, can I show the gain is real and not just luck? That second part is why this is really a statistics project.

My background is in Industrial & Systems Engineering, where statistics is how you measure and control a process. Statistical process control started on manufacturing assembly lines and has since spread to many industries.

I’ve spent the last few years applying AI to development workflows and one-off features, and I’ve mostly treated the model as a black box: inputs in, outputs out. It’s a very smart box, but it’ll gaslight you if you don’t check what comes out. Now I want to go back to the math behind how models get optimized and evaluated. I’m taking Stanford’s online Probability in AI course, and JevGym is the hands-on project to go with it.

What Jev is

Note: I’m not associated with Jev or TypeSafe in any way! Just a fan.

Jev is a model from TypeSafe. It doesn’t generate text, but just probabilities. They call it a System One model for “quick decisions”, meant to bridge the gap between LLM intelligence and procedural code. Think easy classification, smart if statements, and more. It’s fast and cheap: TypeSafe puts it at up to about 200x faster and 400x cheaper than frontier LLMs. You give it some text, ask it questions, and get probabilities back. The best way to learn how it works is to sign up and try the playground examples.

It got me thinking: training LLMs and evaluating text output is a hard task, and cost bloats quickly. But what if the output consists of bounded numerical values? And it’s really cheap and fast to train and eval? That made Jev an ideal target to experiment with automated optimization.

Choices, choices…

I’m just going to focus on Choice prompts for now. A Choice prompt has two parts, the Instructions and the Criteria, one description per option. Here’s the most basic prompt starter in this project, to fit the dataset we’ll be using (more on that below.)

Questions
{
"answer_type": {
"type": "choice",
"instructions": "What kind of answer does `question` ask for?",
"criteria": {
"ABBR": "abbreviation",
"DESC": "description",
"ENTY": "entity",
"HUM": "human",
"LOC": "location",
"NUM": "numeric"
}
}
}

The option IDs are straight from the dataset and they don’t change. The optimizer only gets to touch the instructions and the criteria.

The task: sorting questions by answer type

The benchmark is TREC question classification, a set of questions labeled by the kind of answer they ask for. “What is the smallest country in Africa ?” is a location question. “What record company produced the 1978 movie The Wiz ?” is a human question, because TREC files companies and groups under human. There are a few “unintuitive” rules to how answers are categorized, which should lead to a quality gap we can measure and improve upon.

TREC is an old benchmark, and fine-tuned classifiers score in the high 90s on its test set. I’m not trying to beat that. Jev only gets a prompt, with no fine-tuning on TREC, so the question is how far a better prompt can take a zero-shot model.

The dataset has 5,870 rows, with 500 already set aside for Test. I’ll split the remaining 4,870 into a Dev set that won’t be used for training, but will serve as an iterative test to measure optimizer progress.

  • 4,370 in the Training set, for feeding the optimizer examples
  • 1,000 in the Dev set, scoring prompts while I explore
  • 500 in the Test set, the final evaluation run at the very end

Rules before results

Before running anything, I wrote down a few rules for how results get reported. They all come from one worry: on 1,000 questions, a prompt can look better just by luck, and I want to be able to tell the difference.

  • Measure how much the score wobbles when I rerun the same prompt, before believing any gain.
  • Put an interval on every score, and don’t call a gain real if it lands inside it.
  • Compare prompts on the same questions, so I can see which answers actually flipped.
  • Keep the optimizer away from Dev and Test, and keep Test locked until the very end. Even if the optimizer never sees Dev, I’m picking prompts by their Dev score, and enough picking will reward lucky ones.
  • Label any number picked from several tries as “best of 5”, because part of being the best is luck.

I’ll explain the stats behind each one when a result actually depends on it. As it turned out, the second rule didn’t survive the noise-floor runs. That’s the next post.

How I split the work with an agent

I’m doing this with Claude Code, and it’s set up so the AI doesn’t just do the learning for me. When I picked the first round, I wrote down my reason as:

generating a foundation for this project so it runs with experimentation instead of the AI just optimizing everything for me. i want to learn more about the statistical methods

The work runs in rounds, and each round answers one question. The agent proposes a few next moves, and I pick one and write down why, so my intuition gets checked against the result later. It builds and runs the round, a separate agent audits the numbers from the raw logs, and the result goes into a lab notebook along with my answers, word for word.

What’s next

Before any optimizing, I’ll set up the core of the project, split the data up, and do one run of the minimal prompt above. Then I’ll test the noise floor to see how much spread I get from running the same prompt several times. I should make some more baseline prompts to test against too that don’t use an LLM at all, namely a hand-written prompt and naive Bayes. And then the training will start.

After that comes the question from the top of this post. Does an iterative optimizer beat one good pass from an LLM writer model, and if it does, where does the gain come from? I don’t know yet.