bool(false)
home / Thought Leadership and Industry Insights

Intelligence Beneath the Surface: Prompt optimization using agents in a loop

13 Oct 2026
featured prompt optimization using agents in a loop

TL;DR: Prompt optimization using agents in a loop applies the data-driven feedback loop behind Ocrolus’ agentic-driven development to workloads that have to stay on foundation models. An agent rewrites a prompt, a separate model is scored on it against labeled ground truth, a hidden validation set catches cheating and a blind test set is run once to report true performance. Ocrolus uses the method wherever foundation models do production work and to bring new models online without hand-tuning.

Most prompts running in production were tuned by hand. Someone wrote a draft, read the outputs on a few dozen documents, adjusted the wording and repeated until the results looked right. That process has no score, no held-out data and no way to tell whether a change improved accuracy or moved errors somewhere nobody was looking.

Then agentic-driven development addressed a version of this problem: agents write processing code, and the code is tested against labeled ground truth until it is production-accurate. Some workloads cannot become code. The long-tail and reasoning-heavy work described in LLMs vs. specialized models still runs on foundation models. While a team cannot rewrite a foundation model, it can control the prompt. Prompt optimization using agents applies the same feedback loop to prompts.

3 reasons why hand-tuned prompts break down

The first reason hand-tuned prompts break down is that prompts do not transfer cleanly between models. A prompt tuned for one provider’s model can underperform on another, because each model responds differently to the same instructions. Every new model restarts the tuning work. At the rate models are launched, this approach is simply impossible to maintain.

The second reason is that hand-tuning can be inconsistent. The only way to know whether a prompt works is to score its outputs against known, verified answers. That applies to any prompt, whether a human or a loop tuned it. A loop is built around that measurement at scale, while hand-tuning substitutes a human’s judgment of a small sample.

Which brings us to the third reason: manual iteration does not scale. A person can review a few dozen outputs per revision. That covers a small fraction of a lending workload: Ocrolus supports thousands of form types, and some have more than 200 data points that a prompt has to get right.

How prompt optimization loops work

The method starts by splitting a labeled data set three ways. For a given task, a team might take 100 documents as a training set, hold out 50 as a validation set and seal another 50 as a blind test set.

An agent receives the training set, the current prompt and its score. It rewrites the prompt with one goal: raise training accuracy when the prompt runs against a different foundation model, the one that will do the production work. The agent writing prompts is not the model being scored. The loop repeats until the agent can no longer improve the result. Several agents built on different models can work the same task and compete on score.

How the split prevents cheating

A loop that optimizes against a score will look for shortcuts. For example, an agent that notices most training answers are the number six can write a prompt that says “the answer is six.” Training accuracy rises and nothing useful is learned.

The validation set catches this. Each candidate prompt also runs against the validation documents, and the agent receives the grade without ever seeing those documents. A prompt that improves for real should score higher on both sets. A prompt that climbs on training data while falling on validation data is gaming the score and gets discarded.

The blind test set is opened once, at the end, and that single run is the reported number. Validation scores cannot serve as final accuracy, because the agents used them to choose between prompts.

Why the answer key has to be right

The loop is only as honest as its labels. If a ground-truth answer is wrong, a better prompt that produces the correct output gets scored as a regression and thrown away, and the loop has no way to know. Ocrolus builds its answer keys from human-verified data: people validate and correct machine output until the training set is fully accurate. Because Ocrolus processes documents across a wide network of lenders, labeled data exists for nearly any task the loop needs to optimize.

Onboarding new foundation models

The loop also speeds up putting a new foundation model to work. Existing prompts written for one provider can be handed to an agent with the labeled data and optimized for the new model automatically, and the tuning happens automatically.

With no manual review involved, several models can be evaluated on the same task in parallel, and the product can use whichever model, prompted whichever way, performs best on each task. A lender prompting a general-purpose model directly would need labeled data at scale and a manual tuning cycle for every model it tries.

Where prompt loops fit next to code loops

Prompt optimization carries a cost that the code loop does not. An optimized prompt still runs a foundation model on every document, so inference spend remains part of the margin. Where a task can become committed code, agentic-driven development is the better choice: cheaper at scale, deterministic and inspectable. Prompt optimization covers the work that has to stay on a model and makes that work measurable.

Both loops depend on labeled ground truth and a scoring setup that cannot be gamed. The series has also covered the inference layer in production lending, observability and evals and agentic-driven development. Lenders get prompts and code tuned against real data without managing either, so their teams stay focused on underwriting and funding loans.

Key takeaways

  • Prompt optimization using agents in a loop applies the agentic-driven development feedback loop to workloads that have to stay on foundation models, where the prompt is the only part of the interface a team controls.
  • The agent writing prompts and the model being scored are kept separate, and every revision is measured against labeled ground truth.
  • A hidden validation set catches prompts that game the training score, and a blind test set is run once to report true accuracy.
  • The loop is only as honest as its answer key. Human-verified ground truth keeps the loop from discarding better prompts because of bad labels.
  • Prompt optimization makes it faster to bring new foundation models online, while committed code remains the better choice wherever a task can be coded.

FAQs

What is prompt optimization using agents in a loop?

Prompt optimization using agents in a loop is a method where an AI agent repeatedly rewrites the prompt sent to a foundation model and each version is scored against labeled ground truth data. The loop runs until the agent can no longer improve accuracy. Ocrolus uses it for workloads that need a foundation model and cannot be converted into code.

Why does prompt optimization need a validation set and a blind test set?ย 

An agent optimizing against a score can game it, for example by writing a prompt that repeats a common answer. A validation set the agent never sees exposes prompts that improve on training data but fail on new documents. A blind test set, run once at the end, provides an accuracy number that was never used to make decisions.

Why do hand-tuned prompts break down?

Prompts tuned for one model can underperform on another, so every new model restarts the tuning work. Hand-tuning also has no objective score and relies on a personโ€™s judgment of a small sample, while some form types have more than 200 data points a prompt has to get right.

How does prompt optimization help with new foundation models?

Prompts written for one model often perform differently on another. An agent in a loop can take existing prompts and a labeled data set and optimize them for a new model automatically, which lets a team evaluate several models on the same task in parallel and use the best performer for each task.

When should lenders use prompt optimization vs. code-based processing?

Code-based processing generated through agentic loops is cheaper at scale, deterministic and inspectable, so it is the better choice wherever a task can be coded. Prompt optimization fits long-tail and reasoning-heavy work that has to stay on a foundation model. It makes that work measurable, though each document still carries inference cost.

Ocrolus RGB logo
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.