Towards a Theoretical Understanding of Prompt Engineering: Tractability, Existence, and Generalization

18 Sept 2025 (modified: 14 Nov 2025)ICLR 2026 Conference Withdrawn SubmissionEveryoneRevisionsBibTeXCC BY 4.0
Keywords: theory, prompt engineering, generalization
TL;DR: A work try to understand Prompt Engineering by theory
Abstract: Prompt engineering has rapidly become an indispensable tool for the effective utilization of large language models (LLMs), turning LLMs into task-specific experts without changing their weights. Despite its significant practical achievements, the theoretical advancement in this area is relatively limited. To enhance its understanding and interpretability, this paper addresses three fundamental questions in prompt engineering: the computational tractability of finding optimal prompts, existence conditions for the required prompts, and the generalizability of prompts. Precisely, we consider the problem of finding a prompt for a given query-answer dataset and a fixed transformer. We prove that deciding the existence of a perfect prompt is NP-complete, and computing an optimal prompt is NP-hard. Furthermore, we establish sufficient conditions for the existence of perfect prompts based on the structural properties of the dataset, which are also necessary in a certain sense. Finally, we derive a generalization bound demonstrating that the effectiveness of a prompt on the dataset extends to the whole data distribution when the dataset size significantly exceeds the prompt’s length. In summary, our findings answer three crucial theoretical questions in prompt engineering, offering enhanced theoretical insights and some practical guidance.
Primary Area: learning theory
Submission Number: 11285
Loading