Introduction
Large Language Models (LLMs) exhibit high sensitivity to prompt structure, where minor phrasing adjustments can lead to drastic performance fluctuations. Traditional prompt engineering is often a manual, heuristic-driven process that is both time-consuming and difficult to scale. This paper presents BO-LLM, a framework that formalizes prompt engineering as a black-box optimization problem solved through Bayesian Optimization (BO). By utilizing a Gaussian Process (GP) surrogate model and an Upper Confidence Bound (UCB) acquisition function, BO-LLM systematically explores the prompt space to maximize accuracy while minimizing costly API evaluations.
Methodology
The BO-LLM framework treats natural language prompts as discrete points in a high-dimensional space. To apply mathematical optimization, the system maps each prompt to a prediction vector generated by running the prompt against a fixed control minibatch ($B_{GP}$). This behavioral representation allows the Gaussian Process to calculate similarity between prompts using a Radial Basis Function (RBF) kernel.
The optimization cycle follows an iterative loop as shown in the figure above:
- Prompt Expansion: An LLM generates candidate prompts by critiquing current errors (gradients).
- Surrogate Modeling: A GP estimates the performance and uncertainty of these candidates.
- Acquisition: The UCB function selects the most promising candidate, balancing the exploitation of known high-performers with the exploration of uncertain regions.
- Evaluation: The selected prompt is evaluated, and the results update the GP's posterior distribution.
To improve stability, the authors implemented Exploration Annealing, linearly decreasing the UCB hyperparameter ($\kappa$) over time to focus the search as more data is gathered.
Experimental Results
The framework was evaluated on two binary classification benchmarks: the LIAR dataset (truthfulness detection) and the ETHOS dataset (hate speech detection).
On the LIAR dataset, BO-LLM achieved a peak accuracy of 58.5%, representing a 32% relative improvement over the initial seed prompt. In the ETHOS benchmark, the framework reached 95.75% accuracy by the seventh round, slightly outperforming the ProTeGi baseline (94.5%). Analysis of the GP posterior dynamics showed that the surrogate model's variance decreased rapidly over the first three rounds, confirming that the GP was effectively learning the prompt landscape.
A notable challenge identified during testing was the "Reversed-Label" pitfall, where the LLM might generate a prompt that is highly accurate but logically inverted (e.g., swapping 'true' and 'false' labels). If selected early, such prompts can misguide the optimization process by chasing high accuracy that is logically flawed.
Conclusion and Future Work
BO-LLM demonstrates that Bayesian Optimization is a viable and sample-efficient approach for automated prompt engineering. While the framework currently focuses on binary classification, its ability to model prompt behavior through prediction vectors provides a foundation for expansion into multi-class and generative tasks. Future work will address the computational complexity of GP updates and the inherent noise in non-deterministic LLM outputs to further stabilize the search process.
Summary updated