A Prompt Is Not a Production System

How an engineer built a system of guarantees around a generative model that now produces educational content in more than 20 languages

Ask a language model to write a lesson, and it will. Ask it to write a good lesson – at scale, in dozens of languages, without anyone reading every line before it reaches a student – and here’s where it gets tricky: the hard part isn’t getting the model to write the text. It’s figuring out whether you can trust it.

That’s what Aleksei Kriuchkov, a full-stack engineer at the US edtech startup Human Program, has spent the past several months working on. He starts from the assumption that the model will inevitably make mistakes, and in predictable ways – so instead of trying to solve every problem through the prompt, he builds a system around the model that catches errors before a student ever sees them.

1. The Problem That Started It All

It began as a mundane task. Human Program’s content existed in English and needed to reach students in other languages. The obvious first move was to translate on the fly: a student opens a lesson in their own language, and the system runs it through Google Translate on the spot.

Kriuchkov quickly ran into the limits of that approach. “Translation quality was mediocre, and formulas kept breaking,” he says. Math notation and machine translation don’t mix well.

The real discovery turned up somewhere unexpected. “It turned out that translating through Google Translate cost more than generating the same content with a language model,” Kriuchkov explains. He’d noticed a less obvious detail: most major model providers offer a batch mode, where requests go out in bulk and results come back not instantly but within a day, at half the price of a standard call, with no drop in quality. “We use it anywhere the answer doesn’t need to come back immediately,” he says. “It’s given us roughly a twofold savings across our entire volume.”

That discovery explained why it made sense to move off Google Translate and onto a language model for translation. But Kriuchkov soon took it a step further: he dropped model-based translation too, switching to generating content from scratch for each language, for the sake of quality. The economics still worked out in his favor: a lesson generated from scratch, with all its checks included, costs 20 to 35 percent less than the same lesson translated through Google Translate.

2. Why a Good Prompt Wasn’t Enough

Kriuchkov describes this as a string of run-ins with the same class of problem: defects a prompt can’t fix, period, not just “handles poorly.”

He caught one of them at the seam between the model and his own system: text was getting corrupted after the model had already done its job correctly. The model returns math formulas as text notation, and certain character sequences, when a slightly damaged response gets auto-repaired, turn into invisible control characters, silently deleting chunks of text. “The model wrote everything correctly – it breaks on our end,” Kriuchkov explains. “The prompt is powerless here by definition.” He built a separate detector for this kind of damage. One telltale sign: a diacritical mark that unexpectedly shows up at the start of a text fragment. Normally it attaches to the character before it, so if it turns up in that position instead, part of the text has gone missing. Kriuchkov applied the principle to Thai, Arabic, and, he says, any other writing system.

He caught a different class of problem where, on the surface, nothing looked wrong at all: quizzes were giving away the answer through form rather than content – the correct choice ran longer than the others, and absolute words like “always” and “never” clustered in the wrong answers. Direct instructions in the prompt didn’t fully solve it, so Kriuchkov moved the check into code: comparing each option’s length against the median (works in any language) and flagging asymmetric use of absolute words like “always” and “never” (so far implemented only for English).

He caught a third case through statistics rather than a single example: the model placed the correct answer in the first position noticeably more often than it should, roughly a third of the time instead of the expected quarter. “The obvious first fix was telling the model, in its instructions, that the correct answer should be distributed evenly across positions. It got us about halfway there: the model started following the rule on paper, but the skew stayed,” he says. So Kriuchkov moved the fix out of the model and into code: answer choices are shuffled at delivery, individually for each user, and the shuffle gets reversed when the answer is checked.

3. Two Attempt Budgets

Kriuchkov built the path content takes through the system as a pipeline of independent stages: task setup, generation, a series of checks, publication. The key architectural decision he singles out is splitting two entirely different kinds of failure. “There are actually two budgets, and that’s deliberate,” he explains. “One caps the number of attempts within a single stage – that covers both technical failures and quality-related revisions that didn’t pan out. The other caps the number of full regenerations from scratch, for when something still hasn’t passed quality within the first budget. You can’t mix them: otherwise it’s impossible to tell where an ordinary revision ends and a decision to start over begins.”

He split the checking process into several layers, each different in kind. Structure, required fields, and numeric signals like answer length moved out of the model and into plain code, since those can be checked deterministically. Where a substantive judgment call is needed, he brings in the model through a separate call, with no access to the generation history: for lessons and quizzes, that’s the same model that generated the content, just acting as an independent reviewer. “For images, a completely different model does the checking, not the one that drew it,” he adds.

When the attempt budget runs out, the system he designed logs the reason for the failure and leaves the task in a queue for review, so a person can see exactly what went wrong and why.

4. Why the Database Was Locking Hundreds of Thousands of Rows to Hand Over a Dozen

Kriuchkov’s engineering work wasn’t limited to generation – it extended to the infrastructure around it. The pipeline’s task table, where each piece of content spawns several tasks across different stages, eventually grew into millions of rows. The database problem actually surfaced after the system already had regular cleanup in place: completed tasks get deleted over time, failed ones stick around for review, and the table now sits at around 800,000 records. But even back when the table held about a million rows, a single batch of tasks being claimed could lock up hundreds of thousands of them.

“Worker processes each grab a batch of tasks, and to keep two workers from grabbing the same one, they do it with row locks,” Kriuchkov says. The database, meanwhile, was choosing a query plan that looked reasonable on paper: it pulled from several separate indexes based on different conditions and intersected the results. In practice, combined with locking, that turned into a disaster. The plan would first lock the entire intersection, hundreds of thousands of rows, and only then sort and hand over the dozen it actually needed. A process that needed to grab a handful of tasks ended up locking a massive chunk of the table, and every neighboring process backed up behind it. The fix was a composite index Kriuchkov designed so its leading columns matched the filter condition exactly, with the sort order built in, and he had to force the database to use it, since the optimizer kept reverting to the bad plan on its own. “A forced index is usually a red flag,” Kriuchkov says. “Here, it’s what correct behavior looks like.”

5. When the Expensive Model Is the Cheaper Option

Kriuchkov works with two main providers and picks a model separately for each stage of the pipeline and each type of content. The architecture lets him swap that choice out without rebuilding the pipeline. “Lessons get generated with one provider’s model, because the text comes out noticeably livelier and richer. Quizzes and images run through the other provider’s models – the quality’s just as good for those tasks, and it costs less,” he explains.

At the review stage, though, Kriuchkov doesn’t cut corners. “A cheaper model misses more defects, and that mistake means a full regeneration cycle, not just one call,” he says. He’s also found the reverse case: for narrow, well-defined tasks, a simpler model holds up just as well as the expensive one, at a noticeably lower cost.

6. The Same Signature Across Different Fixes

At first glance, the problems Kriuchkov solved don’t have much in common: corrupted formulas, an answer choice that ran too long, a skew in where correct answers land, a queue of hundreds of thousands of locked rows in a database. But the engineering approach behind each one looks remarkably similar. Kriuchkov pushes control into code wherever a result can be checked with certainty, rather than leaving it to the model’s probabilistic behavior.

He puts the principle even more bluntly himself: “If a property of the result needs to be guaranteed, you can’t frame it as a request to the model. A request gets carried out statistically. Only code delivers a guarantee.”

That’s the core of Kriuchkov’s engineering approach: instead of demanding absolute reliability from a probabilistic model, he makes the system around it reliable.

Author:
Written byTom Allen

Founder of The AI Journal. I like to write about AI and emerging technologies to inform people how they are changing our world for the better.

Follow Tom Allen