- The paper introduces a two-stage framework that first employs reasoning-guided search for global prompt adjustments before applying gradient-guided local refinement.
- It demonstrates a notable improvement in FS-TACRED, with a +1.4 F1 boost, by targeting high-impact token spans for precise edits.
- The modular approach enables adaptability and efficiency, highlighting its potential for generalizing to other few-shot and prompt engineering tasks.
Introduction
Prompt engineering is pivotal for leveraging LLMs in episodic few-shot relation extraction (FSRE), particularly when applied to modest-sized models (e.g., Qwen3-4B, Gemma3-4B) in complex settings with limited support examples. This paper introduces a two-stage automatic prompt optimization paradigm for FSRE, combining global, reasoning-based search with local, gradient-guided span editing. The approach systematically disentangles broad semantic prompt improvements (Stage 1) from precise, loss-driven refinements (Stage 2), thereby addressing the suboptimality and model-sensitivity of prior monolithic or heuristic-driven prompt tuning methods.
Figure 1: Schematic of the two-stage prompt optimization pipeline combining a reasoning-based optimizer (broad semantic mutation) with GradPO (local, gradient-informed span refinement) on a real FSRE example.
FSRE is framed under the canonical N-way M-shot episodic design, operationalizing each episode as a set of N binary classification problems. The primary challenge is to classify relations in a query by leveraging only one support instance per relation. Models receive relation names, descriptions, support sentences, and the candidate query, and must produce a binary yes/no verdict without explicit fine-tuning, placing maximal inference burden on prompt quality and structure.
Two-Stage Optimization Framework
Stage 1: Reasoning-Guided Prompt Optimization
The first stage deploys a suite of reasoning-based optimizers, each responsible for high-level, global prompt recomposition via semantic or feedback-driven mutations. Three instantiations are explored:
- RPO: Maintains a prompt population and uses validation-driven stochastic selection to sample parents. Revised prompts are synthesized via external feedback and error explanations, allowing unconstrained mutations.
- EvoPrompt-DE: Leverages evolutionary algorithms for population-based prompt crossover and random mutation, focusing on genetic diversity rather than direct error-feedback loops.
- ETGPO: Structures feedback into taxonomies of error classes, producing revised prompts in one shot guided by the most impactful failure types.
Each method seeks to rapidly traverse the global prompt space, correcting both structural and semantic deficiencies undetectable by single-token or local schemes.
Stage 2: Gradient-Guided Prompt Optimization (GradPO)
Following reasoning-based optimization, the top-performing prompt is submitted to a local refinement stage, GradPO. Unlike previous gradient-based approaches restricted to token-level edits, GradPO innovates by:
- Identifying multiple high-impact spans via the gradient magnitude of the loss w.r.t. prompt tokens.
- Grouping contiguous high-gradient tokens, then employing beam search to explore the combinatorial space of replacements.
- Sampling replacement candidates either via LLM generation (preserving fluency/semantics) or model-led probability-based sampling.
- Scoring candidates with a loss objective Ltask​+λPPL, penalizing loss and fluency violations.
- Leveraging only the target model for gradient computation and candidate ranking, guaranteeing model-aligned refinements.
Significantly, GradPO is instantiated as a lightweight, non-reasoning method, accelerating local optimization steps and ensuring computational tractability.
Empirical Results
Empirical evaluation is conducted on FS-TACRED and FS-FewRel, using both Qwen3-4B and Gemma3-4B as inference models. Key findings include:
- State-of-the-art Performance: On FS-TACRED, the two-stage pipeline with Qwen3-4B elevates F1 from 27.6 (baseline ICL) to 29.0—an absolute +1.4 improvement—demonstrating algorithmic dominance over both purely reasoning-based and gradient-based alternatives.
- Complementarity: Out of 19 test scenarios, a second-stage local refiner improved 17 cases. GradPO yielded the best improvement in 8, compared to 4 for LPO and 3 for GreaTer. This confirms that global and local edits target orthogonal prompt vulnerabilities unaddressed by single-method solutions.
- Stability and Efficiency: Stage-1 prompt quality is volatile across iterations; in contrast, a one-step GradPO refinement consistently delivers monotonic F1 improvements, with most gains front-loaded in early iterations. Candidate search overhead is minimal—approx. 10% of total dev-set evaluation—enabling practical deployment at moderate compute budget.
- Model-Specificity: Local refinements are strongly model-aligned, with minimal cross-model transfer, consistent with the observation that optimal span edits are highly sensitive to the underlying model’s idiosyncratic loss and token gradients.
Qualitative Insights
GradPO predominantly preserves the overarching prompt structure (Figure 1), confining edits to spans with maximal gain as indicated by the loss landscape. While local syntactic or typographic artifacts can occur (e.g., redundant tokens in minority cases), the magnitude and scope are reliably constrained, as verified by near-constant prompt lengths pre/post-edit (~283 tokens vs. ~281 on Qwen3-4B). Furthermore, these local edits are responsible for correcting highly sensitive, decision-critical prompt regions (notoriously impactful in LLM-controlled pipelines).
Theoretical and Practical Implications
This work substantiates the hypothesis that prompt optimization in the low-data regime is best understood as the composition of two orthogonal processes: broad, semantically-driven exploration and fine-grained, gradient-aligned refinement. The proposed pipeline is modular: reasoning-based optimizers can be instantiated with arbitrary search or mutation engines, and GradPO operates agnostically to prior stage implementation, making the method extensible and combinable with emerging prompt optimization techniques. From a practical standpoint, the state-of-the-art results on standard FSRE corpora establish the framework as a highly competitive baseline for future episodic relation extraction tasks in low-resource LLM environments.
Future Directions
Potential directions for expansion include:
- Generalization to Reasoning-Intensive Tasks: Adapting the pipeline for tasks involving multi-step logical or chain-of-thought processes, where prompt features interact with model inference beyond local binary classification.
- Integration with Programmatic Prompt Construction: Combining the automatic pipeline with neuro-symbolic or rule-based prompt frameworks for further gains in interpretability and robustness.
- Scaling to Larger Models and Domains: Empirically evaluating transferability and edit stability on new-generation LLMs (e.g., 70B+ parameters) and domain-specialized datasets.
Conclusion
The presented two-stage framework for prompt optimization—combining reasoning-driven search with targeted gradient-based span edits—systematically outperforms previous monolithic or global-only optimization paradigms on few-shot relation extraction. Results indicate that broad semantic reformation followed by aggressive local refinement is critical for extracting maximal performance from smaller LLMs under strong supervision constraints. The modularity and empirical effectiveness of this approach position it as a canonical solution for future research in prompt engineering for episodic and few-shot extraction problems.
Figure 1: Schematic of the two-stage prompt optimization. The reasoning-guided optimizer (left) proposes a broad prompt change. GradPO (right) precisely refines high-gradient spans, enabling further performance gains on FSRE tasks.